imtk

view src/checkbox.c @ 8:10604ff95527

imtk_draw_rect
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 14 Apr 2011 23:21:56 +0300
parents 38609a9f7586
children eae09a1dca1d
line source
1 #include <assert.h>
2 #include "imtk.h"
3 #include "state.h"
4 #include "draw.h"
7 #define CHECKBOX_SIZE 14
10 static void draw_checkbox(int id, const char *label, int x, int y, int state);
13 int imtk_checkbox(int id, const char *label, int x, int y, int state)
14 {
15 int sz = CHECKBOX_SIZE;
16 int over = 0;
18 assert(id >= 0);
20 if(imtk_hit_test(x, y, sz, sz)) {
21 imtk_set_hot(id);
22 over = 1;
23 }
25 if(imtk_button_state(IMTK_LEFT_BUTTON)) {
26 if(over) {
27 imtk_set_active(id);
28 }
29 } else { /* mouse button up */
30 if(imtk_is_active(id)) {
31 imtk_set_active(-1);
32 if(imtk_is_hot(id) && over) {
33 state = !state;
34 }
35 }
36 }
38 draw_checkbox(id, label, x, y, state);
39 return state;
40 }
42 static void draw_checkbox(int id, const char *label, int x, int y, int state)
43 {
44 static const int sz = CHECKBOX_SIZE;
46 if(imtk_hit_test(x, y, sz, sz)) {
47 glColor4fv(imtk_get_color(IMTK_FOCUS_COLOR));
48 } else {
49 glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
50 }
52 imtk_draw_rect(x, y, sz, sz, 0);
53 imtk_draw_frame(x, y, sz, sz, FRAME_INSET);
55 glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));
56 if(state) {
57 glPushAttrib(GL_LINE_BIT);
58 glLineWidth(2);
60 glBegin(GL_LINES);
61 glVertex2f(x + 2, y + 2);
62 glVertex2f(x + sz - 2, y + sz - 2);
63 glVertex2f(x + sz - 2, y + 2);
64 glVertex2f(x + 2, y + sz - 2);
65 glEnd();
67 glPopAttrib();
68 }
70 imtk_draw_string(x + sz + 5, y + sz - 2, label);
71 }