nuclear@6: #include nuclear@6: #include "imtk.h" nuclear@6: #include "state.h" nuclear@6: #include "draw.h" nuclear@6: nuclear@6: nuclear@6: #define CHECKBOX_SIZE 14 nuclear@6: nuclear@6: nuclear@6: static void draw_checkbox(int id, const char *label, int x, int y, int state); nuclear@6: nuclear@6: nuclear@6: int imtk_checkbox(int id, const char *label, int x, int y, int state) nuclear@6: { nuclear@6: int sz = CHECKBOX_SIZE; nuclear@6: int over = 0; nuclear@6: nuclear@6: assert(id >= 0); nuclear@6: nuclear@6: if(imtk_hit_test(x, y, sz, sz)) { nuclear@6: imtk_set_hot(id); nuclear@6: over = 1; nuclear@6: } nuclear@6: nuclear@6: if(imtk_button_state(IMTK_LEFT_BUTTON)) { nuclear@6: if(over) { nuclear@6: imtk_set_active(id); nuclear@6: } nuclear@6: } else { /* mouse button up */ nuclear@6: if(imtk_is_active(id)) { nuclear@6: imtk_set_active(-1); nuclear@6: if(imtk_is_hot(id) && over) { nuclear@6: state = !state; nuclear@6: } nuclear@6: } nuclear@6: } nuclear@6: nuclear@6: draw_checkbox(id, label, x, y, state); nuclear@6: return state; nuclear@6: } nuclear@6: nuclear@6: static void draw_checkbox(int id, const char *label, int x, int y, int state) nuclear@6: { nuclear@6: static const int sz = CHECKBOX_SIZE; nuclear@6: nuclear@6: if(imtk_hit_test(x, y, sz, sz)) { nuclear@6: glColor4fv(imtk_get_color(IMTK_FOCUS_COLOR)); nuclear@6: } else { nuclear@6: glColor4fv(imtk_get_color(IMTK_BASE_COLOR)); nuclear@6: } nuclear@6: nuclear@8: imtk_draw_rect(x, y, sz, sz, 0); nuclear@6: imtk_draw_frame(x, y, sz, sz, FRAME_INSET); nuclear@6: nuclear@6: glColor4fv(imtk_get_color(IMTK_TEXT_COLOR)); nuclear@6: if(state) { nuclear@6: glPushAttrib(GL_LINE_BIT); nuclear@6: glLineWidth(2); nuclear@6: nuclear@6: glBegin(GL_LINES); nuclear@6: glVertex2f(x + 2, y + 2); nuclear@6: glVertex2f(x + sz - 2, y + sz - 2); nuclear@6: glVertex2f(x + sz - 2, y + 2); nuclear@6: glVertex2f(x + 2, y + sz - 2); nuclear@6: glEnd(); nuclear@6: nuclear@6: glPopAttrib(); nuclear@6: } nuclear@6: nuclear@6: imtk_draw_string(x + sz + 5, y + sz - 2, label); nuclear@6: } nuclear@6: