imtk

changeset 14:df2bc9406561

added gradients
author John Tsiombikas <nuclear@siggraph.org>
date Tue, 19 Apr 2011 03:01:46 +0300
parents 9c7987064bb0
children 6893b4dca5a3
files Makefile src/button.c src/checkbox.c src/draw.c src/draw.h src/imtk.h src/progress.c src/slider.c src/textbox.c test.c
diffstat 10 files changed, 171 insertions(+), 88 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Mon Apr 18 06:15:46 2011 +0300
     1.2 +++ b/Makefile	Tue Apr 19 03:01:46 2011 +0300
     1.3 @@ -1,5 +1,6 @@
     1.4  src = $(wildcard *.c src/*.c)
     1.5  obj = $(src:.c=.o)
     1.6 +depfiles = $(obj:.o=.d)
     1.7  bin = test
     1.8  
     1.9  CC = gcc
    1.10 @@ -15,6 +16,15 @@
    1.11  $(bin): $(obj)
    1.12  	$(CC) -o $@ $(obj) $(LDFLAGS)
    1.13  
    1.14 +-include $(depfiles)
    1.15 +
    1.16 +%.d: %.c
    1.17 +	@$(CPP) $(CFLAGS) -MM -MT $(@:.d=.o) $< >$@
    1.18 +
    1.19  .PHONY: clean
    1.20  clean:
    1.21  	rm -f $(obj) $(bin)
    1.22 +
    1.23 +.PHONY: cleandep
    1.24 +cleandep:
    1.25 +	rm -f $(depfiles)
     2.1 --- a/src/button.c	Mon Apr 18 06:15:46 2011 +0300
     2.2 +++ b/src/button.c	Tue Apr 19 03:01:46 2011 +0300
     2.3 @@ -1,10 +1,11 @@
     2.4 +#include <string.h>
     2.5  #include <assert.h>
     2.6  #include "imtk.h"
     2.7  #include "state.h"
     2.8  #include "draw.h"
     2.9  
    2.10  static void calc_button_size(const char *label, int *wret, int *hret);
    2.11 -static void draw_button(int id, const char *label, int x, int y);
    2.12 +static void draw_button(int id, const char *label, int x, int y, int over);
    2.13  
    2.14  int imtk_button(int id, const char *label, int x, int y)
    2.15  {
    2.16 @@ -33,24 +34,26 @@
    2.17  		}
    2.18  	}
    2.19  
    2.20 -	draw_button(id, label, x, y);
    2.21 +	draw_button(id, label, x, y, over);
    2.22  	return res;
    2.23  }
    2.24  
    2.25 -static void draw_button(int id, const char *label, int x, int y)
    2.26 +static void draw_button(int id, const char *label, int x, int y, int over)
    2.27  {
    2.28 -	int width, height;
    2.29 +	float tcol[4], bcol[4];
    2.30 +	int width, height, active = imtk_is_active(id);
    2.31 +	unsigned int attr = 0;
    2.32 +
    2.33 +	if(over) attr |= IMTK_FOCUS_BIT;
    2.34 +	if(active) attr |= IMTK_PRESS_BIT;
    2.35  
    2.36  	calc_button_size(label, &width, &height);
    2.37  
    2.38 -	if(imtk_hit_test(x, y, width, height)) {
    2.39 -		glColor4fv(imtk_get_color(IMTK_FOCUS_COLOR));
    2.40 -	} else {
    2.41 -		glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
    2.42 -	}
    2.43 +	memcpy(tcol, imtk_get_color(IMTK_TOP_COLOR | attr), sizeof tcol);
    2.44 +	memcpy(bcol, imtk_get_color(IMTK_BOTTOM_COLOR | attr), sizeof bcol);
    2.45  
    2.46 -	imtk_draw_rect(x, y, width, height, 0);
    2.47 -	imtk_draw_frame(x, y, width, height, imtk_is_active(id) ? FRAME_INSET : FRAME_OUTSET);
    2.48 +	imtk_draw_rect(x, y, width, height, tcol, bcol);
    2.49 +	imtk_draw_frame(x, y, width, height, active ? FRAME_INSET : FRAME_OUTSET);
    2.50  
    2.51  	glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));
    2.52  	imtk_draw_string(x + 20, y + 15, label);
     3.1 --- a/src/checkbox.c	Mon Apr 18 06:15:46 2011 +0300
     3.2 +++ b/src/checkbox.c	Tue Apr 19 03:01:46 2011 +0300
     3.3 @@ -1,3 +1,4 @@
     3.4 +#include <string.h>
     3.5  #include <assert.h>
     3.6  #include "imtk.h"
     3.7  #include "state.h"
     3.8 @@ -38,32 +39,38 @@
     3.9  	return state;
    3.10  }
    3.11  
    3.12 +static float v[][2] = {
    3.13 +	{-0.2, 0.63},	/* 0 */
    3.14 +	{0.121, 0.325},	/* 1 */
    3.15 +	{0.15, 0.5},	/* 2 */
    3.16 +	{0.28, 0.125},	/* 3 */
    3.17 +	{0.38, 0.33},	/* 4 */
    3.18 +	{0.42, -0.122},	/* 5 */
    3.19 +	{0.58, 0.25},	/* 6 */
    3.20 +	{0.72, 0.52},	/* 7 */
    3.21 +	{0.625, 0.65},	/* 8 */
    3.22 +	{0.89, 0.78},	/* 9 */
    3.23 +	{0.875, 0.92},	/* 10 */
    3.24 +	{1.13, 1.145}	/* 11 */
    3.25 +};
    3.26 +#define TRI(a, b, c)	(glVertex2fv(v[a]), glVertex2fv(v[b]), glVertex2fv(v[c]))
    3.27 +
    3.28  static void draw_checkbox(int id, const char *label, int x, int y, int state, int over)
    3.29  {
    3.30  	static const int sz = CHECKBOX_SIZE;
    3.31 -	static float v[][2] = {
    3.32 -		{-0.2, 0.63},	/* 0 */
    3.33 -		{0.121, 0.325},	/* 1 */
    3.34 -		{0.15, 0.5},	/* 2 */
    3.35 -		{0.28, 0.125},	/* 3 */
    3.36 -		{0.38, 0.33},	/* 4 */
    3.37 -		{0.42, -0.122},	/* 5 */
    3.38 -		{0.58, 0.25},	/* 6 */
    3.39 -		{0.72, 0.52},	/* 7 */
    3.40 -		{0.625, 0.65},	/* 8 */
    3.41 -		{0.89, 0.78},	/* 9 */
    3.42 -		{0.875, 0.92},	/* 10 */
    3.43 -		{1.13, 1.145}	/* 11 */
    3.44 -	};
    3.45 -#define TRI(a, b, c)	(glVertex2fv(v[a]), glVertex2fv(v[b]), glVertex2fv(v[c]))
    3.46 +	unsigned int attr = 0;
    3.47 +	float tcol[4], bcol[4];
    3.48  
    3.49  	if(over) {
    3.50 -		glColor4fv(imtk_get_color(IMTK_FOCUS_COLOR));
    3.51 -	} else {
    3.52 -		glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
    3.53 +		attr |= IMTK_FOCUS_BIT;
    3.54  	}
    3.55 +	if(imtk_is_active(id)) {
    3.56 +		attr |= IMTK_PRESS_BIT;
    3.57 +	}
    3.58 +	memcpy(tcol, imtk_get_color(IMTK_BOTTOM_COLOR | attr), sizeof tcol);
    3.59 +	memcpy(bcol, imtk_get_color(IMTK_TOP_COLOR | attr), sizeof bcol);
    3.60  
    3.61 -	imtk_draw_rect(x, y, sz, sz, 0);
    3.62 +	imtk_draw_rect(x, y, sz, sz, tcol, bcol);
    3.63  	imtk_draw_frame(x, y, sz, sz, FRAME_INSET);
    3.64  
    3.65  	glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));
     4.1 --- a/src/draw.c	Mon Apr 18 06:15:46 2011 +0300
     4.2 +++ b/src/draw.c	Tue Apr 19 03:01:46 2011 +0300
     4.3 @@ -3,35 +3,52 @@
     4.4  #include "draw.h"
     4.5  #include "imtk.h"
     4.6  
     4.7 +#define COLOR_MASK	0xff
     4.8 +
     4.9  /* default colors, can be changed with imtk_set_color */
    4.10  static float colors[][4] = {
    4.11  	{0.0, 0.0, 0.0, 1.0},		/* text color */
    4.12 -	{0.7, 0.7, 0.7, 1.0},		/* base color */
    4.13 -	{0.85, 0.85, 0.85, 1.0},	/* focus color */
    4.14 -	{1.0, 1.0, 1.0, 1.0},		/* lit bevel */
    4.15 +	{0.75, 0.75, 0.75, 1.0},	/* top color */
    4.16 +	{0.56, 0.56, 0.56, 1.0},	/* bot color */
    4.17 +	{0.9, 0.9, 0.9, 1.0},		/* lit bevel */
    4.18  	{0.3, 0.3, 0.3, 1.0},		/* shadowed bevel */
    4.19  	{0.8, 0.25, 0.18, 1.0},		/* cursor color */
    4.20  	{0.4, 0.5, 0.9, 1.0},		/* selection color */
    4.21 -	{0.63, 0.078, 0.078, 1.0}	/* check color */
    4.22 +	{0.75, 0.1, 0.095, 1.0}		/* check color */
    4.23  };
    4.24  
    4.25 +static float focus_factor = 1.1;
    4.26 +static float press_factor = 0.8;
    4.27  static float alpha = 1.0;
    4.28  static float bevel = 1.0;
    4.29  
    4.30 -void imtk_set_color(int col, float r, float g, float b, float a)
    4.31 +void imtk_set_color(unsigned int col, float r, float g, float b, float a)
    4.32  {
    4.33 -	assert(col >= 0 && col < sizeof colors / sizeof *colors);
    4.34 +	int idx = col & COLOR_MASK;
    4.35 +	assert(idx >= 0 && idx < sizeof colors / sizeof *colors);
    4.36  
    4.37 -	colors[col][0] = r;
    4.38 -	colors[col][1] = g;
    4.39 -	colors[col][2] = b;
    4.40 -	colors[col][3] = a;
    4.41 +	colors[idx][0] = r;
    4.42 +	colors[idx][1] = g;
    4.43 +	colors[idx][2] = b;
    4.44 +	colors[idx][3] = a;
    4.45  }
    4.46  
    4.47 -float *imtk_get_color(int col)
    4.48 +float *imtk_get_color(unsigned int col)
    4.49  {
    4.50  	static float ret[4];
    4.51 -	memcpy(ret, colors + col, sizeof ret);
    4.52 +	int idx = col & COLOR_MASK;
    4.53 +
    4.54 +	memcpy(ret, colors + idx, sizeof ret);
    4.55 +	if(col & IMTK_FOCUS_BIT) {
    4.56 +		ret[0] *= focus_factor;
    4.57 +		ret[1] *= focus_factor;
    4.58 +		ret[2] *= focus_factor;
    4.59 +	}
    4.60 +	if(col & IMTK_PRESS_BIT) {
    4.61 +		ret[0] *= press_factor;
    4.62 +		ret[1] *= press_factor;
    4.63 +		ret[2] *= press_factor;
    4.64 +	}
    4.65  	ret[3] *= alpha;
    4.66  	return ret;
    4.67  }
    4.68 @@ -56,14 +73,38 @@
    4.69  	return bevel;
    4.70  }
    4.71  
    4.72 -void imtk_draw_rect(int x, int y, int w, int h, float *color_rgba)
    4.73 +void imtk_set_focus_factor(float fact)
    4.74 +{
    4.75 +	focus_factor = fact;
    4.76 +}
    4.77 +
    4.78 +float imtk_get_focus_factor(void)
    4.79 +{
    4.80 +	return focus_factor;
    4.81 +}
    4.82 +
    4.83 +void imtk_set_press_factor(float fact)
    4.84 +{
    4.85 +	press_factor = fact;
    4.86 +}
    4.87 +
    4.88 +float imtk_get_press_factor(void)
    4.89 +{
    4.90 +	return press_factor;
    4.91 +}
    4.92 +
    4.93 +void imtk_draw_rect(int x, int y, int w, int h, float *ctop, float *cbot)
    4.94  {
    4.95  	glBegin(GL_QUADS);
    4.96 -	if(color_rgba) {
    4.97 -		glColor4fv(color_rgba);
    4.98 +	if(ctop) {
    4.99 +		glColor4fv(ctop);
   4.100  	}
   4.101  	glVertex2f(x, y);
   4.102  	glVertex2f(x + w, y);
   4.103 +
   4.104 +	if(cbot) {
   4.105 +		glColor4fv(cbot);
   4.106 +	}
   4.107  	glVertex2f(x + w, y + h);
   4.108  	glVertex2f(x, y + h);
   4.109  	glEnd();
   4.110 @@ -74,6 +115,15 @@
   4.111  	float tcol[4], bcol[4];
   4.112  	float b = imtk_get_bevel_width();
   4.113  
   4.114 +	if(!b) {
   4.115 +		return;
   4.116 +	}
   4.117 +
   4.118 +	x -= b;
   4.119 +	y -= b;
   4.120 +	w += b * 2;
   4.121 +	h += b * 2;
   4.122 +
   4.123  	switch(style) {
   4.124  	case FRAME_INSET:
   4.125  		memcpy(tcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof tcol);
   4.126 @@ -109,20 +159,6 @@
   4.127  	glVertex2f(x + w, y + h);
   4.128  	glVertex2f(x + w - b, y + h - b);
   4.129  	glEnd();
   4.130 -
   4.131 -	/*glBegin(GL_LINES);
   4.132 -	glColor4fv(tcol);
   4.133 -	glVertex2f(x, y + h);
   4.134 -	glVertex2f(x, y);
   4.135 -	glVertex2f(x, y);
   4.136 -	glVertex2f(x + w, y);
   4.137 -	glColor4fv(bcol);
   4.138 -	glVertex2f(x + w, y);
   4.139 -	glVertex2f(x + w, y + h);
   4.140 -	glVertex2f(x + w, y + h);
   4.141 -	glVertex2f(x, y + h);
   4.142 -	glEnd();*/
   4.143 -
   4.144  }
   4.145  
   4.146  void imtk_draw_string(int x, int y, const char *str)
     5.1 --- a/src/draw.h	Mon Apr 18 06:15:46 2011 +0300
     5.2 +++ b/src/draw.h	Tue Apr 19 03:01:46 2011 +0300
     5.3 @@ -13,9 +13,7 @@
     5.4  	FRAME_INSET
     5.5  };
     5.6  
     5.7 -/*void imtk_set_color(int col, float r, float g, float b, float a); in imtk.h */
     5.8 -float *imtk_get_color(int col);
     5.9 -void imtk_draw_rect(int x, int y, int w, int h, float *color_rgba);
    5.10 +void imtk_draw_rect(int x, int y, int w, int h, float *ctop, float *cbot);
    5.11  void imtk_draw_frame(int x, int y, int w, int h, int style);
    5.12  void imtk_draw_string(int x, int y, const char *str);
    5.13  int imtk_string_size(const char *str);
     6.1 --- a/src/imtk.h	Mon Apr 18 06:15:46 2011 +0300
     6.2 +++ b/src/imtk.h	Tue Apr 19 03:01:46 2011 +0300
     6.3 @@ -22,8 +22,8 @@
     6.4  
     6.5  enum {
     6.6  	IMTK_TEXT_COLOR,
     6.7 -	IMTK_BASE_COLOR,
     6.8 -	IMTK_FOCUS_COLOR,
     6.9 +	IMTK_TOP_COLOR,
    6.10 +	IMTK_BOTTOM_COLOR,
    6.11  	IMTK_BEVEL_LIT_COLOR,
    6.12  	IMTK_BEVEL_SHAD_COLOR,
    6.13  	IMTK_CURSOR_COLOR,
    6.14 @@ -31,6 +31,12 @@
    6.15  	IMTK_CHECK_COLOR
    6.16  };
    6.17  
    6.18 +#define IMTK_FOCUS_BIT		0x100
    6.19 +#define IMTK_PRESS_BIT		0x200
    6.20 +
    6.21 +#define IMTK_BASE_COLOR		IMTK_BOTTOM_COLOR
    6.22 +#define IMTK_FOCUS_COLOR	(IMTK_TOP_COLOR | IMTK_FOCUS_BIT)
    6.23 +
    6.24  
    6.25  #ifdef __cplusplus
    6.26  extern "C" {
    6.27 @@ -65,11 +71,16 @@
    6.28  void imtk_free_list(char *list);
    6.29  
    6.30  /* defined in draw.c */
    6.31 -void imtk_set_color(int col, float r, float g, float b, float a);
    6.32 +void imtk_set_color(unsigned int col, float r, float g, float b, float a);
    6.33 +float *imtk_get_color(unsigned int col);
    6.34  void imtk_set_alpha(float a);
    6.35  float imtk_get_alpha(void);
    6.36  void imtk_set_bevel_width(float b);
    6.37  float imtk_get_bevel_width(void);
    6.38 +void imtk_set_focus_factor(float fact);
    6.39 +float imtk_get_focus_factor(void);
    6.40 +void imtk_set_press_factor(float fact);
    6.41 +float imtk_get_press_factor(void);
    6.42  
    6.43  #ifdef __cplusplus
    6.44  }
     7.1 --- a/src/progress.c	Mon Apr 18 06:15:46 2011 +0300
     7.2 +++ b/src/progress.c	Tue Apr 19 03:01:46 2011 +0300
     7.3 @@ -1,3 +1,4 @@
     7.4 +#include <string.h>
     7.5  #include "imtk.h"
     7.6  #include "draw.h"
     7.7  
     7.8 @@ -15,17 +16,24 @@
     7.9  {
    7.10  	int bar_size = PROGR_SIZE * pos;
    7.11  	float b = imtk_get_bevel_width();
    7.12 +	float tcol[4], bcol[4];
    7.13  
    7.14  	if(pos < 0.0) pos = 0.0;
    7.15  	if(pos > 1.0) pos = 1.0;
    7.16  
    7.17 +	memcpy(tcol, imtk_get_color(IMTK_BOTTOM_COLOR), sizeof tcol);
    7.18 +	memcpy(bcol, imtk_get_color(IMTK_TOP_COLOR), sizeof bcol);
    7.19 +
    7.20  	/* through */
    7.21 -	imtk_draw_rect(x - b, y - b, PROGR_SIZE + b * 2, PROGR_HEIGHT + b * 2, imtk_get_color(IMTK_BASE_COLOR));
    7.22 +	imtk_draw_rect(x - b, y - b, PROGR_SIZE + b * 2, PROGR_HEIGHT + b * 2, tcol, bcol);
    7.23  	imtk_draw_frame(x - b, y - b, PROGR_SIZE + b * 2, PROGR_HEIGHT + b * 2, FRAME_INSET);
    7.24  
    7.25 +	/* bar */
    7.26  	if(pos > 0.0) {
    7.27 -		/* bar */
    7.28 -		imtk_draw_rect(x, y, bar_size, PROGR_HEIGHT, imtk_get_color(IMTK_BASE_COLOR));
    7.29 +		memcpy(tcol, imtk_get_color(IMTK_TOP_COLOR), sizeof tcol);
    7.30 +		memcpy(bcol, imtk_get_color(IMTK_BOTTOM_COLOR), sizeof bcol);
    7.31 +
    7.32 +		imtk_draw_rect(x, y, bar_size, PROGR_HEIGHT, tcol, bcol);
    7.33  		imtk_draw_frame(x, y, bar_size, PROGR_HEIGHT, FRAME_OUTSET);
    7.34  	}
    7.35  }
     8.1 --- a/src/slider.c	Mon Apr 18 06:15:46 2011 +0300
     8.2 +++ b/src/slider.c	Tue Apr 19 03:01:46 2011 +0300
     8.3 @@ -1,4 +1,5 @@
     8.4  #include <stdio.h>
     8.5 +#include <string.h>
     8.6  #include <assert.h>
     8.7  #include "imtk.h"
     8.8  #include "state.h"
     8.9 @@ -8,7 +9,7 @@
    8.10  #define THUMB_WIDTH		10
    8.11  #define THUMB_HEIGHT	20
    8.12  
    8.13 -static void draw_slider(int id, float pos, float min, float max, int x, int y);
    8.14 +static void draw_slider(int id, float pos, float min, float max, int x, int y, int over);
    8.15  
    8.16  float imtk_slider(int id, float pos, float min, float max, int x, int y)
    8.17  {
    8.18 @@ -58,32 +59,40 @@
    8.19  		if(pos > 1.0) pos = 1.0;
    8.20  	}
    8.21  
    8.22 -	draw_slider(id, pos, min, max, x, y);
    8.23 +	draw_slider(id, pos, min, max, x, y, over);
    8.24  	return pos * range + min;
    8.25  }
    8.26  
    8.27  
    8.28 -static void draw_slider(int id, float pos, float min, float max, int x, int y)
    8.29 +static void draw_slider(int id, float pos, float min, float max, int x, int y, int over)
    8.30  {
    8.31  	float range = max - min;
    8.32  	int thumb_x, thumb_y;
    8.33  	char buf[32];
    8.34 +	float tcol[4], bcol[4];
    8.35 +	unsigned int attr = 0;
    8.36  
    8.37  	thumb_x = x + SLIDER_SIZE * pos - THUMB_WIDTH / 2;
    8.38  	thumb_y = y - THUMB_HEIGHT / 2;
    8.39  
    8.40 +	memcpy(tcol, imtk_get_color(IMTK_BOTTOM_COLOR), sizeof tcol);
    8.41 +	memcpy(bcol, imtk_get_color(IMTK_TOP_COLOR), sizeof bcol);
    8.42 +
    8.43  	/* draw trough */
    8.44 -	imtk_draw_rect(x, y - 2, SLIDER_SIZE, 4, imtk_get_color(IMTK_BASE_COLOR));
    8.45 -	imtk_draw_frame(x, y - 2, SLIDER_SIZE, 4, FRAME_INSET);
    8.46 +	imtk_draw_rect(x, y - 2, SLIDER_SIZE, 5, tcol, bcol);
    8.47 +	imtk_draw_frame(x, y - 2, SLIDER_SIZE, 5, FRAME_INSET);
    8.48  
    8.49 -	if(imtk_hit_test(thumb_x, thumb_y, THUMB_WIDTH, THUMB_HEIGHT)) {
    8.50 -		glColor4fv(imtk_get_color(IMTK_FOCUS_COLOR));
    8.51 -	} else {
    8.52 -		glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
    8.53 +	if(over) {
    8.54 +		attr |= IMTK_FOCUS_BIT;
    8.55  	}
    8.56 +	if(imtk_is_active(id)) {
    8.57 +		attr |= IMTK_PRESS_BIT;
    8.58 +	}
    8.59 +	memcpy(tcol, imtk_get_color(IMTK_TOP_COLOR | attr), sizeof tcol);
    8.60 +	memcpy(bcol, imtk_get_color(IMTK_BOTTOM_COLOR | attr), sizeof bcol);
    8.61  
    8.62  	/* draw handle */
    8.63 -	imtk_draw_rect(thumb_x, thumb_y, THUMB_WIDTH, THUMB_HEIGHT, 0);
    8.64 +	imtk_draw_rect(thumb_x, thumb_y, THUMB_WIDTH, THUMB_HEIGHT, tcol, bcol);
    8.65  	imtk_draw_frame(thumb_x, thumb_y, THUMB_WIDTH, THUMB_HEIGHT, FRAME_OUTSET);
    8.66  
    8.67  	/* draw display */
     9.1 --- a/src/textbox.c	Mon Apr 18 06:15:46 2011 +0300
     9.2 +++ b/src/textbox.c	Tue Apr 19 03:01:46 2011 +0300
     9.3 @@ -7,7 +7,7 @@
     9.4  
     9.5  #define TEXTBOX_SIZE	100
     9.6  
     9.7 -static void draw_textbox(int id, const char *text, int x, int y);
     9.8 +static void draw_textbox(int id, const char *text, int x, int y, int over);
     9.9  
    9.10  
    9.11  void imtk_textbox(int id, char *textbuf, size_t buf_sz, int x, int y)
    9.12 @@ -58,21 +58,23 @@
    9.13  		}
    9.14  	}
    9.15  
    9.16 -	draw_textbox(id, textbuf, x, y);
    9.17 +	draw_textbox(id, textbuf, x, y, over);
    9.18  }
    9.19  
    9.20  
    9.21 -static void draw_textbox(int id, const char *text, int x, int y)
    9.22 +static void draw_textbox(int id, const char *text, int x, int y, int over)
    9.23  {
    9.24  	int strsz = imtk_string_size(text);
    9.25 +	float tcol[4], bcol[4];
    9.26 +	unsigned int attr = 0;
    9.27  
    9.28 -	if(imtk_hit_test(x, y, TEXTBOX_SIZE, 20)) {
    9.29 -		glColor4fv(imtk_get_color(IMTK_FOCUS_COLOR));
    9.30 -	} else {
    9.31 -		glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
    9.32 +	if(over) {
    9.33 +		attr |= IMTK_FOCUS_BIT;
    9.34  	}
    9.35 +	memcpy(tcol, imtk_get_color(IMTK_BOTTOM_COLOR | attr), sizeof tcol);
    9.36 +	memcpy(bcol, imtk_get_color(IMTK_TOP_COLOR | attr), sizeof bcol);
    9.37  
    9.38 -	imtk_draw_rect(x, y, TEXTBOX_SIZE, 20, 0);
    9.39 +	imtk_draw_rect(x, y, TEXTBOX_SIZE, 20, tcol, bcol);
    9.40  
    9.41  	if(imtk_has_focus(id)) {
    9.42  		glBegin(GL_LINES);
    10.1 --- a/test.c	Mon Apr 18 06:15:46 2011 +0300
    10.2 +++ b/test.c	Tue Apr 19 03:01:46 2011 +0300
    10.3 @@ -53,8 +53,7 @@
    10.4  	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
    10.5  	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 60.0);
    10.6  
    10.7 -	/*imtk_set_color(IMTK_BEVEL_LIT_COLOR, 0.3, 0.3, 0.3, 0.5);
    10.8 -	imtk_set_color(IMTK_BEVEL_SHAD_COLOR, 0.3, 0.3, 0.3, 0.5);*/
    10.9 +	imtk_set_bevel_width(1);
   10.10  
   10.11  	glutMainLoop();
   10.12  	return 0;