Project

General

Profile

Statistics
| Revision:

root / proj / libs / graph / include / font.h @ 331

History | View | Annotate | Download (3.69 KB)

1 182 up20180642
#ifndef FONT_H_INCLUDED
2
#define FONT_H_INCLUDED
3
4 314 up20180642
struct font;
5 319 up20180642
/**
6
 * @brief Font. Represents a set of glyphs that can be drawn for showing text.
7
 */
8 314 up20180642
typedef struct font font_t;
9 319 up20180642
/**
10
 * @brief Construct font.
11
 *
12
 * The font is constructed from a provided path. That path is required to
13
 * contain glyphs with the name "ascii???.xpm2", files with format XPM2 where
14
 * instead of having "???" we have 3-digit ASCII codes, where the glyph with
15
 * that name map to that XPM2 file.
16
 * @param   s   Path to directory
17
 * @return      Pointer to font
18
 */
19 314 up20180642
font_t* (font_ctor)(const char *s);
20 319 up20180642
/**
21
 * @brief Destruct font.
22
 * @param   p   Pointer to font to be destroyed
23
 */
24
void    (font_dtor)(font_t *p);
25 314 up20180642
26 319 up20180642
/**
27
 * @brief Initialize font stuff.
28
 *
29
 * More specifically, this involves loading the default font, which is currently consolas.
30
 * @return  SUCCESS if initialization was successful, false otherwise
31
 */
32 314 up20180642
int (font_init)(void);
33 319 up20180642
/**
34
 * @brief Get default font.
35
 *
36
 * Currently, the default font is Consolas.
37
 * @return  Pointer to default font
38
 */
39 314 up20180642
const font_t* font_get_default(void);
40 319 up20180642
/**
41
 * @brief Get Consolas font.
42
 * @return Pointer to Consolas font
43
 */
44 314 up20180642
const font_t* font_get_consolas(void);
45 319 up20180642
/**
46
 * @brief Free resources used on initialization of fonts.
47
 */
48
void (font_free)(void);
49 314 up20180642
50 319 up20180642
/**
51
 * @brief Enumeration of vertical alignment schemes.
52
 */
53 314 up20180642
typedef enum{
54 188 up20180642
    text_valign_top    = -1,
55
    text_valign_center =  0,
56
    text_valign_bottom =  1
57 314 up20180642
} text_valign;
58 319 up20180642
/**
59
 * @brief Enumeration of horizontal alignment schemes.
60
 */
61 314 up20180642
typedef enum{
62 188 up20180642
    text_halign_left   = -1,
63
    text_halign_center =  0,
64
    text_halign_right  =  1
65 314 up20180642
} text_halign;
66 188 up20180642
67 183 up20180642
struct text;
68 319 up20180642
/**
69
 * @brief Drawable text.
70
 */
71 183 up20180642
typedef struct text text_t;
72 319 up20180642
/**
73
 * @brief Construct text.
74
 * @param   fnt Font to draw the text
75
 * @param   txt String to be drawn
76
 * @return      Pointer to constructed text
77
 */
78 183 up20180642
text_t* (text_ctor)(const font_t *fnt, const char *txt);
79 319 up20180642
/**
80
 * @brief Destruct text.
81
 * @param   p   Pointer to text to be destroyed
82
 */
83 183 up20180642
void    (text_dtor)(text_t *p);
84 319 up20180642
/**
85
 * @brief Set text string.
86
 * @param   p   Pointer to text
87
 * @param   txt String to be set
88
 */
89 314 up20180642
void (text_set_string)(text_t *p, const char *txt);
90 319 up20180642
/**
91
 * @brief Set text position.
92
 * @param   p   Pointer to text
93
 * @param   x   X-position of the text
94
 * @param   y   Y-position of the text
95
 */
96 188 up20180642
void (text_set_pos)   (text_t *p, int16_t x, int16_t y);
97 319 up20180642
/**
98 323 up20180642
 * @brief Set text size (letter size, in pixels).
99 319 up20180642
 * @param   p       Pointer to text
100
 * @param   size    Letter size of the text
101
 */
102 323 up20180642
void (text_set_size)  (text_t *p, uint16_t size);
103 319 up20180642
/**
104
 * @brief Set text color.
105
 * @param   p       Pointer to text
106
 * @param   color   Text color
107
 */
108 188 up20180642
void (text_set_color) (text_t *p, uint32_t color);
109 319 up20180642
/**
110
 * @brief Set text vertical alignment.
111
 * @param   p       Pointer to text
112
 * @param   valign  Vertical alignment of the text
113
 */
114 314 up20180642
void (text_set_valign)(text_t *p, text_valign valign);
115 319 up20180642
/**
116
 * @brief Set text horizontal alignment.
117
 * @param   p       Pointer to text
118
 * @param   halign  Horizontal alignment of the text
119
 */
120 314 up20180642
void (text_set_halign)(text_t *p, text_halign halign);
121 319 up20180642
/**
122
 * @brief Get string of the text.
123
 * @param   p       Pointer to text
124
 * @return  Pointer to string
125
 */
126
const char* (text_get_string)(const text_t *p);
127
/**
128
 * @brief Get text x-position.
129
 * @param   p   Pointer to text
130
 * @return      X-position of text
131
 */
132 297 up20180642
int16_t (text_get_x)  (const text_t *p);
133 319 up20180642
/**
134
 * @brief Get text y-position.
135
 * @param   p   Pointer to text
136
 * @return      Y-position of text
137
 */
138 297 up20180642
int16_t (text_get_y)  (const text_t *p);
139 319 up20180642
/**
140
 * @brief Draw text on the screen buffer.
141
 * @param   p   Pointer to text
142
 * @return      SUCCESS if operation was successful, false otherwise
143
 */
144 314 up20180642
int     (text_draw)   (const text_t *p);
145 182 up20180642
146
#endif //FONT_H_INCLUDED