-
-
Notifications
You must be signed in to change notification settings - Fork 182
/
Copy pathFont.h
147 lines (119 loc) · 2.97 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* Copyright (c) scott.cgi All Rights Reserved.
*
* This source code belongs to project Mojoc, which is a pure C Game Engine hosted on GitHub.
* The Mojoc Game Engine is licensed under the MIT License, and will continue to be iterated with coding passion.
*
* License : https://github.com/scottcgi/Mojoc/blob/master/LICENSE
* GitHub : https://github.com/scottcgi/Mojoc
* CodeStyle: https://github.com/scottcgi/Mojoc/blob/master/Docs/CodeStyle.md
*
* Since : 2016-7-27
* Update : 2021-2-8
* Author : scott.cgi
*/
#ifndef FONT_H
#define FONT_H
#include "Engine/Toolkit/Utils/ArrayIntSet.h"
#include "Engine/Extension/TextureAtlas.h"
#include "Engine/Graphics/OpenGL/Mesh.h"
/**
* Font implementation by TextureAtlas.
*/
typedef struct
{
/**
* the TextureAtlas that Font used.
*/
TextureAtlas* textureAtlas;
/**
* The Mesh that textureAtlas used.
*/
Mesh mesh[1];
/**
* Cache all FontTexts.
*/
ArrayIntSet(FontText*) fontTextSet[1];
/**
* Font Mesh unused SubMesh list.
* released FontText's SubMesh will add into this.
*/
ArrayList (SubMesh*) unusedSubMeshList[1];
}
Font;
/**
* FontText alignment type.
*/
typedef enum
{
FontTextAlignment_HorizontalLeft,
FontTextAlignment_HorizontalRight,
FontTextAlignment_VerticalTop,
FontTextAlignment_VerticalBottom,
}
FontTextAlignment;
/**
* The text in font textureAtlas.
*/
typedef struct
{
/**
* The base class for provide draw functions.
*/
Drawable drawable[1];
/**
* Default FontTextAlignment_HorizontalLeft.
*/
FontTextAlignment alignment;
/**
* The spacing between chars, default 0.
*/
float charSpacing;
/**
* The Font that FontText belongs to.
*/
Font* font;
/**
* The SubMesh list that FontText used.
*/
ArrayList(SubMesh*) usedSubMeshList[1];
}
FontText;
/**
* Control Font and FontText.
*/
struct AFont
{
/**
* Get Font by filePath.
*
* filePath:
* Android: assets
* IOS : NSBundle
*/
Font* (*Get) (const char* filePath);
FontText* (*GetText) (Font* font);
void (*Draw) (Font* font);
void (*SetString) (FontText* text, const char* str);
void (*SetInt) (FontText* text, int num);
void (*SetFloat) (FontText* text, float num);
/**
* Make Font can reuse in Get method,
* and release all FontTexts.
*/
void (*Release) (Font* font);
/**
* Make FontText can reuse in GetText method.
* and add FontText's SubMesh into Font->unusedSubMeshList.
*/
void (*ReleaseText) (FontText* text);
};
extern struct AFont AFont[1];
/**
* Set FontText color.
*/
static inline void AFont_SetTextColor(FontText* text, Color* color)
{
ADrawable_SetColor(text->drawable, color);
}
#endif