-
Notifications
You must be signed in to change notification settings - Fork 0
/
Font.h
71 lines (57 loc) · 1.31 KB
/
Font.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
64
65
66
67
68
69
70
71
#pragma once
// C++
#include <iostream> // Reading file
#include <fstream> // Reading file
#include <string> // Reading file
#include <vector> // Reading file
// SDL
//#include "SDL.h"
#include "SDL_gpu.h"
// Utils
#include "Utils/Debug.h"
#include "Utils/StringHelper.h"
// Giving alias for data types
using file = std::string;
using text = std::string;
using byte = unsigned char;
class Font
{
public:
Font(GPU_Target* screen);
~Font();
bool Load(file filePath);
void Free();
void DrawText(text string, float x, float y);
void SetColor(byte r, byte g, byte b, byte a = 255);
void SetScale(float scale);
//void SetRotation(float rotation);
//void SetTranslate(float x, float y);
//void SetOrigin(float x, float y);
private:
// Structs
struct FontData
{
GPU_Rect texture;
short X; //offset of character (x,y) relative to top-left
short Y;
unsigned short AdvX; //x-advance after character
};
struct FontKerning
{
unsigned char first;
unsigned char second;
short distance;
};
// Methods
void DrawChar(byte ch);
void DrawCharScale(byte ch);
// Members
GPU_Target* screen;
GPU_Image* imgFont;
float x;
float y;
float scale;
FontData stFontData[128];
FontKerning stFontKerning[256];
unsigned short stFontKerningNum;
};