Project

General

Profile

Revision 319

documented font. also changed a bit the timer

View differences:

font.c
8 8
#include "errors.h"
9 9
#include <assert.h>
10 10

  
11
/// GLYPH
11
/**
12
 * @brief Text glyph. Represents a letter that can be drawn.
13
 */
12 14
typedef struct {
13 15
    uint16_t w, h;
14 16
    uint8_t *map;
15 17
} glyph_t;
18
/**
19
 * @brief Construct glyph.
20
 * @param   xpm XPM describing the glyph
21
 * @return      Pointer to created glyph
22
 */
16 23
static glyph_t* (glyph_ctor)(const char **xpm){
17 24
    if(xpm == NULL) return NULL;
18 25
    glyph_t *ret = malloc(sizeof(glyph_t));
......
37 44
    }
38 45
    return ret;
39 46
}
47
/**
48
 * @brief Destruct glyph.
49
 * @param   p   Pointer to glyph to be destroyed
50
 */
40 51
static void (glyph_dtor)(glyph_t *p){
41 52
    if(p == NULL) return;
42 53
    free(p->map);
43 54
    free(p);
44 55
}
56
/**
57
 * @brief Draw glyph to an alpha-buffer.
58
 *
59
 * An alpha-buffer is an array of uint8_t that represents transparencies.
60
 * It proves fit as a tool for drawing text.
61
 * @param   p       Pointer to glyph to be drawn
62
 * @param   x       X-position to draw the glyph
63
 * @param   y       Y-position to draw the glyph
64
 * @param   alp_buf Alpha-buffer to which the glyph will be drawn
65
 * @param   W       Width of the alpha-buffer
66
 * @param   H       Height of the alpha-buffer
67
 */
45 68
static int (glyph_draw_to_alpha_buffer)(const glyph_t *p, int16_t x, int16_t y, uint8_t *alp_buf, uint16_t W, uint16_t H){
46 69
    if(p == NULL) return NULL_PTR;
47 70
    for(int16_t h = 0; h < p->h; ++h){
......
84 107
        return NULL;
85 108
    }
86 109
}
87
int (font_dtor)(font_t *p){
88
    if(p == NULL) return SUCCESS;
110
void (font_dtor)(font_t *p){
111
    if(p == NULL) return;
89 112
    for(size_t i = 0; i < p->nchars; ++i)
90 113
        glyph_dtor(p->glyphs[i]);
91 114
    free(p->glyphs);
92 115
    free(p);
93
    return SUCCESS;
94 116
}
95 117

  
96 118
static font_t *consolas     = NULL;
......
104 126
}
105 127
const font_t* font_get_default(void){ return default_font; }
106 128
const font_t* font_get_consolas(void){ return consolas; }
107
int (font_free)(void){
108
    int r;
109
    if((r = font_dtor(consolas))) return r;
129
void (font_free)(void){
130
    font_dtor(consolas);
110 131
    consolas = NULL;
111 132
    default_font = NULL;
112
    return SUCCESS;
113 133
}
114 134

  
115 135
/// TEXT
......
148 168
    if(p->txt == NULL) return;
149 169
    strcpy(p->txt, txt);
150 170
}
151
char* (text_get_string)(const text_t *p){return p->txt; }
171
const char* (text_get_string)(const text_t *p){return p->txt; }
152 172
void (text_set_pos)   (text_t *p, int16_t x, int16_t y){ p->x = x; p->y = y; }
153 173
void (text_set_size)  (text_t *p, unsigned size       ){ p->size = size    ; }
154 174
void (text_set_color) (text_t *p, uint32_t color      ){ p->color = color  ; }

Also available in: Unified diff