Add non-animated SSSE3 blitter
[openttd/fttd.git] / src / strings_func.h
blobdbdbf2842ebba3cc21303314723284886d234650
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file strings_func.h Functions related to OTTD's strings. */
12 #ifndef STRINGS_FUNC_H
13 #define STRINGS_FUNC_H
15 #include "strings_type.h"
16 #include "string_type.h"
17 #include "gfx_type.h"
19 class StringParameters {
20 StringParameters *parent; ///< If not NULL, this instance references data from this parent instance.
21 uint64 *data; ///< Array with the actual data.
22 WChar *type; ///< Array with type information about the data. Can be NULL when no type information is needed. See #StringControlCode.
24 public:
25 uint offset; ///< Current offset in the data/type arrays.
26 uint num_param; ///< Length of the data array.
28 /** Create a new StringParameters instance. */
29 StringParameters(uint64 *data, uint num_param, WChar *type) :
30 parent(NULL),
31 data(data),
32 type(type),
33 offset(0),
34 num_param(num_param)
35 { }
37 /** Create a new StringParameters instance. */
38 template <size_t Tnum_param>
39 StringParameters(int64 (&data)[Tnum_param]) :
40 parent(NULL),
41 data((uint64 *)data),
42 type(NULL),
43 offset(0),
44 num_param(Tnum_param)
46 assert_compile(sizeof(data[0]) == sizeof(uint64));
49 /**
50 * Create a new StringParameters instance that can reference part of the data of
51 * the given partent instance.
53 StringParameters(StringParameters &parent, uint size) :
54 parent(&parent),
55 data(parent.data + parent.offset),
56 offset(0),
57 num_param(size)
59 assert(size <= parent.num_param - parent.offset);
60 if (parent.type == NULL) {
61 this->type = NULL;
62 } else {
63 this->type = parent.type + parent.offset;
67 ~StringParameters()
69 if (this->parent != NULL) {
70 this->parent->offset += this->num_param;
74 void ClearTypeInformation();
76 int64 GetInt64(WChar type = 0);
78 /** Read an int32 from the argument array. @see GetInt64. */
79 int32 GetInt32(WChar type = 0)
81 return (int32)this->GetInt64(type);
84 void ShiftParameters(uint amount);
86 /** Get a pointer to the current element in the data array. */
87 uint64 *GetDataPointer() const
89 return &this->data[this->offset];
92 /** Get a pointer to a specific element in the data array. */
93 uint64 *GetPointerToOffset(uint offset) const
95 assert(offset < this->num_param);
96 return &this->data[offset];
99 /** Does this instance store information about the type of the parameters. */
100 bool HasTypeInformation() const
102 return this->type != NULL;
105 /** Get the type of a specific element. */
106 WChar GetTypeAtOffset(uint offset) const
108 assert(offset < this->num_param);
109 assert(this->HasTypeInformation());
110 return this->type[offset];
113 void SetParam(uint n, uint64 v)
115 assert(n < this->num_param);
116 this->data[n] = v;
119 uint64 GetParam(uint n) const
121 assert(n < this->num_param);
122 return this->data[n];
125 extern StringParameters _global_string_params;
127 char *InlineString(char *buf, StringID string);
128 char *GetString(char *buffr, StringID string, const char *last);
129 char *GetStringWithArgs(char *buffr, StringID string, StringParameters *args, const char *last, uint case_index = 0, bool game_script = false);
130 const char *GetStringPtr(StringID string);
132 uint ConvertKmhishSpeedToDisplaySpeed(uint speed);
133 uint ConvertDisplaySpeedToKmhishSpeed(uint speed);
135 void InjectDParam(uint amount);
138 * Set a string parameter \a v at index \a n in a given array \a s.
139 * @param s Array of string parameters.
140 * @param n Index of the string parameter.
141 * @param v Value of the string parameter.
143 static inline void SetDParamX(uint64 *s, uint n, uint64 v)
145 s[n] = v;
149 * Set a string parameter \a v at index \a n in the global string parameter array.
150 * @param n Index of the string parameter.
151 * @param v Value of the string parameter.
153 static inline void SetDParam(uint n, uint64 v)
155 _global_string_params.SetParam(n, v);
158 void SetDParamMaxValue(uint n, uint64 max_value, uint min_count = 0, FontSize size = FS_NORMAL);
159 void SetDParamMaxDigits(uint n, uint count, FontSize size = FS_NORMAL);
161 void SetDParamStr(uint n, const char *str);
163 void CopyInDParam(int offs, const uint64 *src, int num);
164 void CopyOutDParam(uint64 *dst, int offs, int num);
165 void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num);
168 * Get the current string parameter at index \a n from parameter array \a s.
169 * @param s Array of string parameters.
170 * @param n Index of the string parameter.
171 * @return Value of the requested string parameter.
173 static inline uint64 GetDParamX(const uint64 *s, uint n)
175 return s[n];
179 * Get the current string parameter at index \a n from the global string parameter array.
180 * @param n Index of the string parameter.
181 * @return Value of the requested string parameter.
183 static inline uint64 GetDParam(uint n)
185 return _global_string_params.GetParam(n);
188 extern TextDirection _current_text_dir; ///< Text direction of the currently selected language
190 void InitializeLanguagePacks();
191 const char *GetCurrentLanguageIsoCode();
193 int CDECL StringIDSorter(const StringID *a, const StringID *b);
196 * A searcher for missing glyphs.
198 class MissingGlyphSearcher {
199 public:
200 /** Make sure everything gets destructed right. */
201 virtual ~MissingGlyphSearcher() {}
204 * Get the next string to search through.
205 * @return The next string or NULL if there is none.
207 virtual const char *NextString() = 0;
210 * Get the default (font) size of the string.
211 * @return The font size.
213 virtual FontSize DefaultSize() = 0;
216 * Reset the search, i.e. begin from the beginning again.
218 virtual void Reset() = 0;
221 * Whether to search for a monospace font or not.
222 * @return True if searching for monospace.
224 virtual bool Monospace() = 0;
227 * Set the right font names.
228 * @param settings The settings to modify.
229 * @param font_name The new font name.
231 virtual void SetFontNames(struct FreeTypeSettings *settings, const char *font_name) = 0;
233 bool FindMissingGlyphs(const char **str);
236 void CheckForMissingGlyphs(bool base_font = true, MissingGlyphSearcher *search = NULL);
238 #endif /* STRINGS_FUNC_H */