FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fontbase.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 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_FONTBASE_H
23 #define FIFE_FONTS_FONTBASE_H
24 
25 // Standard C++ library includes
26 #include <string>
27 
28 // Platform specific includes
29 #include "util/base/fife_stdint.h"
30 
31 // 3rd party library includes
32 #include <SDL.h>
33 
34 // FIFE includes
35 // These includes are split up in two parts, separated by one empty line
36 // First block: files included from the FIFE root src directory
37 // Second block: files included from the same folder
38 #include "textrenderpool.h"
39 #include "ifont.h"
40 
41 struct SDL_Surface;
42 namespace FIFE {
43 
48  class FontBase: public IFont {
49  public:
50  FontBase();
51  virtual ~FontBase() {};
52 
53  void invalidate();
54  void setRowSpacing (int32_t spacing);
55  int32_t getRowSpacing() const;
56  void setGlyphSpacing(int32_t spacing);
57  int32_t getGlyphSpacing() const;
58  void setAntiAlias(bool antiAlias);
59  bool isAntiAlias();
60  virtual int32_t getStringIndexAt(const std::string &text, int32_t x) const;
61 
62  Image* getAsImage(const std::string& text);
63  Image* getAsImageMultiline(const std::string& text);
64  std::string splitTextToWidth (const std::string& text, int32_t render_width);
65 
66  SDL_Color getColor() const;
67 
68  virtual SDL_Surface* renderString(const std::string& text) = 0;
69 
70  protected:
72 
73  SDL_Color mColor;
74  int32_t mGlyphSpacing;
75  int32_t mRowSpacing;
76 
77  std::string mFilename;
79  };
80 
81 }
82 
83 #endif
void invalidate()
Definition: fontbase.cpp:52
int32_t getGlyphSpacing() const
Gets the spacing between letters in pixels.
Definition: fontbase.cpp:68
Base Class for Images.
Definition: image.h:47
int32_t mGlyphSpacing
Definition: fontbase.h:74
Generic pool for rendered text Caches a number of Images with text, as rendered by a Font...
virtual ~FontBase()
Definition: fontbase.h:51
Image * getAsImageMultiline(const std::string &text)
Gets given text as Image.
Definition: fontbase.cpp:122
void setAntiAlias(bool antiAlias)
Sets the use of anti aliasing.
Definition: fontbase.cpp:72
SDL_Color mColor
Definition: fontbase.h:73
Abstract Font Base Class Uses a pool for rendered strings.
Definition: fontbase.h:48
TextRenderPool m_pool
Definition: fontbase.h:71
virtual int32_t getStringIndexAt(const std::string &text, int32_t x) const
Definition: fontbase.cpp:84
void setRowSpacing(int32_t spacing)
Sets the spacing between rows in pixels.
Definition: fontbase.cpp:56
int32_t mRowSpacing
Definition: fontbase.h:75
int32_t getRowSpacing() const
Gets the spacing between rows in pixels.
Definition: fontbase.cpp:60
Image * getAsImage(const std::string &text)
Gets given text as Image The rsulting image is pooled, so it&#39;s not that time critical.
Definition: fontbase.cpp:112
void setGlyphSpacing(int32_t spacing)
Sets the spacing between letters in pixels.
Definition: fontbase.cpp:64
bool isAntiAlias()
Checks if anti aliasing is used.
Definition: fontbase.cpp:76
bool m_antiAlias
Definition: fontbase.h:78
std::string mFilename
Definition: fontbase.h:77
Pure abstract Font interface.
Definition: ifont.h:43
std::string splitTextToWidth(const std::string &text, int32_t render_width)
Definition: fontbase.cpp:174
virtual SDL_Surface * renderString(const std::string &text)=0
SDL_Color getColor() const
Get the color the text was rendered in.
Definition: fontbase.cpp:80