Project

General

Profile

Revision 313

organizing fonts

View differences:

proj/libs/graph/include/font.h
16 16
struct font;
17 17
typedef struct font font_t;
18 18
font_t* (font_ctor)(const char *s);
19
void    (font_dtor)(font_t *p);
19
int     (font_dtor)(font_t *p);
20 20

  
21 21
font_t *consolas;
22
font_t *default_font;
22 23

  
24
int (font_init)(void);
25
int (font_free)(void);
26

  
23 27
struct text;
24 28
typedef struct text text_t;
25 29
text_t* (text_ctor)(const font_t *fnt, const char *txt);
proj/libs/graph/src/font.c
84 84
        return NULL;
85 85
    }
86 86
}
87
void (font_dtor)(font_t *p){
88
    if(p == NULL) return;
87
int (font_dtor)(font_t *p){
88
    if(p == NULL) return SUCCESS;
89 89
    for(size_t i = 0; i < p->nchars; ++i)
90 90
        glyph_dtor(p->glyphs[i]);
91 91
    free(p->glyphs);
92 92
    free(p);
93
    return SUCCESS;
93 94
}
94 95

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

  
99
int (font_init)(void){
100
    consolas = font_ctor("/home/lcom/labs/proj/media/font/Consolas/xpm2");
101
    if(consolas == NULL) return NULL_PTR;
102
    default_font = consolas;
103
    return SUCCESS;
104
}
105
int (font_free)(void){
106
    int r;
107
    if((r = font_dtor(consolas))) return r;
108
    consolas = NULL;
109
    default_font = NULL;
110
    return SUCCESS;
111
}
112

  
95 113
struct text{
96 114
    const font_t *fnt;
97 115
    char *txt;
proj/libs/uart/src/hltp.c
111 111

  
112 112
    return ret;
113 113
}
114

  
115 114
int hltp_send_remote_info(const remote_info_t *p) {
116 115
    // struct size
117 116
    size_t struct_size = sizeof(keys_t) + sizeof(int32_t) * 2 + sizeof(size_t) + sizeof(double) * (3 *p->bullets_shot);
proj/src/ent.c
41 41
    ret->y = 0.0;
42 42
    ret->health = 100;
43 43
    ret->current_health = ret->health;
44
    ret->txt = text_ctor(consolas, "");
44
    ret->txt = text_ctor(default_font, "");
45 45
    ret->type = type;
46 46
    ret->team = team;
47 47
    ret->dude   = sprite_ctor(dude  );
proj/src/proj.c
49 49
    return 0;
50 50
}
51 51

  
52
font_t               *consolas      = NULL;
53 52
basic_sprite_t       *bsp_crosshair = NULL;
54 53
basic_sprite_t       *bsp_shooter   = NULL;
55 54
basic_sprite_t       *bsp_zombie    = NULL;
......
66 65

  
67 66
    int r;
68 67

  
69
    consolas = font_ctor("/home/lcom/labs/proj/media/font/Consolas/xpm2");
70
    if(consolas == NULL){ printf("Failed to load consolas\n"); return 1; }
68
    if(font_init()){ printf("Failed to initialize fonts\n"); return 1; }
71 69

  
72 70
    /// subscribe interrupts
73 71
    if (subscribe_all()) { return 1; }
......
82 80
    /// Load stuff
83 81
    {
84 82
        graph_clear_screen();
85
        text_t *txt = text_ctor(consolas, "Loading...");
83
        text_t *txt = text_ctor(default_font, "Loading...");
86 84
        text_set_pos(txt, graph_get_XRes()/2, graph_get_YRes()/2);
87 85
        text_set_valign(txt, text_valign_center);
88 86
        text_set_halign(txt, text_halign_center);
......
102 100
        sp_crosshair = sprite_ctor(bsp_crosshair); if(sp_crosshair == NULL) printf("Failed to get crosshair sprite\n");
103 101
    }
104 102

  
105
    menu_t *main_menu = menu_ctor(consolas);
103
    menu_t *main_menu = menu_ctor(default_font);
106 104
    menu_add_item(main_menu, "Single player");
107 105
    menu_add_item(main_menu, "Multiplayer");
108 106
    menu_add_item(main_menu, "Chat");
......
167 165
    basic_sprite_dtor      (bsp_pistol   ); bsp_pistol    = NULL;
168 166
    basic_sprite_dtor      (bsp_nothing  ); bsp_nothing   = NULL;
169 167
    map_dtor               (map1         ); map1          = NULL;
170
    font_dtor              (consolas     ); consolas      = NULL;
168
    if(font_free()){ printf("Failed to free fonts\n"); return 1; }
171 169

  
172 170
    // Unsubscribe interrupts
173 171
    if (unsubscribe_all()) {
......
207 205
static int (multiplayer)(void) {
208 206
    int r;
209 207

  
210
    menu_t *main_menu = menu_ctor(consolas);
208
    menu_t *main_menu = menu_ctor(default_font);
211 209
    menu_add_item(main_menu, "Create");
212 210
    menu_add_item(main_menu, "Connect");
213 211
    menu_add_item(main_menu, "Back");
......
272 270
    nctp_set_processor(multiplayer_process);/*
273 271

  
274 272
    ent_set_scale(DEFAULT_SCALE);
275
    text_timer_t *in_game_timer = timer_ctor(consolas);
273
    text_timer_t *in_game_timer = timer_ctor(default_font);
276 274

  
277 275
    list_t *shooter_list = list_ctor();
278 276

  
......
336 334
    nctp_set_processor(multiplayer_process);
337 335

  
338 336
    ent_set_scale(DEFAULT_SCALE);
339
    text_timer_t *in_game_timer = timer_ctor(consolas);
337
    text_timer_t *in_game_timer = timer_ctor(default_font);
340 338

  
341 339
    list_t *shooter_list = list_ctor();
342 340

  
......
400 398

  
401 399
    int r;
402 400

  
403
    menu_t *main_menu = menu_ctor(consolas);
401
    menu_t *main_menu = menu_ctor(default_font);
404 402
    menu_add_item(main_menu, "Campaign");
405 403
    menu_add_item(main_menu, "Zombies");
406 404
    menu_add_item(main_menu, "Back");
......
464 462
    int r;
465 463

  
466 464
    ent_set_scale(DEFAULT_SCALE);
467
    text_timer_t *in_game_timer = timer_ctor(consolas);
465
    text_timer_t *in_game_timer = timer_ctor(default_font);
468 466

  
469 467
    list_t *shooter_list = list_ctor();
470 468

  
......
572 570
    int r;
573 571

  
574 572
    ent_set_scale(DEFAULT_SCALE);
575
    text_timer_t *in_game_timer = timer_ctor(consolas);
573
    text_timer_t *in_game_timer = timer_ctor(default_font);
576 574

  
577 575
    list_t *shooter_list = list_ctor();
578 576

  
......
751 749
        rectangle_set_fill_trans(r_buffer, GRAPH_TRANSPARENT);
752 750
    }
753 751
    text_t      *t_buffer = NULL; {
754
        t_buffer = text_ctor(consolas, "");
752
        t_buffer = text_ctor(default_font, "");
755 753
        text_set_pos(t_buffer, rectangle_get_x(r_buffer)+50,
756 754
        rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)/2);
757 755
        text_set_halign(t_buffer, text_halign_left);
......
759 757
        text_set_color (t_buffer, TEXT_COLOR);
760 758
    }
761 759
    text_t      *t_size   = NULL; {
762
        t_size = text_ctor(consolas, "");
760
        t_size = text_ctor(default_font, "");
763 761
        text_set_pos(t_size, rectangle_get_x(r_buffer)+rectangle_get_w(r_buffer)-5,
764 762
        rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)-5);
765 763
        text_set_halign(t_size, text_halign_right);
......
782 780
    }
783 781
    /** t_text */ {
784 782
    for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
785
        t_text[i] = text_ctor(consolas, " ");
783
        t_text[i] = text_ctor(default_font, " ");
786 784
        text_set_pos(t_text[i], rectangle_get_x(r_text)+50,
787 785
        rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-25*i);
788 786
        text_set_halign(t_text[i], text_halign_left);

Also available in: Unified diff