| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
|
| 22 |
#ifndef FIFE_FONTS_IMAGEFONTBASE_H |
| 23 |
#define FIFE_FONTS_IMAGEFONTBASE_H |
| 24 |
|
| 25 |
// Standard C++ library includes |
| 26 |
#include <map> |
| 27 |
#include <string> |
| 28 |
|
| 29 |
// 3rd party library includes |
| 30 |
|
| 31 |
// FIFE includes |
| 32 |
// These includes are split up in two parts, separated by one empty line |
| 33 |
// First block: files included from the FIFE root src directory |
| 34 |
// Second block: files included from the same folder |
| 35 |
#include "util/structures/point.h" |
| 36 |
|
| 37 |
#include "fontbase.h" |
| 38 |
|
| 39 |
namespace FIFE { |
| 40 |
|
| 41 |
/** ImageFont base class |
| 42 |
* |
| 43 |
* Just set the glyphs/placeholder in any derived class and the rendering |
| 44 |
* is handled by this class. Also frees all glyph surfaces on destruction. |
| 45 |
*/ |
| 46 |
class ImageFontBase: public FontBase { |
| 47 |
public: |
| 48 |
|
| 49 |
/** |
| 50 |
* Constructor. |
| 51 |
*/ |
| 52 |
ImageFontBase(); |
| 53 |
|
| 54 |
/** |
| 55 |
* Destructor. |
| 56 |
*/ |
| 57 |
virtual ~ImageFontBase(); |
| 58 |
|
| 59 |
/** Get the width in pixels a given text would occupy |
| 60 |
* @param text The text that should be measured. |
| 61 |
*/ |
| 62 |
virtual int32_t getWidth(const std::string& text) const; |
| 63 |
|
| 64 |
/** Get the height in pixels a text line would occupy |
| 65 |
*/ |
| 66 |
virtual int32_t getHeight() const; |
| 67 |
|
| 68 |
virtual SDL_Surface *renderString(const std::string& text); |
| 69 |
virtual void setColor(uint8_t r,uint8_t g,uint8_t b, uint8_t a = 255); |
| 70 |
|
| 71 |
protected: |
| 72 |
// A glyph (visible character) |
| 73 |
typedef struct { |
| 74 |
// The offset of the glyph relative to the top-left corner. |
| 75 |
Point offset; |
| 76 |
// The glyphs image |
| 77 |
// should be with SDL_SRCALPHA off, so that it's just copied over. |
| 78 |
SDL_Surface* surface; |
| 79 |
} s_glyph; |
| 80 |
|
| 81 |
typedef std::map<int32_t,s_glyph> type_glyphs; |
| 82 |
type_glyphs m_glyphs; |
| 83 |
|
| 84 |
// The glyph used, when the real glyph is not found |
| 85 |
// Should default to '?' |
| 86 |
s_glyph m_placeholder; |
| 87 |
|
| 88 |
int32_t m_height; |
| 89 |
}; |
| 90 |
} |
| 91 |
|
| 92 |
#endif // end GCN_SDLTRUETYPEFONT_HPP |