$treeview $search $mathjax
Stratagus
2.2.6
$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 "SDL.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 private: 00075 CFont(const std::string &ident) : 00076 Ident(ident), 00077 CharWidth(NULL), 00078 G(NULL) 00079 {} 00080 00081 public: 00082 virtual ~CFont(); 00083 00084 static CFont *New(const std::string &ident, CGraphic *g); 00085 static CFont *Get(const std::string &ident); 00086 00087 int Height() const; 00088 int Width(const std::string &text) const; 00089 int Width(const int number) const; 00090 bool IsLoaded() const; 00091 00092 virtual int getHeight() const { return Height(); } 00093 virtual int getWidth(const std::string &text) const 00094 { return Width(text); } 00095 virtual void drawString(gcn::Graphics *graphics, const std::string &text, 00096 int x, int y); 00097 00098 00099 void Load(); 00100 void Reload() const; 00101 void FreeOpenGL(); 00102 void Clean(); 00103 00104 CGraphic *GetFontColorGraphic(const CFontColor *fontColor) const; 00105 00106 template<bool CLIP> 00107 unsigned int DrawChar(CGraphic *g, int utf8, int x, int y, const CFontColor *fc) const; 00108 00109 00110 void DynamicLoad() const; 00111 00112 private: 00113 void MakeFontColorTextures() const; 00114 void MeasureWidths(); 00115 00116 private: 00117 std::string Ident; 00118 char *CharWidth; 00119 CGraphic *G; 00120 }; 00121 00122 #define MaxFontColors 9 00123 00125 class CFontColor { 00126 public: 00127 CFontColor(const std::string &ident); 00128 ~CFontColor(); 00129 00130 static CFontColor *New(const std::string &ident); 00131 static CFontColor *Get(const std::string &ident); 00132 00133 std::string Ident; 00134 SDL_Color Colors[MaxFontColors]; 00135 }; 00136 00137 /*---------------------------------------------------------------------------- 00138 -- Definitions 00139 ----------------------------------------------------------------------------*/ 00140 00141 #define MaxFonts 15 00142 00143 00146 #define FontRed "red" 00147 #define FontGreen "green" 00148 #define FontYellow "yellow" 00149 #define FontWhite "white" 00150 #define FontGrey "grey" 00151 00152 /*---------------------------------------------------------------------------- 00153 -- Variables 00154 ----------------------------------------------------------------------------*/ 00155 00160 extern CFont *GetSmallFont(); 00161 extern CFont *GetGameFont(); 00162 00163 /*---------------------------------------------------------------------------- 00164 -- Functions 00165 ----------------------------------------------------------------------------*/ 00166 00168 extern void SetDefaultTextColors(const std::string &normal, const std::string &reverse); 00170 extern void GetDefaultTextColors(std::string &normalp, std::string &reversep); 00172 extern std::string GetLineFont(unsigned int line, const std::string &s, unsigned int maxlen, CFont *font); 00173 00175 extern int GetHotKey(const std::string &text); 00176 00178 extern void LoadFonts(); 00180 extern void FreeOpenGLFonts(); 00182 extern void ReloadFonts(); 00184 extern void CleanFonts(); 00185 00186 class CLabel { 00187 const CFontColor *normal; 00188 const CFontColor *reverse; 00189 const CFont *font; 00190 00191 template <const bool CLIP> 00192 int DoDrawText(int x, int y, const char*const text, 00193 const size_t len, const CFontColor *fc) const; 00194 00195 public: 00196 CLabel(const CFont *f, const std::string &nc, const std::string &rc): font(f) { 00197 normal = CFontColor::Get(nc); 00198 reverse = CFontColor::Get(rc); 00199 } 00200 CLabel(const CFont *f); 00201 00202 int Height() const 00203 { 00204 return font->Height(); 00205 } 00206 00207 void SetFont(const CFont *f) { 00208 font = f; 00209 } 00210 00211 void SetNormalColor(const std::string &nc) { 00212 normal = CFontColor::Get(nc); 00213 } 00214 00216 int Draw(int x, int y, const char*const text) const; 00217 int Draw(int x, int y, const std::string &text) const; 00218 int Draw(int x, int y, int number) const; 00220 int DrawClip(int x, int y, const char*const text) const; 00221 int DrawClip(int x, int y, const std::string &text) const; 00222 int DrawClip(int x, int y, int number) const; 00224 int DrawReverse(int x, int y, const char*const text) const; 00225 int DrawReverse(int x, int y, const std::string &text) const; 00226 int DrawReverse(int x, int y, int number)const ; 00228 int DrawReverseClip(int x, int y, const char*const text) const; 00229 int DrawReverseClip(int x, int y, const std::string &text) const; 00230 int DrawReverseClip(int x, int y, int number) const; 00231 00232 int DrawCentered(int x, int y, const std::string &text) const; 00233 00234 }; 00235 00237 00238 #endif // !__FONT_H__