imtk

annotate 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
rev   line source
nuclear@6 1 #include <assert.h>
nuclear@6 2 #include "imtk.h"
nuclear@6 3 #include "state.h"
nuclear@6 4 #include "draw.h"
nuclear@6 5
nuclear@6 6
nuclear@6 7 #define CHECKBOX_SIZE 14
nuclear@6 8
nuclear@6 9
nuclear@6 10 static void draw_checkbox(int id, const char *label, int x, int y, int state);
nuclear@6 11
nuclear@6 12
nuclear@6 13 int imtk_checkbox(int id, const char *label, int x, int y, int state)
nuclear@6 14 {
nuclear@6 15 int sz = CHECKBOX_SIZE;
nuclear@6 16 int over = 0;
nuclear@6 17
nuclear@6 18 assert(id >= 0);
nuclear@6 19
nuclear@6 20 if(imtk_hit_test(x, y, sz, sz)) {
nuclear@6 21 imtk_set_hot(id);
nuclear@6 22 over = 1;
nuclear@6 23 }
nuclear@6 24
nuclear@6 25 if(imtk_button_state(IMTK_LEFT_BUTTON)) {
nuclear@6 26 if(over) {
nuclear@6 27 imtk_set_active(id);
nuclear@6 28 }
nuclear@6 29 } else { /* mouse button up */
nuclear@6 30 if(imtk_is_active(id)) {
nuclear@6 31 imtk_set_active(-1);
nuclear@6 32 if(imtk_is_hot(id) && over) {
nuclear@6 33 state = !state;
nuclear@6 34 }
nuclear@6 35 }
nuclear@6 36 }
nuclear@6 37
nuclear@6 38 draw_checkbox(id, label, x, y, state);
nuclear@6 39 return state;
nuclear@6 40 }
nuclear@6 41
nuclear@6 42 static void draw_checkbox(int id, const char *label, int x, int y, int state)
nuclear@6 43 {
nuclear@6 44 static const int sz = CHECKBOX_SIZE;
nuclear@6 45
nuclear@6 46 if(imtk_hit_test(x, y, sz, sz)) {
nuclear@6 47 glColor4fv(imtk_get_color(IMTK_FOCUS_COLOR));
nuclear@6 48 } else {
nuclear@6 49 glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
nuclear@6 50 }
nuclear@6 51
nuclear@8 52 imtk_draw_rect(x, y, sz, sz, 0);
nuclear@6 53 imtk_draw_frame(x, y, sz, sz, FRAME_INSET);
nuclear@6 54
nuclear@6 55 glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));
nuclear@6 56 if(state) {
nuclear@6 57 glPushAttrib(GL_LINE_BIT);
nuclear@6 58 glLineWidth(2);
nuclear@6 59
nuclear@6 60 glBegin(GL_LINES);
nuclear@6 61 glVertex2f(x + 2, y + 2);
nuclear@6 62 glVertex2f(x + sz - 2, y + sz - 2);
nuclear@6 63 glVertex2f(x + sz - 2, y + 2);
nuclear@6 64 glVertex2f(x + 2, y + sz - 2);
nuclear@6 65 glEnd();
nuclear@6 66
nuclear@6 67 glPopAttrib();
nuclear@6 68 }
nuclear@6 69
nuclear@6 70 imtk_draw_string(x + sz + 5, y + sz - 2, label);
nuclear@6 71 }
nuclear@6 72