imtk

diff src/checkbox.c @ 14:df2bc9406561

added gradients
author John Tsiombikas <nuclear@siggraph.org>
date Tue, 19 Apr 2011 03:01:46 +0300
parents 9c7987064bb0
children c7a7ddbe7714
line diff
     1.1 --- a/src/checkbox.c	Mon Apr 18 06:15:46 2011 +0300
     1.2 +++ b/src/checkbox.c	Tue Apr 19 03:01:46 2011 +0300
     1.3 @@ -1,3 +1,4 @@
     1.4 +#include <string.h>
     1.5  #include <assert.h>
     1.6  #include "imtk.h"
     1.7  #include "state.h"
     1.8 @@ -38,32 +39,38 @@
     1.9  	return state;
    1.10  }
    1.11  
    1.12 +static float v[][2] = {
    1.13 +	{-0.2, 0.63},	/* 0 */
    1.14 +	{0.121, 0.325},	/* 1 */
    1.15 +	{0.15, 0.5},	/* 2 */
    1.16 +	{0.28, 0.125},	/* 3 */
    1.17 +	{0.38, 0.33},	/* 4 */
    1.18 +	{0.42, -0.122},	/* 5 */
    1.19 +	{0.58, 0.25},	/* 6 */
    1.20 +	{0.72, 0.52},	/* 7 */
    1.21 +	{0.625, 0.65},	/* 8 */
    1.22 +	{0.89, 0.78},	/* 9 */
    1.23 +	{0.875, 0.92},	/* 10 */
    1.24 +	{1.13, 1.145}	/* 11 */
    1.25 +};
    1.26 +#define TRI(a, b, c)	(glVertex2fv(v[a]), glVertex2fv(v[b]), glVertex2fv(v[c]))
    1.27 +
    1.28  static void draw_checkbox(int id, const char *label, int x, int y, int state, int over)
    1.29  {
    1.30  	static const int sz = CHECKBOX_SIZE;
    1.31 -	static float v[][2] = {
    1.32 -		{-0.2, 0.63},	/* 0 */
    1.33 -		{0.121, 0.325},	/* 1 */
    1.34 -		{0.15, 0.5},	/* 2 */
    1.35 -		{0.28, 0.125},	/* 3 */
    1.36 -		{0.38, 0.33},	/* 4 */
    1.37 -		{0.42, -0.122},	/* 5 */
    1.38 -		{0.58, 0.25},	/* 6 */
    1.39 -		{0.72, 0.52},	/* 7 */
    1.40 -		{0.625, 0.65},	/* 8 */
    1.41 -		{0.89, 0.78},	/* 9 */
    1.42 -		{0.875, 0.92},	/* 10 */
    1.43 -		{1.13, 1.145}	/* 11 */
    1.44 -	};
    1.45 -#define TRI(a, b, c)	(glVertex2fv(v[a]), glVertex2fv(v[b]), glVertex2fv(v[c]))
    1.46 +	unsigned int attr = 0;
    1.47 +	float tcol[4], bcol[4];
    1.48  
    1.49  	if(over) {
    1.50 -		glColor4fv(imtk_get_color(IMTK_FOCUS_COLOR));
    1.51 -	} else {
    1.52 -		glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
    1.53 +		attr |= IMTK_FOCUS_BIT;
    1.54  	}
    1.55 +	if(imtk_is_active(id)) {
    1.56 +		attr |= IMTK_PRESS_BIT;
    1.57 +	}
    1.58 +	memcpy(tcol, imtk_get_color(IMTK_BOTTOM_COLOR | attr), sizeof tcol);
    1.59 +	memcpy(bcol, imtk_get_color(IMTK_TOP_COLOR | attr), sizeof bcol);
    1.60  
    1.61 -	imtk_draw_rect(x, y, sz, sz, 0);
    1.62 +	imtk_draw_rect(x, y, sz, sz, tcol, bcol);
    1.63  	imtk_draw_frame(x, y, sz, sz, FRAME_INSET);
    1.64  
    1.65  	glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));