$treeview $search $mathjax
Stratagus
2.2.7
$projectbrief
|
$projectbrief
|
$searchbox |
_________ __ __ / _____// |_____________ _/ |______ ____ __ __ ______ \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \ /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > \/ \/ \//_____/ \/ ______________________ ______________________ T H E W A R B E G I N S Stratagus - A free fantasy real time strategy game engine
00001 // _________ __ __ 00002 // / _____// |_____________ _/ |______ ____ __ __ ______ 00003 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ 00004 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ | 00005 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > 00006 // \/ \/ \//_____/ \/ 00007 // ______________________ ______________________ 00008 // T H E W A R B E G I N S 00009 // Stratagus - A free fantasy real time strategy game engine 00010 // 00012 // 00013 // (c) Copyright 1998-2005 by Lutz Sammer and Jimmy Salmon 00014 // 00015 // This program is free software; you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation; only version 2 of the License. 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 // GNU General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with this program; if not, write to the Free Software 00026 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00027 // 02111-1307, USA. 00028 // 00029 00030 #ifndef __FONT_H__ 00031 #define __FONT_H__ 00032 00034 00035 /*---------------------------------------------------------------------------- 00036 -- Documentation 00037 ----------------------------------------------------------------------------*/ 00038 00058 /*---------------------------------------------------------------------------- 00059 -- Includes 00060 ----------------------------------------------------------------------------*/ 00061 00062 #include <string> 00063 #include "color.h" 00064 #include "guichan/font.h" 00065 00066 /*---------------------------------------------------------------------------- 00067 -- Declarations 00068 ----------------------------------------------------------------------------*/ 00069 class CGraphic; 00070 class CFontColor; 00071 00073 class CFont : public gcn::Font 00074 { 00075 private: 00076 explicit CFont(const std::string &ident) : 00077 Ident(ident), 00078 CharWidth(NULL), 00079 G(NULL) 00080 {} 00081 00082 public: 00083 virtual ~CFont(); 00084 00085 static CFont *New(const std::string &ident, CGraphic *g); 00086 static CFont *Get(const std::string &ident); 00087 00088 int Height() const; 00089 int Width(const std::string &text) const; 00090 int Width(const int number) const; 00091 bool IsLoaded() const; 00092 00093 virtual int getHeight() const { return Height(); } 00094 virtual int getWidth(const std::string &text) const { return Width(text); } 00095 virtual void drawString(gcn::Graphics *graphics, const std::string &text, int x, int y); 00096 00097 void Load(); 00098 void Reload() const; 00099 void FreeOpenGL(); 00100 void Clean(); 00101 00102 CGraphic *GetFontColorGraphic(const CFontColor &fontColor) const; 00103 00104 template<bool CLIP> 00105 unsigned int DrawChar(CGraphic &g, int utf8, int x, int y, const CFontColor &fc) const; 00106 00107 void DynamicLoad() const; 00108 00109 private: 00110 void MakeFontColorTextures() const; 00111 void MeasureWidths(); 00112 00113 private: 00114 std::string Ident; 00115 char *CharWidth; 00116 CGraphic *G; 00117 }; 00118 00119 #define MaxFontColors 9 00120 00122 class CFontColor 00123 { 00124 public: 00125 explicit CFontColor(const std::string &ident); 00126 ~CFontColor(); 00127 00128 static CFontColor *New(const std::string &ident); 00129 static CFontColor *Get(const std::string &ident); 00130 00131 std::string Ident; 00132 CColor Colors[MaxFontColors]; 00133 }; 00134 00135 /*---------------------------------------------------------------------------- 00136 -- Definitions 00137 ----------------------------------------------------------------------------*/ 00138 00142 #define FontRed "red" 00143 #define FontGreen "green" 00144 #define FontYellow "yellow" 00145 #define FontWhite "white" 00146 #define FontGrey "grey" 00147 00148 /*---------------------------------------------------------------------------- 00149 -- Variables 00150 ----------------------------------------------------------------------------*/ 00151 00156 extern CFont &GetSmallFont(); 00157 extern CFont &GetGameFont(); 00158 00159 /*---------------------------------------------------------------------------- 00160 -- Functions 00161 ----------------------------------------------------------------------------*/ 00162 00164 extern void SetDefaultTextColors(const std::string &normal, const std::string &reverse); 00166 extern void GetDefaultTextColors(std::string &normalp, std::string &reversep); 00168 extern std::string GetLineFont(unsigned int line, const std::string &s, unsigned int maxlen, CFont *font); 00169 00171 extern int GetHotKey(const std::string &text); 00172 00174 extern void LoadFonts(); 00176 extern void FreeOpenGLFonts(); 00178 extern void ReloadFonts(); 00180 extern void CleanFonts(); 00181 00182 class CLabel 00183 { 00184 public: 00185 CLabel(const CFont &f, const std::string &nc, const std::string &rc): font(&f) { 00186 normal = CFontColor::Get(nc); 00187 reverse = CFontColor::Get(rc); 00188 } 00189 explicit CLabel(const CFont &f); 00190 00191 int Height() const { return font->Height(); } 00192 00193 void SetFont(const CFont &f) { font = &f; } 00194 00195 void SetNormalColor(const std::string &nc) { normal = CFontColor::Get(nc); } 00196 00198 int Draw(int x, int y, const char *const text) const; 00199 int Draw(int x, int y, const std::string &text) const; 00200 int Draw(int x, int y, int number) const; 00202 int DrawClip(int x, int y, const char *const text) const; 00203 int DrawClip(int x, int y, const std::string &text) const; 00204 int DrawClip(int x, int y, int number) const; 00206 int DrawReverse(int x, int y, const char *const text) const; 00207 int DrawReverse(int x, int y, const std::string &text) const; 00208 int DrawReverse(int x, int y, int number) const ; 00210 int DrawReverseClip(int x, int y, const char *const text) const; 00211 int DrawReverseClip(int x, int y, const std::string &text) const; 00212 int DrawReverseClip(int x, int y, int number) const; 00213 00214 int DrawCentered(int x, int y, const std::string &text) const; 00215 private: 00216 template <const bool CLIP> 00217 int DoDrawText(int x, int y, const char *const text, 00218 const size_t len, const CFontColor *fc) const; 00219 private: 00220 const CFontColor *normal; 00221 const CFontColor *reverse; 00222 const CFont *font; 00223 }; 00224 00226 00227 #endif // !__FONT_H__