OpenTTD: src/strings_func.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

strings_func.h
Go to the documentation of this file.
1 /* $Id: strings_func.h 26238 2014-01-12 17:59:43Z frosch $ */
2
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 */
9
12 #ifndef STRINGS_FUNC_H
13 #define STRINGS_FUNC_H
14
15 #include "strings_type.h"
16 #include "string_type.h"
17 #include "gfx_type.h"
18
19 class StringParameters {
20 StringParameters *parent;
21 uint64 *data;
22 WChar *type;
23
24 public:
25 uint offset;
26 uint num_param;
27
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 { }
36
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)
45 {
46 assert_compile(sizeof(data[0]) == sizeof(uint64));
47 }
48
53 StringParameters(StringParameters &parent, uint size) :
54 parent(&parent),
55 data(parent.data + parent.offset),
56 offset(0),
57 num_param(size)
58 {
59 assert(size <= parent.GetDataLeft());
60 if (parent.type == NULL) {
61 this->type = NULL;
62 } else {
63 this->type = parent.type + parent.offset;
64 }
65 }
66
67 ~StringParameters()
68 {
69 if (this->parent != NULL) {
70 this->parent->offset += this->num_param;
71 }
72 }
73
74 void ClearTypeInformation();
75
76 int64 GetInt64(WChar type = 0);
77
79 int32 GetInt32(WChar type = 0)
80 {
81 return (int32)this->GetInt64(type);
82 }
83
84 void ShiftParameters(uint amount);
85
87 uint64 *GetDataPointer() const
88 {
89 return &this->data[this->offset];
90 }
91
93 uint GetDataLeft() const
94 {
95 return this->num_param - this->offset;
96 }
97
99 uint64 *GetPointerToOffset(uint offset) const
100 {
101 assert(offset < this->num_param);
102 return &this->data[offset];
103 }
104
106 bool HasTypeInformation() const
107 {
108 return this->type != NULL;
109 }
110
112 WChar GetTypeAtOffset(uint offset) const
113 {
114 assert(offset < this->num_param);
115 assert(this->HasTypeInformation());
116 return this->type[offset];
117 }
118
119 void SetParam(uint n, uint64 v)
120 {
121 assert(n < this->num_param);
122 this->data[n] = v;
123 }
124
125 uint64 GetParam(uint n) const
126 {
127 assert(n < this->num_param);
128 return this->data[n];
129 }
130 };
131 extern StringParameters _global_string_params;
132
133 char *GetString(char *buffr, StringID string, const char *last);
134 char *GetStringWithArgs(char *buffr, StringID string, StringParameters *args, const char *last, uint case_index = 0, bool game_script = false);
135 const char *GetStringPtr(StringID string);
136
137 uint ConvertKmhishSpeedToDisplaySpeed(uint speed);
138 uint ConvertDisplaySpeedToKmhishSpeed(uint speed);
139
140 void InjectDParam(uint amount);
141
148 static inline void SetDParamX(uint64 *s, uint n, uint64 v)
149 {
150 s[n] = v;
151 }
152
158 static inline void SetDParam(uint n, uint64 v)
159 {
160 _global_string_params.SetParam(n, v);
161 }
162
163 void SetDParamMaxValue(uint n, uint64 max_value, uint min_count = 0, FontSize size = FS_NORMAL);
164 void SetDParamMaxDigits(uint n, uint count, FontSize size = FS_NORMAL);
165
166 void SetDParamStr(uint n, const char *str);
167
168 void CopyInDParam(int offs, const uint64 *src, int num);
169 void CopyOutDParam(uint64 *dst, int offs, int num);
170 void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num);
171
178 static inline uint64 GetDParamX(const uint64 *s, uint n)
179 {
180 return s[n];
181 }
182
188 static inline uint64 GetDParam(uint n)
189 {
190 return _global_string_params.GetParam(n);
191 }
192
193 extern TextDirection _current_text_dir;
194
195 void InitializeLanguagePacks();
196 const char *GetCurrentLanguageIsoCode();
197
198 int CDECL StringIDSorter(const StringID *a, const StringID *b);
199
203 class MissingGlyphSearcher {
204 public:
206 virtual ~MissingGlyphSearcher() {}
207
212 virtual const char *NextString() = 0;
213
218 virtual FontSize DefaultSize() = 0;
219
223 virtual void Reset() = 0;
224
229 virtual bool Monospace() = 0;
230
236 virtual void SetFontNames(struct FreeTypeSettings *settings, const char *font_name) = 0;
237
238 bool FindMissingGlyphs(const char **str);
239 };
240
241 void CheckForMissingGlyphs(bool base_font = true, MissingGlyphSearcher *search = NULL);
242
243 #endif /* STRINGS_FUNC_H */