imtk

annotate src/checkbox.c @ 12:17c9525b2e35

merged -lGLU fix with listbox patch
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 17 Apr 2011 18:20:23 +0300
parents 10604ff95527
children 9c7987064bb0
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@11 10 static void draw_checkbox(int id, const char *label, int x, int y, int state, int over);
nuclear@6 11
nuclear@6 12 int imtk_checkbox(int id, const char *label, int x, int y, int state)
nuclear@6 13 {
nuclear@6 14 int sz = CHECKBOX_SIZE;
nuclear@6 15 int over = 0;
nuclear@6 16
nuclear@6 17 assert(id >= 0);
nuclear@6 18
nuclear@11 19 if(imtk_hit_test(x, y, sz + imtk_string_size(label) + 5, sz)) {
nuclear@6 20 imtk_set_hot(id);
nuclear@6 21 over = 1;
nuclear@6 22 }
nuclear@6 23
nuclear@6 24 if(imtk_button_state(IMTK_LEFT_BUTTON)) {
nuclear@6 25 if(over) {
nuclear@6 26 imtk_set_active(id);
nuclear@6 27 }
nuclear@6 28 } else { /* mouse button up */
nuclear@6 29 if(imtk_is_active(id)) {
nuclear@6 30 imtk_set_active(-1);
nuclear@6 31 if(imtk_is_hot(id) && over) {
nuclear@6 32 state = !state;
nuclear@6 33 }
nuclear@6 34 }
nuclear@6 35 }
nuclear@6 36
nuclear@11 37 draw_checkbox(id, label, x, y, state, over);
nuclear@6 38 return state;
nuclear@6 39 }
nuclear@6 40
nuclear@11 41 static void draw_checkbox(int id, const char *label, int x, int y, int state, int over)
nuclear@6 42 {
nuclear@6 43 static const int sz = CHECKBOX_SIZE;
nuclear@6 44
nuclear@11 45 if(over) {
nuclear@6 46 glColor4fv(imtk_get_color(IMTK_FOCUS_COLOR));
nuclear@6 47 } else {
nuclear@6 48 glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
nuclear@6 49 }
nuclear@6 50
nuclear@8 51 imtk_draw_rect(x, y, sz, sz, 0);
nuclear@6 52 imtk_draw_frame(x, y, sz, sz, FRAME_INSET);
nuclear@6 53
nuclear@6 54 glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));
nuclear@6 55 if(state) {
nuclear@6 56 glPushAttrib(GL_LINE_BIT);
nuclear@6 57 glLineWidth(2);
nuclear@6 58
nuclear@6 59 glBegin(GL_LINES);
nuclear@6 60 glVertex2f(x + 2, y + 2);
nuclear@6 61 glVertex2f(x + sz - 2, y + sz - 2);
nuclear@6 62 glVertex2f(x + sz - 2, y + 2);
nuclear@6 63 glVertex2f(x + 2, y + sz - 2);
nuclear@6 64 glEnd();
nuclear@6 65
nuclear@6 66 glPopAttrib();
nuclear@6 67 }
nuclear@6 68
nuclear@6 69 imtk_draw_string(x + sz + 5, y + sz - 2, label);
nuclear@6 70 }
nuclear@6 71