Project

General

Profile

Revision 314

some changes in fonts and ent.c

View differences:

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

  
11
/// GLYPH
11 12
struct glyph{
12 13
    uint16_t w, h;
13 14
    uint8_t *map;
......
55 56
    return SUCCESS;
56 57
}
57 58

  
59
/// FONT
58 60
struct font{
59 61
    size_t nchars;
60 62
    glyph_t **glyphs;
61 63
};
62

  
63 64
font_t* (font_ctor)(const char *s){
64 65
    font_t *ret = malloc(sizeof(font_t));
65 66
    if(ret == NULL) return NULL;
......
93 94
    return SUCCESS;
94 95
}
95 96

  
96
font_t *consolas = NULL;
97
font_t *default_font = NULL;
97
static font_t *consolas     = NULL;
98
static font_t *default_font = NULL;
98 99

  
99 100
int (font_init)(void){
100 101
    consolas = font_ctor("/home/lcom/labs/proj/media/font/Consolas/xpm2");
......
102 103
    default_font = consolas;
103 104
    return SUCCESS;
104 105
}
106
const font_t* font_get_default(void){ return default_font; }
107
const font_t* font_get_consolas(void){ return consolas; }
105 108
int (font_free)(void){
106 109
    int r;
107 110
    if((r = font_dtor(consolas))) return r;
......
110 113
    return SUCCESS;
111 114
}
112 115

  
116
/// TEXT
113 117
struct text{
114 118
    const font_t *fnt;
115 119
    char *txt;
116 120
    int16_t x, y;
117 121
    int size;
118 122
    uint32_t color;
119
    enum text_valign valign;
120
    enum text_halign halign;
123
    text_valign valign;
124
    text_halign halign;
121 125
};
122 126
text_t* (text_ctor)(const font_t *fnt, const char *txt){
123 127
    if(fnt == NULL) return NULL;
......
125 129
    if(ret == NULL) return NULL;
126 130
    ret->fnt = fnt;
127 131
    ret->txt = NULL;
128
    text_set_text(ret, txt);
132
    text_set_string(ret, txt);
129 133
    ret->x = 0;
130 134
    ret->y = 0;
131 135
    ret->size = 25;
......
139 143
    free(p->txt);
140 144
    free(p);
141 145
}
142
void (text_set_text) (text_t *p, const char *txt){
146
void (text_set_string) (text_t *p, const char *txt){
143 147
    size_t sz = strlen(txt);
144 148
    p->txt = realloc(p->txt, (sz+1)*sizeof(char));
145 149
    if(p->txt == NULL) return;
146 150
    strcpy(p->txt, txt);
147 151
}
148 152
char* (text_get_string)(const text_t *p){return p->txt; }
149
void (text_set_pos)   (text_t *p, int16_t x, int16_t y   ){ p->x = x; p->y = y; }
150
void (text_set_size)  (text_t *p, unsigned size          ){ p->size = size    ; }
151
void (text_set_color) (text_t *p, uint32_t color         ){ p->color = color  ; }
152
void (text_set_valign)(text_t *p, enum text_valign valign){ p->valign = valign; }
153
void (text_set_halign)(text_t *p, enum text_halign halign){ p->halign = halign; }
153
void (text_set_pos)   (text_t *p, int16_t x, int16_t y){ p->x = x; p->y = y; }
154
void (text_set_size)  (text_t *p, unsigned size       ){ p->size = size    ; }
155
void (text_set_color) (text_t *p, uint32_t color      ){ p->color = color  ; }
156
void (text_set_valign)(text_t *p, text_valign valign  ){ p->valign = valign; }
157
void (text_set_halign)(text_t *p, text_halign halign  ){ p->halign = halign; }
154 158
int16_t (text_get_x)  (const text_t *p){ return p->x; }
155 159
int16_t (text_get_y)  (const text_t *p){ return p->y; }
156 160

  

Also available in: Unified diff