imtk
diff src/button.c @ 14:df2bc9406561
added gradients
author | John Tsiombikas <nuclear@siggraph.org> |
---|---|
date | Tue, 19 Apr 2011 03:01:46 +0300 |
parents | 10604ff95527 |
children | c7a7ddbe7714 |
line diff
1.1 --- a/src/button.c Mon Apr 18 06:15:46 2011 +0300 1.2 +++ b/src/button.c Tue Apr 19 03:01:46 2011 +0300 1.3 @@ -1,10 +1,11 @@ 1.4 +#include <string.h> 1.5 #include <assert.h> 1.6 #include "imtk.h" 1.7 #include "state.h" 1.8 #include "draw.h" 1.9 1.10 static void calc_button_size(const char *label, int *wret, int *hret); 1.11 -static void draw_button(int id, const char *label, int x, int y); 1.12 +static void draw_button(int id, const char *label, int x, int y, int over); 1.13 1.14 int imtk_button(int id, const char *label, int x, int y) 1.15 { 1.16 @@ -33,24 +34,26 @@ 1.17 } 1.18 } 1.19 1.20 - draw_button(id, label, x, y); 1.21 + draw_button(id, label, x, y, over); 1.22 return res; 1.23 } 1.24 1.25 -static void draw_button(int id, const char *label, int x, int y) 1.26 +static void draw_button(int id, const char *label, int x, int y, int over) 1.27 { 1.28 - int width, height; 1.29 + float tcol[4], bcol[4]; 1.30 + int width, height, active = imtk_is_active(id); 1.31 + unsigned int attr = 0; 1.32 + 1.33 + if(over) attr |= IMTK_FOCUS_BIT; 1.34 + if(active) attr |= IMTK_PRESS_BIT; 1.35 1.36 calc_button_size(label, &width, &height); 1.37 1.38 - if(imtk_hit_test(x, y, width, height)) { 1.39 - glColor4fv(imtk_get_color(IMTK_FOCUS_COLOR)); 1.40 - } else { 1.41 - glColor4fv(imtk_get_color(IMTK_BASE_COLOR)); 1.42 - } 1.43 + memcpy(tcol, imtk_get_color(IMTK_TOP_COLOR | attr), sizeof tcol); 1.44 + memcpy(bcol, imtk_get_color(IMTK_BOTTOM_COLOR | attr), sizeof bcol); 1.45 1.46 - imtk_draw_rect(x, y, width, height, 0); 1.47 - imtk_draw_frame(x, y, width, height, imtk_is_active(id) ? FRAME_INSET : FRAME_OUTSET); 1.48 + imtk_draw_rect(x, y, width, height, tcol, bcol); 1.49 + imtk_draw_frame(x, y, width, height, active ? FRAME_INSET : FRAME_OUTSET); 1.50 1.51 glColor4fv(imtk_get_color(IMTK_TEXT_COLOR)); 1.52 imtk_draw_string(x + 20, y + 15, label);