imtk
diff src/listbox.c @ 18:737e9047d9c9
added radio group
author | John Tsiombikas <nuclear@siggraph.org> |
---|---|
date | Mon, 25 Apr 2011 08:54:05 +0300 |
parents | ac2a8d8fca9a |
children | 11da537aeba6 |
line diff
1.1 --- a/src/listbox.c Tue Apr 19 08:36:23 2011 +0300 1.2 +++ b/src/listbox.c Mon Apr 25 08:54:05 2011 +0300 1.3 @@ -8,10 +8,22 @@ 1.4 #define ITEM_HEIGHT 18 1.5 #define PAD 3 1.6 1.7 +static int list_radio(int id, const char *list, int sel, int x, int y, void (*draw)()); 1.8 static void draw_listbox(int id, const char *list, int sel, int x, int y, int width, int nitems, int over); 1.9 +static void draw_radio(int id, const char *list, int sel, int x, int y, int width, int nitems, int over); 1.10 1.11 int imtk_listbox(int id, const char *list, int sel, int x, int y) 1.12 { 1.13 + return list_radio(id, list, sel, x, y, draw_listbox); 1.14 +} 1.15 + 1.16 +int imtk_radiogroup(int id, const char *list, int sel, int x, int y) 1.17 +{ 1.18 + return list_radio(id, list, sel, x, y, draw_radio); 1.19 +} 1.20 + 1.21 +static int list_radio(int id, const char *list, int sel, int x, int y, void (*draw)()) 1.22 +{ 1.23 int i, max_width, nitems, over; 1.24 const char *ptr; 1.25 1.26 @@ -48,7 +60,7 @@ 1.27 } 1.28 } 1.29 1.30 - draw_listbox(id, list, sel, x, y, max_width, nitems, over); 1.31 + draw(id, list, sel, x, y, max_width, nitems, over); 1.32 return sel; 1.33 } 1.34 1.35 @@ -127,3 +139,36 @@ 1.36 1.37 imtk_draw_frame(x, y, width, ITEM_HEIGHT * nitems, FRAME_INSET); 1.38 } 1.39 + 1.40 +static void draw_radio(int id, const char *list, int sel, int x, int y, int width, int nitems, int over) 1.41 +{ 1.42 + int i; 1.43 + const char *item = list; 1.44 + float rad = ITEM_HEIGHT * 0.5; 1.45 + 1.46 + for(i=0; i<nitems; i++) { 1.47 + int item_y = i * ITEM_HEIGHT + y; 1.48 + unsigned int attr = 0; 1.49 + float tcol[4], bcol[4]; 1.50 + 1.51 + if(over - 1 == i) { 1.52 + attr |= IMTK_FOCUS_BIT; 1.53 + } 1.54 + 1.55 + memcpy(tcol, imtk_get_color(IMTK_BOTTOM_COLOR | attr), sizeof tcol); 1.56 + memcpy(bcol, imtk_get_color(IMTK_TOP_COLOR | attr), sizeof bcol); 1.57 + 1.58 + imtk_draw_disc(x + rad, item_y + rad, rad * 0.8, 5, tcol, bcol); 1.59 + 1.60 + if(i == sel) { 1.61 + attr |= IMTK_SEL_BIT; 1.62 + memcpy(tcol, imtk_get_color(IMTK_TOP_COLOR | attr), sizeof tcol); 1.63 + memcpy(bcol, imtk_get_color(IMTK_BOTTOM_COLOR | attr), sizeof bcol); 1.64 + imtk_draw_disc(x + rad, item_y + ITEM_HEIGHT / 2, rad * 0.6, 5, tcol, bcol); 1.65 + } 1.66 + 1.67 + glColor4fv(imtk_get_color(IMTK_TEXT_COLOR)); 1.68 + imtk_draw_string(x + rad * 2.0 + 3, item_y + ITEM_HEIGHT - 5, item); 1.69 + item += strlen(item) + 1; 1.70 + } 1.71 +}