imtk

view src/checkbox.c @ 6:38609a9f7586

reorganizing ...
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 14 Apr 2011 14:22:42 +0300
parents
children 10604ff95527
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 glBegin(GL_QUADS);
53 glVertex2f(x, y);
54 glVertex2f(x + sz, y);
55 glVertex2f(x + sz, y + sz);
56 glVertex2f(x, y + sz);
57 glEnd();
59 imtk_draw_frame(x, y, sz, sz, FRAME_INSET);
61 glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));
62 if(state) {
63 glPushAttrib(GL_LINE_BIT);
64 glLineWidth(2);
66 glBegin(GL_LINES);
67 glVertex2f(x + 2, y + 2);
68 glVertex2f(x + sz - 2, y + sz - 2);
69 glVertex2f(x + sz - 2, y + 2);
70 glVertex2f(x + 2, y + sz - 2);
71 glEnd();
73 glPopAttrib();
74 }
76 imtk_draw_string(x + sz + 5, y + sz - 2, label);
77 }