Gamedev Framework (gf)  0.17.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 
126  ConsoleFont(const Image& image, ConsoleFontFormat format, Vector2i size);
127 
131  virtual ~ConsoleFont();
132 
142  return m_format;
143  }
144 
150  Vector2i getSize() const {
151  return m_size;
152  }
153 
160  return m_characterSize;
161  }
162 
178  void mapCode(char16_t c, Vector2i position);
179 
187  void mapCodeRange(char16_t c, int count, Vector2i position);
188 
195  void mapString(StringRef str, Vector2i position);
196 
202  void mapElement(ConsoleFontElement element);
203 
209  void mapElements(ArrayRef<ConsoleFontElement> elements);
210 
216  void clearMapping();
217 
235  RectI getSubTexture(char16_t c) const;
236 
245  RectF getTextureRect(char16_t c) const;
246 
252  virtual const BareTexture *getTexture() const = 0;
253 
258  protected:
266  void logFormat(const Path& filename) const;
267 
276  Vector2i getColorKeyPosition() const;
277 
278  private:
279  std::vector<uint8_t> m_mapping;
280  ConsoleFontFormat m_format;
281  Vector2i m_size;
282  Vector2i m_characterSize;
283  };
284 
294  class GF_API BitmapConsoleFont : public ConsoleFont {
295  public:
303  BitmapConsoleFont(const Image& image, ConsoleFontFormat format, Vector2i size = { 0u, 0u });
304 
312  BitmapConsoleFont(const Path& filename, ConsoleFontFormat format, Vector2i size = { 0u, 0u });
313 
314  const BareTexture *getTexture() const override;
315 
316  private:
317  AlphaTexture m_texture;
318  };
319 
327  class GF_API ColoredConsoleFont : public ConsoleFont {
328  public:
336  ColoredConsoleFont(const Image& image, ConsoleFontFormat format, Vector2i size = { 0u, 0u });
337 
345  ColoredConsoleFont(const Path& filename, ConsoleFontFormat format, Vector2i size = { 0u, 0u });
346 
347  const BareTexture *getTexture() const override;
348 
349  private:
350  Texture m_texture;
351  };
352 
353 
354 #ifndef DOXYGEN_SHOULD_SKIP_THIS
355 }
356 #endif
357 }
358 
359 #endif // GF_CONSOLE_FONT_H
In row.
Definition: ConsoleFont.h:59
Given by a color key.
Definition: ConsoleFont.h:49
Transparency transparency
The transparency method of the font.
Definition: ConsoleFont.h:52
A bitmap console font.
Definition: ConsoleFont.h:294
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:309
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
Class for loading, manipulating and saving images.
Definition: Image.h:80
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:75
A colored console font.
Definition: ConsoleFont.h:327
A constant reference to an array and its size.
Definition: ArrayRef.h:43
Given by the alpha channel of the image.
Definition: ConsoleFont.h:47
A console font.
Definition: ConsoleFont.h:110
Vector2i getCharacterSize() const
Get the size of the characters.
Definition: ConsoleFont.h:159
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
Vector2i getSize() const
Get the size of the fonts.
Definition: ConsoleFont.h:150
A texture with a single alpha channel.
Definition: Texture.h:391
Code page 437 modified by libtcod.
Definition: ConsoleFont.h:69
ConsoleFontFormat getFormat() const
Get the format of the font.
Definition: ConsoleFont.h:141
uint8_t index
The index in the font.
Definition: ConsoleFont.h:85
A console font format.
Definition: ConsoleFont.h:42