8 #define CHECKBOX_SIZE 14
11 static void draw_checkbox(int id, const char *label, int x, int y, int state, int over);
13 int imtk_checkbox(int id, const char *label, int x, int y, int state)
15 int sz = CHECKBOX_SIZE;
16 int full_size, over = 0;
20 if(x == IMTK_AUTO || y == IMTK_AUTO) {
21 imtk_layout_get_pos(&x, &y);
24 full_size = sz + imtk_string_size(label) + 5;
25 if(imtk_hit_test(x, y, full_size, sz)) {
30 if(imtk_button_state(IMTK_LEFT_BUTTON)) {
34 } else { /* mouse button up */
35 if(imtk_is_active(id)) {
37 if(imtk_is_hot(id) && over) {
43 draw_checkbox(id, label, x, y, state, over);
44 imtk_layout_advance(full_size, sz);
48 static float v[][2] = {
50 {0.121, 0.325}, /* 1 */
52 {0.28, 0.125}, /* 3 */
54 {0.42, -0.122}, /* 5 */
57 {0.625, 0.65}, /* 8 */
59 {0.875, 0.92}, /* 10 */
60 {1.13, 1.145} /* 11 */
62 #define TRI(a, b, c) (glVertex2fv(v[a]), glVertex2fv(v[b]), glVertex2fv(v[c]))
64 static void draw_checkbox(int id, const char *label, int x, int y, int state, int over)
66 static const int sz = CHECKBOX_SIZE;
67 unsigned int attr = 0;
68 float tcol[4], bcol[4];
71 attr |= IMTK_FOCUS_BIT;
73 if(imtk_is_active(id)) {
74 attr |= IMTK_PRESS_BIT;
76 memcpy(tcol, imtk_get_color(IMTK_BOTTOM_COLOR | attr), sizeof tcol);
77 memcpy(bcol, imtk_get_color(IMTK_TOP_COLOR | attr), sizeof bcol);
79 imtk_draw_rect(x, y, sz, sz, tcol, bcol);
80 imtk_draw_frame(x, y, sz, sz, FRAME_INSET);
82 glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));
84 glMatrixMode(GL_MODELVIEW);
86 glTranslatef(x, y + sz, 0);
87 glScalef(sz * 1.2, -sz * 1.3, 1);
89 glBegin(GL_TRIANGLES);
90 glColor4fv(imtk_get_color(IMTK_CHECK_COLOR));
106 glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));
107 imtk_draw_string(x + sz + 5, y + sz - 2, label);