strings_func.h

Go to the documentation of this file.
00001 /* $Id: strings_func.h 26238 2014-01-12 17:59:43Z frosch $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
00008  */
00009 
00012 #ifndef STRINGS_FUNC_H
00013 #define STRINGS_FUNC_H
00014 
00015 #include "strings_type.h"
00016 #include "string_type.h"
00017 #include "gfx_type.h"
00018 
00019 class StringParameters {
00020   StringParameters *parent; 
00021   uint64 *data;             
00022   WChar *type;              
00023 
00024 public:
00025   uint offset;              
00026   uint num_param;           
00027 
00029   StringParameters(uint64 *data, uint num_param, WChar *type) :
00030     parent(NULL),
00031     data(data),
00032     type(type),
00033     offset(0),
00034     num_param(num_param)
00035   { }
00036 
00038   template <size_t Tnum_param>
00039   StringParameters(int64 (&data)[Tnum_param]) :
00040     parent(NULL),
00041     data((uint64 *)data),
00042     type(NULL),
00043     offset(0),
00044     num_param(Tnum_param)
00045   {
00046     assert_compile(sizeof(data[0]) == sizeof(uint64));
00047   }
00048 
00053   StringParameters(StringParameters &parent, uint size) :
00054     parent(&parent),
00055     data(parent.data + parent.offset),
00056     offset(0),
00057     num_param(size)
00058   {
00059     assert(size <= parent.GetDataLeft());
00060     if (parent.type == NULL) {
00061       this->type = NULL;
00062     } else {
00063       this->type = parent.type + parent.offset;
00064     }
00065   }
00066 
00067   ~StringParameters()
00068   {
00069     if (this->parent != NULL) {
00070       this->parent->offset += this->num_param;
00071     }
00072   }
00073 
00074   void ClearTypeInformation();
00075 
00076   int64 GetInt64(WChar type = 0);
00077 
00079   int32 GetInt32(WChar type = 0)
00080   {
00081     return (int32)this->GetInt64(type);
00082   }
00083 
00084   void ShiftParameters(uint amount);
00085 
00087   uint64 *GetDataPointer() const
00088   {
00089     return &this->data[this->offset];
00090   }
00091 
00093   uint GetDataLeft() const
00094   {
00095     return this->num_param - this->offset;
00096   }
00097 
00099   uint64 *GetPointerToOffset(uint offset) const
00100   {
00101     assert(offset < this->num_param);
00102     return &this->data[offset];
00103   }
00104 
00106   bool HasTypeInformation() const
00107   {
00108     return this->type != NULL;
00109   }
00110 
00112   WChar GetTypeAtOffset(uint offset) const
00113   {
00114     assert(offset < this->num_param);
00115     assert(this->HasTypeInformation());
00116     return this->type[offset];
00117   }
00118 
00119   void SetParam(uint n, uint64 v)
00120   {
00121     assert(n < this->num_param);
00122     this->data[n] = v;
00123   }
00124 
00125   uint64 GetParam(uint n) const
00126   {
00127     assert(n < this->num_param);
00128     return this->data[n];
00129   }
00130 };
00131 extern StringParameters _global_string_params;
00132 
00133 char *GetString(char *buffr, StringID string, const char *last);
00134 char *GetStringWithArgs(char *buffr, StringID string, StringParameters *args, const char *last, uint case_index = 0, bool game_script = false);
00135 const char *GetStringPtr(StringID string);
00136 
00137 uint ConvertKmhishSpeedToDisplaySpeed(uint speed);
00138 uint ConvertDisplaySpeedToKmhishSpeed(uint speed);
00139 
00140 void InjectDParam(uint amount);
00141 
00148 static inline void SetDParamX(uint64 *s, uint n, uint64 v)
00149 {
00150   s[n] = v;
00151 }
00152 
00158 static inline void SetDParam(uint n, uint64 v)
00159 {
00160   _global_string_params.SetParam(n, v);
00161 }
00162 
00163 void SetDParamMaxValue(uint n, uint64 max_value, uint min_count = 0, FontSize size = FS_NORMAL);
00164 void SetDParamMaxDigits(uint n, uint count, FontSize size = FS_NORMAL);
00165 
00166 void SetDParamStr(uint n, const char *str);
00167 
00168 void CopyInDParam(int offs, const uint64 *src, int num);
00169 void CopyOutDParam(uint64 *dst, int offs, int num);
00170 void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num);
00171 
00178 static inline uint64 GetDParamX(const uint64 *s, uint n)
00179 {
00180   return s[n];
00181 }
00182 
00188 static inline uint64 GetDParam(uint n)
00189 {
00190   return _global_string_params.GetParam(n);
00191 }
00192 
00193 extern TextDirection _current_text_dir; 
00194 
00195 void InitializeLanguagePacks();
00196 const char *GetCurrentLanguageIsoCode();
00197 
00198 int CDECL StringIDSorter(const StringID *a, const StringID *b);
00199 
00203 class MissingGlyphSearcher {
00204 public:
00206   virtual ~MissingGlyphSearcher() {}
00207 
00212   virtual const char *NextString() = 0;
00213 
00218   virtual FontSize DefaultSize() = 0;
00219 
00223   virtual void Reset() = 0;
00224 
00229   virtual bool Monospace() = 0;
00230 
00236   virtual void SetFontNames(struct FreeTypeSettings *settings, const char *font_name) = 0;
00237 
00238   bool FindMissingGlyphs(const char **str);
00239 };
00240 
00241 void CheckForMissingGlyphs(bool base_font = true, MissingGlyphSearcher *search = NULL);
00242 
00243 #endif /* STRINGS_FUNC_H */