7 static void calc_button_size(const char *label, int *wret, int *hret);
8 static void draw_button(int id, const char *label, int x, int y, int over);
10 int imtk_button(int id, const char *label, int x, int y)
17 if(x == IMTK_AUTO || y == IMTK_AUTO) {
18 imtk_layout_get_pos(&x, &y);
21 calc_button_size(label, &w, &h);
23 if(imtk_hit_test(x, y, w, h)) {
28 if(imtk_button_state(IMTK_LEFT_BUTTON)) {
32 } else { /* mouse button up */
33 if(imtk_is_active(id)) {
35 if(imtk_is_hot(id) && over) {
41 draw_button(id, label, x, y, over);
42 imtk_layout_advance(w, h);
46 static void draw_button(int id, const char *label, int x, int y, int over)
48 float tcol[4], bcol[4];
49 int width, height, active = imtk_is_active(id);
50 unsigned int attr = 0;
52 if(over) attr |= IMTK_FOCUS_BIT;
53 if(active) attr |= IMTK_PRESS_BIT;
55 calc_button_size(label, &width, &height);
57 memcpy(tcol, imtk_get_color(IMTK_TOP_COLOR | attr), sizeof tcol);
58 memcpy(bcol, imtk_get_color(IMTK_BOTTOM_COLOR | attr), sizeof bcol);
60 imtk_draw_rect(x, y, width, height, tcol, bcol);
61 imtk_draw_frame(x, y, width, height, active ? FRAME_INSET : FRAME_OUTSET);
63 glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));
64 imtk_draw_string(x + 20, y + 15, label);
67 static void calc_button_size(const char *label, int *wret, int *hret)
69 int strsz = imtk_string_size(label);
70 if(wret) *wret = strsz + 40;