| 1 |
// ____ _ __ |
| 2 |
// / __ )____ _____ | | / /___ ___________ |
| 3 |
// / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/ |
| 4 |
// / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) |
| 5 |
// /_____/\____/____/ |__/|__/\__,_/_/ /____/ |
| 6 |
// |
| 7 |
// A futuristic real-time strategy game. |
| 8 |
// This file is part of Bos Wars. |
| 9 |
// |
| 10 |
/**@name include/font.h - The font headerfile. */ |
| 11 |
// |
| 12 |
// (c) Copyright 1998-2008 by Lutz Sammer and Jimmy Salmon |
| 13 |
// |
| 14 |
// This program is free software; you can redistribute it and/or modify |
| 15 |
// it under the terms of the GNU General Public License as published by |
| 16 |
// the Free Software Foundation; only version 2 of the License. |
| 17 |
// |
| 18 |
// This program is distributed in the hope that it will be useful, |
| 19 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
// GNU General Public License for more details. |
| 22 |
// |
| 23 |
// You should have received a copy of the GNU General Public License |
| 24 |
// along with this program; if not, write to the Free Software |
| 25 |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 26 |
// 02111-1307, USA. |
| 27 |
|
| 28 |
#ifndef __FONT_H__ |
| 29 |
#define __FONT_H__ |
| 30 |
|
| 31 |
//@{ |
| 32 |
|
| 33 |
/*---------------------------------------------------------------------------- |
| 34 |
-- Documentation |
| 35 |
----------------------------------------------------------------------------*/ |
| 36 |
|
| 37 |
/** |
| 38 |
** @class CFont font.h |
| 39 |
** |
| 40 |
** \#include "font.h" |
| 41 |
** |
| 42 |
** Defines the fonts used in the Stratagus engine. We support |
| 43 |
** proportional multicolor fonts of 9 colors. |
| 44 |
** (Currently the fonts aren't packed) |
| 45 |
** |
| 46 |
** CFont::CharWidth[] |
| 47 |
** |
| 48 |
** The width of each font glyph in pixels. The index 0 is the |
| 49 |
** width of the SPACE (' ', 0x20). |
| 50 |
** |
| 51 |
** CFont::G |
| 52 |
** |
| 53 |
** Contains the graphics of the font, Only 9 colors are supported. |
| 54 |
*/ |
| 55 |
|
| 56 |
/*---------------------------------------------------------------------------- |
| 57 |
-- Includes |
| 58 |
----------------------------------------------------------------------------*/ |
| 59 |
|
| 60 |
#include <string> |
| 61 |
#include "SDL.h" |
| 62 |
#include "guichan/font.h" |
| 63 |
|
| 64 |
/*---------------------------------------------------------------------------- |
| 65 |
-- Declarations |
| 66 |
----------------------------------------------------------------------------*/ |
| 67 |
|
| 68 |
class CGraphic; |
| 69 |
class CFontFamily; |
| 70 |
|
| 71 |
/// Font definition |
| 72 |
class CFont : public gcn::Font { |
| 73 |
friend class CFontFamily; |
| 74 |
|
| 75 |
public: |
| 76 |
virtual ~CFont(); |
| 77 |
|
| 78 |
static CFont *New(const std::string &ident, CGraphic *g); |
| 79 |
static CFont *Get(const std::string &ident); |
| 80 |
CFont *PlainText(); |
| 81 |
|
| 82 |
int Height() const; |
| 83 |
int Width(const std::string &text) const; |
| 84 |
bool IsLoaded() const; |
| 85 |
bool IsPlainText() const; |
| 86 |
CFontFamily *FontFamily() { return this->Family; } |
| 87 |
|
| 88 |
virtual int getHeight() const { return Height(); } |
| 89 |
virtual int getWidth(const std::string &text) const |
| 90 |
{ return Width(text); } |
| 91 |
virtual void drawString(gcn::Graphics *graphics, const std::string &text, |
| 92 |
int x, int y); |
| 93 |
|
| 94 |
private: |
| 95 |
CFont(); |
| 96 |
|
| 97 |
CFontFamily *Family; |
| 98 |
|
| 99 |
private: // undefined |
| 100 |
CFont(const CFont &); |
| 101 |
CFont &operator =(const CFont &); |
| 102 |
}; |
| 103 |
|
| 104 |
#define MaxFontColors 9 |
| 105 |
|
| 106 |
/// Font color definition |
| 107 |
class CFontColor { |
| 108 |
public: |
| 109 |
CFontColor(const std::string &ident); |
| 110 |
~CFontColor(); |
| 111 |
|
| 112 |
static CFontColor *New(const std::string &ident); |
| 113 |
static CFontColor *Get(const std::string &ident); |
| 114 |
|
| 115 |
std::string Ident; |
| 116 |
SDL_Color Colors[MaxFontColors]; |
| 117 |
}; |
| 118 |
|
| 119 |
/*---------------------------------------------------------------------------- |
| 120 |
-- Definitions |
| 121 |
----------------------------------------------------------------------------*/ |
| 122 |
|
| 123 |
/** |
| 124 |
** FIXME: should be moved to lua |
| 125 |
*/ |
| 126 |
#define FontRed "red" |
| 127 |
#define FontGreen "green" |
| 128 |
#define FontYellow "yellow" |
| 129 |
#define FontWhite "white" |
| 130 |
#define FontGrey "grey" |
| 131 |
|
| 132 |
/*---------------------------------------------------------------------------- |
| 133 |
-- Variables |
| 134 |
----------------------------------------------------------------------------*/ |
| 135 |
|
| 136 |
/** |
| 137 |
** Font selector for the font functions. |
| 138 |
** FIXME: should be moved to lua |
| 139 |
*/ |
| 140 |
extern CFont *SmallFont; /// Small font used in stats |
| 141 |
extern CFont *GameFont; /// Normal font used in game |
| 142 |
extern CFont *LargeFont; /// Large font used in menus |
| 143 |
|
| 144 |
/*---------------------------------------------------------------------------- |
| 145 |
-- Functions |
| 146 |
----------------------------------------------------------------------------*/ |
| 147 |
|
| 148 |
/// Set the default text colors for normal and reverse text |
| 149 |
extern void SetDefaultTextColors(const std::string &normal, const std::string &reverse); |
| 150 |
/// Get the default text colors for normal and reverse text |
| 151 |
extern void GetDefaultTextColors(std::string &normalp, std::string &reversep); |
| 152 |
/// Draw text unclipped |
| 153 |
extern int VideoDrawText(int x, int y, CFont *font, const std::string &text); |
| 154 |
/// Draw text unclipped |
| 155 |
extern int VideoDrawTextClip(int x, int y, CFont *font, const std::string &text); |
| 156 |
/// Draw reverse text unclipped |
| 157 |
extern int VideoDrawReverseText(int x, int y, CFont *font, const std::string &text); |
| 158 |
/// Draw reverse text clipped |
| 159 |
extern int VideoDrawReverseTextClip(int x, int y, CFont *font, const std::string &text); |
| 160 |
/// Draw text centered and unclipped |
| 161 |
extern int VideoDrawTextCentered(int x, int y, CFont *font, const std::string &text); |
| 162 |
/// Draw number unclipped |
| 163 |
extern int VideoDrawNumber(int x, int y, CFont *font, int number); |
| 164 |
/// Draw number clipped |
| 165 |
extern int VideoDrawNumberClip(int x, int y, CFont *font, int number); |
| 166 |
/// Draw reverse number unclipped |
| 167 |
extern int VideoDrawReverseNumber(int x, int y, CFont *font, int number); |
| 168 |
/// Draw reverse number clipped |
| 169 |
extern int VideoDrawReverseNumberClip(int x, int y, CFont *font, int number); |
| 170 |
|
| 171 |
/// Get the hot key from a string |
| 172 |
extern int GetHotKey(const std::string &text); |
| 173 |
|
| 174 |
/// Load and initialize the fonts |
| 175 |
extern void LoadFonts(); |
| 176 |
/// Free OpenGL fonts |
| 177 |
extern void FreeOpenGLFonts(); |
| 178 |
/// Reload OpenGL fonts |
| 179 |
extern void ReloadFonts(); |
| 180 |
/// Cleanup the font module |
| 181 |
extern void CleanFonts(); |
| 182 |
|
| 183 |
//@} |
| 184 |
|
| 185 |
#endif // !__FONT_H__ |