-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleFonts.h
63 lines (45 loc) · 1.4 KB
/
ModuleFonts.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef __MODULE_FONTS_H__
#define __MODULE_FONTS_H__
#include "Module.h"
#include "SDL2\include\SDL_pixels.h"
#define MAX_FONTS 10
#define MAX_FONT_CHARS 256
struct SDL_Texture;
struct Font
{
// Lookup table. All characters displayed in the same order as the texture
char table[MAX_FONT_CHARS];
// The font texture
SDL_Texture* texture = nullptr;
// Font setup data
uint totalLength;
uint rows, columns;
uint char_w, char_h;
};
class ModuleFonts : public Module
{
public:
// Constructor
ModuleFonts(bool isEnabled);
// Destructor
~ModuleFonts();
// Loads a font file from a texture
// Returns a font index from the fonts array
// Param texturePath - The path to the texture file
// Param characters - The lookup table. All characters displayed in the same order as the texture
// Param rows - The amount of character rows in the texture
int Load(const char* texturePath, const char* characters, uint rows = 1);
// Removes a font by its index
// Unloads the texture and removes it from the fonts array
void UnLoad(int fontIndex);
// Create a surface from text
void BlitText(int x, int y, int fontIndex, const char* text) const;
inline uint GetFontsCount() const { return fontsCount; };
private:
// An array to keep track and store all loaded fonts
Font fonts[MAX_FONTS];
// The amount of fonts loaded into the array
uint fontsCount = 0;
SDL_Texture* tex;
};
#endif // __ModuleFonts_H__