GlistEngine
Loading...
Searching...
No Matches
gBitmapFont.h
Go to the documentation of this file.
1/*
2 * gBitmapFont.h
3 *
4 * Loads pre-rendered glyphs from a bitmap and draws text by sampling the
5 * configured character rectangles.
6 */
7
8#ifndef ENGINE_GRAPHICS_GBITMAPFONT_H_
9#define ENGINE_GRAPHICS_GBITMAPFONT_H_
10
11#include "gImage.h"
12#include "gRect.h"
13
14#include <cstdint>
15#include <string>
16#include <unordered_map>
17#include <vector>
18
20public:
22 bool load(const std::string& fullPath);
23
25 bool loadImage(const std::string& imagePath);
26 bool loadFontImage(const std::string& imagePath);
27
32 void setCharacterList(const std::string& characters);
33 void setCharacters(const std::string& characters);
34
39 void setCharacterCoordinates(const std::vector<gRect>& coordinates);
40
42 bool setCharacters(const std::string& characters, const std::vector<gRect>& coordinates);
43
45 void drawText(const std::string& text, float x, float y);
46
47 void setScale(float scale);
48 float getScale() const;
49 void setLetterSpacing(float spacing);
50 float getLetterSpacing() const;
51 void setLineHeight(float height);
52 float getLineHeight() const;
53
54 bool isLoaded() const;
55 bool isConfigured() const;
56 int getCharacterCount() const;
57
58private:
59 void rebuildGlyphs();
60
61 gImage bitmap;
62 std::vector<std::uint32_t> characterlist;
63 std::vector<gRect> coordinatelist;
64 std::unordered_map<std::uint32_t, gRect> glyphs;
65 float scale = 1.0f;
66 float letterspacing = 0.0f;
67 float lineheight = 0.0f;
68 float calculatedlineheight = 0.0f;
69 bool loaded = false;
70 bool configured = false;
71};
72
73#endif /* ENGINE_GRAPHICS_GBITMAPFONT_H_ */
Definition gBitmapFont.h:19
void setLineHeight(float height)
bool loadImage(const std::string &imagePath)
bool setCharacters(const std::string &characters, const std::vector< gRect > &coordinates)
float getLineHeight() const
int getCharacterCount() const
float getLetterSpacing() const
void setLetterSpacing(float spacing)
bool load(const std::string &fullPath)
void setCharacterCoordinates(const std::vector< gRect > &coordinates)
float getScale() const
void drawText(const std::string &text, float x, float y)
bool isConfigured() const
void setScale(float scale)
bool isLoaded() const
void setCharacterList(const std::string &characters)
bool loadFontImage(const std::string &imagePath)
void setCharacters(const std::string &characters)
Definition gImage.h:34