Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (3.69 KB)

1
#ifndef FONT_H_INCLUDED
2
#define FONT_H_INCLUDED
3

    
4
struct font;
5
/**
6
 * @brief Font. Represents a set of glyphs that can be drawn for showing text.
7
 */
8
typedef struct font font_t;
9
/**
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
font_t* (font_ctor)(const char *s);
20
/**
21
 * @brief Destruct font.
22
 * @param   p   Pointer to font to be destroyed
23
 */
24
void    (font_dtor)(font_t *p);
25

    
26
/**
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
int (font_init)(void);
33
/**
34
 * @brief Get default font.
35
 *
36
 * Currently, the default font is Consolas.
37
 * @return  Pointer to default font
38
 */
39
const font_t* font_get_default(void);
40
/**
41
 * @brief Get Consolas font.
42
 * @return Pointer to Consolas font
43
 */
44
const font_t* font_get_consolas(void);
45
/**
46
 * @brief Free resources used on initialization of fonts.
47
 */
48
void (font_free)(void);
49

    
50
/**
51
 * @brief Enumeration of vertical alignment schemes.
52
 */
53
typedef enum{
54
    text_valign_top    = -1,
55
    text_valign_center =  0,
56
    text_valign_bottom =  1
57
} text_valign;
58
/**
59
 * @brief Enumeration of horizontal alignment schemes.
60
 */
61
typedef enum{
62
    text_halign_left   = -1,
63
    text_halign_center =  0,
64
    text_halign_right  =  1
65
} text_halign;
66

    
67
struct text;
68
/**
69
 * @brief Drawable text.
70
 */
71
typedef struct text text_t;
72
/**
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
text_t* (text_ctor)(const font_t *fnt, const char *txt);
79
/**
80
 * @brief Destruct text.
81
 * @param   p   Pointer to text to be destroyed
82
 */
83
void    (text_dtor)(text_t *p);
84
/**
85
 * @brief Set text string.
86
 * @param   p   Pointer to text
87
 * @param   txt String to be set
88
 */
89
void (text_set_string)(text_t *p, const char *txt);
90
/**
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
void (text_set_pos)   (text_t *p, int16_t x, int16_t y);
97
/**
98
 * @brief Set text size (letter size, in pixels).
99
 * @param   p       Pointer to text
100
 * @param   size    Letter size of the text
101
 */
102
void (text_set_size)  (text_t *p, uint16_t size);
103
/**
104
 * @brief Set text color.
105
 * @param   p       Pointer to text
106
 * @param   color   Text color
107
 */
108
void (text_set_color) (text_t *p, uint32_t color);
109
/**
110
 * @brief Set text vertical alignment.
111
 * @param   p       Pointer to text
112
 * @param   valign  Vertical alignment of the text
113
 */
114
void (text_set_valign)(text_t *p, text_valign valign);
115
/**
116
 * @brief Set text horizontal alignment.
117
 * @param   p       Pointer to text
118
 * @param   halign  Horizontal alignment of the text
119
 */
120
void (text_set_halign)(text_t *p, text_halign halign);
121
/**
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
int16_t (text_get_x)  (const text_t *p);
133
/**
134
 * @brief Get text y-position.
135
 * @param   p   Pointer to text
136
 * @return      Y-position of text
137
 */
138
int16_t (text_get_y)  (const text_t *p);
139
/**
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
int     (text_draw)   (const text_t *p);
145

    
146
#endif //FONT_H_INCLUDED