Gamedev Framework (gf)  0.12.0
A C++14 framework for 2D games
ConsoleFont.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_CONSOLE_FONT_H
22 #define GF_CONSOLE_FONT_H
23 
24 #include "ArrayRef.h"
25 #include "Path.h"
26 #include "Portability.h"
27 #include "StringRef.h"
28 #include "Texture.h"
29 #include "Vector.h"
30 
31 namespace gf {
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 inline namespace v1 {
34 #endif
35 
42  struct GF_API ConsoleFontFormat {
46  enum Transparency {
50  };
51 
53 
57  enum Layout {
60  };
61 
63 
67  enum Mapping {
72  };
73 
75  };
76 
83  struct GF_API ConsoleFontElement {
84  char16_t character;
85  uint8_t index;
86  };
87 
97 
102  };
103 
110  class GF_API ConsoleFont {
111  public:
117  ConsoleFont();
118 
122  virtual ~ConsoleFont();
123 
133  return m_format;
134  }
135 
141  Vector2u getSize() const {
142  return m_size;
143  }
144 
151  return m_characterSize;
152  }
153 
169  void mapCode(char16_t c, Vector2u position);
170 
178  void mapCodeRange(char16_t c, unsigned count, Vector2u position);
179 
186  void mapString(StringRef str, Vector2u position);
187 
193  void mapElement(ConsoleFontElement element);
194 
200  void mapElements(ArrayRef<ConsoleFontElement> elements);
201 
207  void clearMapping();
208 
226  RectU getSubTexture(char16_t c) const;
227 
236  RectF getTextureRect(char16_t c) const;
237 
243  virtual const BareTexture *getTexture() const = 0;
244 
249  protected:
260  bool setFormatAndComputeSizes(ConsoleFontFormat format, Vector2u size, Vector2u imageSize);
261 
269  void logFormat(const Path& filename) const;
270 
279  Vector2u getColorKeyPosition() const;
280 
281  private:
282  std::vector<uint8_t> m_mapping;
283  ConsoleFontFormat m_format;
284  Vector2u m_size;
285  Vector2u m_characterSize;
286  };
287 
297  class GF_API BitmapConsoleFont : public ConsoleFont {
298  public:
299 
300  virtual const BareTexture *getTexture() const override;
301 
310  bool loadFromFile(const Path& filename, ConsoleFontFormat format, Vector2u size = { 0u, 0u });
311 
312  private:
313  AlphaTexture m_texture;
314  };
315 
323  class GF_API ColoredConsoleFont : public ConsoleFont {
324  public:
325 
326  virtual const BareTexture *getTexture() const override;
327 
336  bool loadFromFile(const Path& filename, ConsoleFontFormat format, Vector2u size = { 0u, 0u });
337 
338  private:
339  Texture m_texture;
340  };
341 
342 
343 #ifndef DOXYGEN_SHOULD_SKIP_THIS
344 }
345 #endif
346 }
347 
348 #endif // GF_CONSOLE_FONT_H
In row.
Definition: ConsoleFont.h:59
Vector2u getCharacterSize() const
Get the size of the characters.
Definition: ConsoleFont.h:150
Given by a color key.
Definition: ConsoleFont.h:49
Vector2u getSize() const
Get the size of the fonts.
Definition: ConsoleFont.h:141
Transparency transparency
The transparency method of the font.
Definition: ConsoleFont.h:52
A bitmap console font.
Definition: ConsoleFont.h:297
char16_t character
The represented character.
Definition: ConsoleFont.h:84
Layout layout
The layout of the font.
Definition: ConsoleFont.h:62
The special libtcod mapping.
Definition: ConsoleFont.h:70
Mapping
A mapping.
Definition: ConsoleFont.h:67
A texture for colored images.
Definition: Texture.h:339
Given by the level of gray (bitmap font only)
Definition: ConsoleFont.h:48
Transparency
A transparency method.
Definition: ConsoleFont.h:46
Layout
A layout.
Definition: ConsoleFont.h:57
A console font element.
Definition: ConsoleFont.h:83
In column.
Definition: ConsoleFont.h:58
The namespace for gf classes.
Definition: Action.h:35
An image that lives in the graphic memory that can be used for drawing.
Definition: Texture.h:67
A colored console font.
Definition: ConsoleFont.h:323
A constant reference to an array and its size.
Definition: ArrayRef.h:42
Given by the alpha channel of the image.
Definition: ConsoleFont.h:47
A console font.
Definition: ConsoleFont.h:110
boost::filesystem::path Path
A path in the filesystem.
Definition: Path.h:44
Predefined console font formats.
Definition: ConsoleFont.h:92
Code page 437.
Definition: ConsoleFont.h:68
A constant reference to a string and its size.
Definition: StringRef.h:41
A user-defined mapping.
Definition: ConsoleFont.h:71
Mapping mapping
The mapping of the font.
Definition: ConsoleFont.h:74
A texture with a single alpha channel.
Definition: Texture.h:474
Code page 437 modified by libtcod.
Definition: ConsoleFont.h:69
ConsoleFontFormat getFormat() const
Get the format of the font.
Definition: ConsoleFont.h:132
uint8_t index
The index in the font.
Definition: ConsoleFont.h:85
A console font format.
Definition: ConsoleFont.h:42