Project

General

Profile

Revision 297

chat working

View differences:

menu.c
22 22
    rectangle_t *frame;
23 23
};
24 24

  
25
static int menu_recalculate(menu_t *menu){
26
    const int Wtotal = 2*W1+W;
27
    const int Htotal = 2*H1+menu->sz*H+(menu->sz-1)*H2;
28
    int x = graph_get_XRes()/2-Wtotal/2;
29
    int y = graph_get_YRes()/2-Htotal/2;
30
    rectangle_set_pos (menu->frame, x, y);
31
    rectangle_set_size(menu->frame, Wtotal, Htotal);
32
    x += W1; y += H1;
33
    for(size_t i = 0; i < menu->sz; ++i, y+=H+H2){
34
        rectangle_set_pos(menu->r[i], x, y);
35
        text_set_pos     (menu->t[i], x+W/2, y+H/2);
36
    }
37
    return SUCCESS;
38
}
39

  
25 40
menu_t* (menu_ctor)(const font_t *fnt){
26 41
    if(fnt == NULL) return NULL;
27 42
    menu_t *ret = (menu_t*)malloc(sizeof(menu_t));
......
31 46
    ret->r = NULL;
32 47
    ret->t = NULL;
33 48

  
34
    ret->frame = rectangle_ctor(0, 0, 800, 500);
49
    ret->frame = rectangle_ctor(0, 0, 0, 0);
35 50
    rectangle_set_fill_color(ret->frame, GRAPH_BLACK);
36 51
    rectangle_set_outline_width(ret->frame, 6);
37 52
    rectangle_set_outline_color(ret->frame, GRAPH_WHITE);
38 53
    rectangle_set_fill_trans(ret->frame, GRAPH_TRANSPARENT);
39 54

  
55
    menu_recalculate(ret);
56

  
40 57
    return ret;
41 58
}
42 59

  
43
static int menu_recalculate(menu_t *menu){
44
    const int Wtotal = 2*W1+W;
45
    const int Htotal = 2*H1+menu->sz*H+(menu->sz-1)*H2;
46
    int x = graph_get_XRes()/2-Wtotal/2;
47
    int y = graph_get_YRes()/2-Htotal/2;
48
    rectangle_set_pos (menu->frame, x, y);
49
    rectangle_set_size(menu->frame, Wtotal, Htotal);
50
    x += W1; y += H1;
51
    for(size_t i = 0; i < menu->sz; ++i, y+=H+H2){
52
        rectangle_set_pos(menu->r[i], x, y);
53
        text_set_pos     (menu->t[i], x+W/2, y+H/2);
54
    }
55
    return SUCCESS;
56
}
57

  
58 60
int (menu_add_item)(menu_t *menu, const char *s){
59 61
    rectangle_t *r = rectangle_ctor(0, 0, W, H);
60 62
    text_t      *t = text_ctor(menu->fnt, s);

Also available in: Unified diff