glamtk

changeset 8:cd00a5775373

beautified the checkbox
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 31 Mar 2011 04:38:16 +0300
parents a115dff39a54
children 4b1989ff2ef7
files src/imtk.c src/imtk.h test.c
diffstat 3 files changed, 46 insertions(+), 43 deletions(-) [+]
line diff
     1.1 --- a/src/imtk.c	Fri Mar 11 02:25:49 2011 +0200
     1.2 +++ b/src/imtk.c	Thu Mar 31 04:38:16 2011 +0300
     1.3 @@ -18,6 +18,9 @@
     1.4  #define THUMB_WIDTH		10
     1.5  #define THUMB_HEIGHT	20
     1.6  
     1.7 +#define IMTK_BEVEL_SHAD_COLOR	3
     1.8 +#define IMTK_BEVEL_LIT_COLOR	3
     1.9 +
    1.10  enum {
    1.11  	FRAME_OUTSET,
    1.12  	FRAME_INSET
    1.13 @@ -47,9 +50,8 @@
    1.14  static float colors[][4] = {
    1.15  	{0.0, 0.0, 0.0, 0.7},		/* text color */
    1.16  	{0.6, 0.6, 0.6, 0.7},		/* base color */
    1.17 -	{0.7, 0.7, 0.7, 0.7},	/* focus color */
    1.18 -	{1.0, 1.0, 1.0, 1.0},		/* lit bevel */
    1.19 -	{0.3, 0.3, 0.3, 1.0}		/* shadowed bevel */
    1.20 +	{0.7, 0.7, 0.7, 0.7},		/* focus color */
    1.21 +	{0.0, 0.0, 0.0, 0.7}		/* frame color */
    1.22  };
    1.23  
    1.24  static int scr_width = 1, scr_height = 1;
    1.25 @@ -410,28 +412,12 @@
    1.26  
    1.27  	calc_button_size(label, &width, &height);
    1.28  
    1.29 -	/*
    1.30 -	glBegin(GL_QUADS);
    1.31 -	if(hit_test(x, y, width, height)) {
    1.32 -		glColor3fv(colors[IMTK_FOCUS_COLOR]);
    1.33 -	} else {
    1.34 -		glColor3fv(colors[IMTK_BASE_COLOR]);
    1.35 -	}
    1.36 -	glVertex2f(x, y);
    1.37 -	glVertex2f(x + width, y);
    1.38 -	glVertex2f(x + width, y + height);
    1.39 -	glVertex2f(x, y + height);
    1.40 -	glEnd();
    1.41 -
    1.42 -	draw_frame(x, y, width, height, active == id ? FRAME_INSET : FRAME_OUTSET);
    1.43 -	*/
    1.44 -
    1.45  	if(hit_test(x, y, width, height)) {
    1.46  		imtk_draw_backgroundv(colors[IMTK_FOCUS_COLOR]);
    1.47  	} else {
    1.48  		imtk_draw_backgroundv(colors[IMTK_BASE_COLOR]);
    1.49  	}
    1.50 -	imtk_draw_rect(x, y, width, height, 8);
    1.51 +	imtk_draw_rect(x, y, width, height, 6);
    1.52  
    1.53  	glColor3fv(colors[IMTK_TEXT_COLOR]);
    1.54  	draw_string(x + 20, y + 15, label);
    1.55 @@ -447,37 +433,55 @@
    1.56  static void draw_checkbox(int id, const char *label, int x, int y, int state)
    1.57  {
    1.58  	static const int sz = CHECKBOX_SIZE;
    1.59 +	static float v[][2] = {
    1.60 +		{-0.2, 0.63},	/* 0 */
    1.61 +		{0.121, 0.325},	/* 1 */
    1.62 +		{0.15, 0.5},	/* 2 */
    1.63 +		{0.28, 0.125},	/* 3 */
    1.64 +		{0.38, 0.33},	/* 4 */
    1.65 +		{0.42, -0.122},	/* 5 */
    1.66 +		{0.58, 0.25},	/* 6 */
    1.67 +		{0.72, 0.52},	/* 7 */
    1.68 +		{0.625, 0.65},	/* 8 */
    1.69 +		{0.89, 0.78},	/* 9 */
    1.70 +		{0.875, 0.92},	/* 10 */
    1.71 +		{1.13, 1.145}	/* 11 */
    1.72 +	};
    1.73 +#define TRI(a, b, c)	(glVertex2fv(v[a]), glVertex2fv(v[b]), glVertex2fv(v[c]))
    1.74 +
    1.75  
    1.76  	if(hit_test(x, y, sz, sz)) {
    1.77 -		glColor3fv(colors[IMTK_FOCUS_COLOR]);
    1.78 +		imtk_draw_backgroundv(colors[IMTK_FOCUS_COLOR]);
    1.79  	} else {
    1.80 -		glColor3fv(colors[IMTK_BASE_COLOR]);
    1.81 +		imtk_draw_backgroundv(colors[IMTK_BASE_COLOR]);
    1.82  	}
    1.83  
    1.84 -	glBegin(GL_QUADS);
    1.85 -	glVertex2f(x, y);
    1.86 -	glVertex2f(x + sz, y);
    1.87 -	glVertex2f(x + sz, y + sz);
    1.88 -	glVertex2f(x, y + sz);
    1.89 -	glEnd();
    1.90 +	imtk_draw_rect(x, y, sz, sz, 3);
    1.91  
    1.92 -	draw_frame(x, y, sz, sz, FRAME_INSET);
    1.93 +	if(state) {
    1.94 +		glMatrixMode(GL_MODELVIEW);
    1.95 +		glPushMatrix();
    1.96 +		glTranslatef(x, y + sz, 0);
    1.97 +		glScalef(sz * 1.2, -sz * 1.3, 1);
    1.98  
    1.99 -	glColor3fv(colors[IMTK_TEXT_COLOR]);
   1.100 -	if(state) {
   1.101 -		glPushAttrib(GL_LINE_BIT);
   1.102 -		glLineWidth(2);
   1.103 -
   1.104 -		glBegin(GL_LINES);
   1.105 -		glVertex2f(x + 2, y + 2);
   1.106 -		glVertex2f(x + sz - 2, y + sz - 2);
   1.107 -		glVertex2f(x + sz - 2, y + 2);
   1.108 -		glVertex2f(x + 2, y + sz - 2);
   1.109 +		glBegin(GL_TRIANGLES);
   1.110 +		glColor4f(0.63, 0.078, 0.078, colors[IMTK_TEXT_COLOR][3]);
   1.111 +		TRI(0, 1, 2);
   1.112 +		TRI(1, 3, 2);
   1.113 +		TRI(3, 4, 2);
   1.114 +		TRI(3, 5, 4);
   1.115 +		TRI(4, 5, 6);
   1.116 +		TRI(4, 6, 7);
   1.117 +		TRI(4, 7, 8);
   1.118 +		TRI(8, 7, 9);
   1.119 +		TRI(8, 9, 10);
   1.120 +		TRI(10, 9, 11);
   1.121  		glEnd();
   1.122  
   1.123 -		glPopAttrib();
   1.124 +		glPopMatrix();
   1.125  	}
   1.126  
   1.127 +	glColor4fv(colors[IMTK_TEXT_COLOR]);
   1.128  	draw_string(x + sz + 5, y + sz - 2, label);
   1.129  }
   1.130  
     2.1 --- a/src/imtk.h	Fri Mar 11 02:25:49 2011 +0200
     2.2 +++ b/src/imtk.h	Thu Mar 31 04:38:16 2011 +0300
     2.3 @@ -8,8 +8,7 @@
     2.4  	IMTK_TEXT_COLOR,
     2.5  	IMTK_BASE_COLOR,
     2.6  	IMTK_FOCUS_COLOR,
     2.7 -	IMTK_BEVEL_LIT_COLOR,
     2.8 -	IMTK_BEVEL_SHAD_COLOR
     2.9 +	IMTK_FRAME_COLOR
    2.10  };
    2.11  
    2.12  /* key/button state enum */
     3.1 --- a/test.c	Fri Mar 11 02:25:49 2011 +0200
     3.2 +++ b/test.c	Thu Mar 31 04:38:16 2011 +0300
     3.3 @@ -118,7 +118,7 @@
     3.4  
     3.5  void gui(void)
     3.6  {
     3.7 -	static int bnshow;
     3.8 +	static int bnshow = 1;
     3.9  	static char textbuf[256];
    3.10  	static char textbuf2[256];
    3.11  	static float val;