-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtext.h
138 lines (125 loc) · 2.7 KB
/
text.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
#ifndef TEXT_H
#define TEXT_H
#include <efi.h>
#include "basic_types.h"
#include "screen.h"
///////////////////////////
// bitmap text rendering //
///////////////////////////
/**
* \brief
* A bitmap text character.
* Defines a font element.
*/
typedef struct bt_char {
/**
* Index of the row used for vertical character alignment.
*/
int baseline;
/**
* \brief
* The width of the data array.
*/
int width;
/**
* \brief
* The height of the data array.
*/
int height;
/**
* \brief
* The character data as a dense matrix.
*
* True values are drawn and false values are skipped.
* These values are called _character elements_.
*/
UINT8 data[];
} bt_char;
/**
* \brief
* Reads the character element at the given position in the character.
*/
UINT8 get_char_el(bt_char const * const c, vec2 p);
/**
* \brief
* A dense mapping of ASCII code points to bt_char structures.
*/
typedef struct bt_font {
bt_char const * const characters[128];
} bt_font;
extern bt_font const default_font;
/**
* \brief
* Information used to render a string.
*/
typedef struct bt_renderer_info {
/**
* \brief
* The color to use to draw character elements.
*/
bgr const color;
/**
* \brief
* The font to use to draw the characters.
*/
bt_font const * const font;
/**
* \brief
* The size in pixels of each character element.
*/
UINT8 const text_scale;
/**
* \brief
* The number of character elements to place between characters.
*/
UINT8 const char_skip;
} bt_renderer_info;
/**
* \brief
* Renders a string to the screen, left-aligned to the given position.
*/
void
bt_render_string(
LFB * const dest,
bt_renderer_info const * const renderer_info,
vec2 const origin,
char const * const str,
UINT32 length);
/**
* \brief
* Renders a string to the screen, centered at the given position.
*
* This isn't particularly efficient since a pass is done over the
* string to determine its width before offsetting it.
*/
void
bt_render_string_centered(
LFB * const dest,
bt_renderer_info const * const renderer_info,
vec2 const origin,
char const * const str,
UINT32 length);
/**
* \brief
* Measures how wide a string would be when rendered on screen.
*/
UINT32
measure_string_width(
bt_renderer_info const * const renderer_info,
char const * const str,
UINT32 length);
/**
* \brief
* Converts the number to a string representation.
*
* The result is written *right-aligned* to the end of the destination
* string.
* If the string is not long enough (according to length) to represent
* the number, then 0 is returned. Otherwise 1 is returned.
*/
int
uint32_to_str(
UINT32 num,
char * const dest,
UINT32 length);
#endif