PROTO::KLUDGE  0.1
Quick prototyping library for games using SDL and OpenGL.
Font.hpp
Go to the documentation of this file.
1 #ifndef FONT_HPP
2 #define FONT_HPP
3 
4 #include <stdio.h>
5 
6 #include <SDL2/SDL.h>
7 #include <SDL2/SDL_ttf.h>
8 
9 namespace pk
10 {
11 
17 class Font
18 {
19  public:
20 
25  Font();
26  virtual ~Font();
27 
35  bool loadFont(char *file, int fontSize);
36 
42  void setFont(TTF_Font *font){ m_font = font; };
43 
49  TTF_Font * getFont(){ return m_font; };
50 
60  enum hinting
61  {
62  h_normal = TTF_HINTING_NORMAL,
63  h_light = TTF_HINTING_LIGHT,
64  h_mono = TTF_HINTING_MONO,
65  h_none = TTF_HINTING_NONE
66  };
67 
72  enum style
73  {
74  normal = TTF_STYLE_NORMAL,
75  bold = TTF_STYLE_BOLD,
76  italic = TTF_STYLE_ITALIC,
77  underline = TTF_STYLE_UNDERLINE,
78  strikethrough = TTF_STYLE_STRIKETHROUGH
79  };
80 
86  void setHinting(Uint32 hinting){ m_hinting = hinting; TTF_SetFontHinting(m_font, m_hinting); };
87 
93  const Uint32 &getHinting(){ return m_hinting; };
94 
99  void setKerning(int allowed){ m_kerning = allowed; TTF_SetFontKerning(m_font, m_kerning); };
100 
106  int getOutline(){ return m_outline; };
107 
113  void setOutline(int outline){ m_outline = outline; TTF_SetFontOutline(m_font, m_outline); };
114 
120  void setFontStyle(int style){ m_style = style; TTF_SetFontStyle(m_font, style); };
121 
127  const int &getStyle(){ return m_style; };
128 
134  void setFontSize(int s);
135 
136  private:
137  TTF_Font* m_font;
138  char * m_path;
139  Uint32 m_hinting;
140  int m_kerning;
141  int m_outline;
142  int m_style;
143 
144 };
145 
146 } //end namespace pk
147 
148 #endif // FONT_HPP
TTF_Font * getFont()
Get a pointer to the TTF_Font data.
Definition: Font.hpp:49
A class implemented using the Facade pattern used for loading SDL TTF_Font data.
Definition: Font.hpp:17
const Uint32 & getHinting()
Get the current hinting of the font.
Definition: Font.hpp:93
void setFontStyle(int style)
Set the style for the font. Use Font::style enum flags to combine styles.
Definition: Font.hpp:120
style
Set the style of the font.
Definition: Font.hpp:72
char * m_path
The path to the Font file.
Definition: Font.hpp:138
Definition: Game.hpp:7
Definition: Font.hpp:62
void setOutline(int outline)
Set the outline for the font (in pixels).
Definition: Font.hpp:113
int m_kerning
Kerning for the font (set to 1, or on, by default.
Definition: Font.hpp:140
Definition: Font.hpp:65
Definition: Font.hpp:64
const int & getStyle()
Get the current style of the font.
Definition: Font.hpp:127
Definition: Font.hpp:74
Definition: Font.hpp:76
int m_style
Font style (defaults to style::normal).
Definition: Font.hpp:142
int getOutline()
Get the outline for the font (in pixels).
Definition: Font.hpp:106
Uint32 m_hinting
Hinting for the font.
Definition: Font.hpp:139
Definition: Font.hpp:78
int m_outline
Font outline (set to 0, or off, by default).
Definition: Font.hpp:141
Definition: Font.hpp:77
Font()
Default constructor.
TTF_Font * m_font
Pointer to TTF_Font data - memory managed outside class.
Definition: Font.hpp:137
void setKerning(int allowed)
Turn on/off font kerning (on by default).
Definition: Font.hpp:99
void setFont(TTF_Font *font)
Set the internal TTF_Font for the Font.
Definition: Font.hpp:42
hinting
From SDL_ttf docs: Hinting Font hinting is the use of mathematical instructions to adjust the display...
Definition: Font.hpp:60
void setFontSize(int s)
Set the size for the font (in pixels).
Definition: Font.hpp:127
Definition: Font.hpp:75
virtual ~Font()
bool loadFont(char *file, int fontSize)
Load a font from a file.
void setHinting(Uint32 hinting)
Set the hinting of the font (use Font::hinting enum to set valid values).
Definition: Font.hpp:86
Definition: Font.hpp:63