nuclear@14: #include 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@11: static void draw_checkbox(int id, const char *label, int x, int y, int state, int over); 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@20: int full_size, over = 0; nuclear@6: nuclear@6: assert(id >= 0); nuclear@6: nuclear@20: if(x == IMTK_AUTO || y == IMTK_AUTO) { nuclear@20: imtk_layout_get_pos(&x, &y); nuclear@20: } nuclear@20: nuclear@20: full_size = sz + imtk_string_size(label) + 5; nuclear@20: if(imtk_hit_test(x, y, full_size, 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@11: draw_checkbox(id, label, x, y, state, over); nuclear@20: imtk_layout_advance(full_size, sz); nuclear@6: return state; nuclear@6: } nuclear@6: nuclear@14: static float v[][2] = { nuclear@14: {-0.2, 0.63}, /* 0 */ nuclear@14: {0.121, 0.325}, /* 1 */ nuclear@14: {0.15, 0.5}, /* 2 */ nuclear@14: {0.28, 0.125}, /* 3 */ nuclear@14: {0.38, 0.33}, /* 4 */ nuclear@14: {0.42, -0.122}, /* 5 */ nuclear@14: {0.58, 0.25}, /* 6 */ nuclear@14: {0.72, 0.52}, /* 7 */ nuclear@14: {0.625, 0.65}, /* 8 */ nuclear@14: {0.89, 0.78}, /* 9 */ nuclear@14: {0.875, 0.92}, /* 10 */ nuclear@14: {1.13, 1.145} /* 11 */ nuclear@14: }; nuclear@14: #define TRI(a, b, c) (glVertex2fv(v[a]), glVertex2fv(v[b]), glVertex2fv(v[c])) nuclear@14: nuclear@11: static void draw_checkbox(int id, const char *label, int x, int y, int state, int over) nuclear@6: { nuclear@6: static const int sz = CHECKBOX_SIZE; nuclear@14: unsigned int attr = 0; nuclear@14: float tcol[4], bcol[4]; nuclear@6: nuclear@11: if(over) { nuclear@14: attr |= IMTK_FOCUS_BIT; nuclear@6: } nuclear@14: if(imtk_is_active(id)) { nuclear@14: attr |= IMTK_PRESS_BIT; nuclear@14: } nuclear@14: memcpy(tcol, imtk_get_color(IMTK_BOTTOM_COLOR | attr), sizeof tcol); nuclear@14: memcpy(bcol, imtk_get_color(IMTK_TOP_COLOR | attr), sizeof bcol); nuclear@6: nuclear@14: imtk_draw_rect(x, y, sz, sz, tcol, bcol); 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@13: glMatrixMode(GL_MODELVIEW); nuclear@13: glPushMatrix(); nuclear@13: glTranslatef(x, y + sz, 0); nuclear@13: glScalef(sz * 1.2, -sz * 1.3, 1); nuclear@6: nuclear@13: glBegin(GL_TRIANGLES); nuclear@13: glColor4fv(imtk_get_color(IMTK_CHECK_COLOR)); nuclear@13: TRI(0, 1, 2); nuclear@13: TRI(1, 3, 2); nuclear@13: TRI(3, 4, 2); nuclear@13: TRI(3, 5, 4); nuclear@13: TRI(4, 5, 6); nuclear@13: TRI(4, 6, 7); nuclear@13: TRI(4, 7, 8); nuclear@13: TRI(8, 7, 9); nuclear@13: TRI(8, 9, 10); nuclear@13: TRI(10, 9, 11); nuclear@6: glEnd(); nuclear@6: nuclear@13: glPopMatrix(); nuclear@6: } nuclear@6: nuclear@13: glColor4fv(imtk_get_color(IMTK_TEXT_COLOR)); nuclear@6: imtk_draw_string(x + sz + 5, y + sz - 2, label); nuclear@6: } nuclear@6: