imtk

changeset 8:10604ff95527

imtk_draw_rect
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 14 Apr 2011 23:21:56 +0300
parents 6d35e6c7b2ca
children 1b27a69603ac eae09a1dca1d
files src/button.c src/checkbox.c src/draw.c src/draw.h src/progress.c src/slider.c src/textbox.c
diffstat 7 files changed, 27 insertions(+), 50 deletions(-) [+]
line diff
     1.1 --- a/src/button.c	Thu Apr 14 23:04:07 2011 +0300
     1.2 +++ b/src/button.c	Thu Apr 14 23:21:56 2011 +0300
     1.3 @@ -43,18 +43,13 @@
     1.4  
     1.5  	calc_button_size(label, &width, &height);
     1.6  
     1.7 -	glBegin(GL_QUADS);
     1.8  	if(imtk_hit_test(x, y, width, height)) {
     1.9  		glColor4fv(imtk_get_color(IMTK_FOCUS_COLOR));
    1.10  	} else {
    1.11  		glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
    1.12  	}
    1.13 -	glVertex2f(x, y);
    1.14 -	glVertex2f(x + width, y);
    1.15 -	glVertex2f(x + width, y + height);
    1.16 -	glVertex2f(x, y + height);
    1.17 -	glEnd();
    1.18  
    1.19 +	imtk_draw_rect(x, y, width, height, 0);
    1.20  	imtk_draw_frame(x, y, width, height, imtk_is_active(id) ? FRAME_INSET : FRAME_OUTSET);
    1.21  
    1.22  	glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));
     2.1 --- a/src/checkbox.c	Thu Apr 14 23:04:07 2011 +0300
     2.2 +++ b/src/checkbox.c	Thu Apr 14 23:21:56 2011 +0300
     2.3 @@ -49,13 +49,7 @@
     2.4  		glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
     2.5  	}
     2.6  
     2.7 -	glBegin(GL_QUADS);
     2.8 -	glVertex2f(x, y);
     2.9 -	glVertex2f(x + sz, y);
    2.10 -	glVertex2f(x + sz, y + sz);
    2.11 -	glVertex2f(x, y + sz);
    2.12 -	glEnd();
    2.13 -
    2.14 +	imtk_draw_rect(x, y, sz, sz, 0);
    2.15  	imtk_draw_frame(x, y, sz, sz, FRAME_INSET);
    2.16  
    2.17  	glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));
     3.1 --- a/src/draw.c	Thu Apr 14 23:04:07 2011 +0300
     3.2 +++ b/src/draw.c	Thu Apr 14 23:21:56 2011 +0300
     3.3 @@ -27,6 +27,19 @@
     3.4  	return colors[col];
     3.5  }
     3.6  
     3.7 +void imtk_draw_rect(int x, int y, int w, int h, float *color_rgba)
     3.8 +{
     3.9 +	glBegin(GL_QUADS);
    3.10 +	if(color_rgba) {
    3.11 +		glColor4fv(color_rgba);
    3.12 +	}
    3.13 +	glVertex2f(x, y);
    3.14 +	glVertex2f(x + w, y);
    3.15 +	glVertex2f(x + w, y + h);
    3.16 +	glVertex2f(x, y + h);
    3.17 +	glEnd();
    3.18 +}
    3.19 +
    3.20  void imtk_draw_frame(int x, int y, int w, int h, int style)
    3.21  {
    3.22  	float tcol[4], bcol[4];
     4.1 --- a/src/draw.h	Thu Apr 14 23:04:07 2011 +0300
     4.2 +++ b/src/draw.h	Thu Apr 14 23:21:56 2011 +0300
     4.3 @@ -23,6 +23,7 @@
     4.4  
     4.5  void imtk_set_color(int col, float r, float g, float b, float a);
     4.6  float *imtk_get_color(int col);
     4.7 +void imtk_draw_rect(int x, int y, int w, int h, float *color_rgba);
     4.8  void imtk_draw_frame(int x, int y, int w, int h, int style);
     4.9  void imtk_draw_string(int x, int y, const char *str);
    4.10  int imtk_string_size(const char *str);
     5.1 --- a/src/progress.c	Thu Apr 14 23:04:07 2011 +0300
     5.2 +++ b/src/progress.c	Thu Apr 14 23:21:56 2011 +0300
     5.3 @@ -18,24 +18,12 @@
     5.4  	if(pos > 1.0) pos = 1.0;
     5.5  
     5.6  	/* through */
     5.7 -	glBegin(GL_QUADS);
     5.8 -	glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
     5.9 -	glVertex2f(x - 1, y - 1);
    5.10 -	glVertex2f(x + SLIDER_SIZE + 1, y - 1);
    5.11 -	glVertex2f(x + SLIDER_SIZE + 1, y + 17);
    5.12 -	glVertex2f(x - 1, y + 17);
    5.13 -	glEnd();
    5.14 +	imtk_draw_rect(x - 1, y - 1, SLIDER_SIZE + 1, 18, imtk_get_color(IMTK_BASE_COLOR));
    5.15  	imtk_draw_frame(x - 1, y - 1, SLIDER_SIZE + 2, 17, FRAME_INSET);
    5.16  
    5.17  	if(pos > 0.0) {
    5.18  		/* bar */
    5.19 -		glBegin(GL_QUADS);
    5.20 -		glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
    5.21 -		glVertex2f(x, y);
    5.22 -		glVertex2f(x + bar_size, y);
    5.23 -		glVertex2f(x + bar_size, y + 15);
    5.24 -		glVertex2f(x, y + 15);
    5.25 -		glEnd();
    5.26 +		imtk_draw_rect(x, y, bar_size, 15, imtk_get_color(IMTK_BASE_COLOR));
    5.27  		imtk_draw_frame(x, y, bar_size, 15, FRAME_OUTSET);
    5.28  	}
    5.29  }
     6.1 --- a/src/slider.c	Thu Apr 14 23:04:07 2011 +0300
     6.2 +++ b/src/slider.c	Thu Apr 14 23:21:56 2011 +0300
     6.3 @@ -73,13 +73,7 @@
     6.4  	thumb_y = y - THUMB_HEIGHT / 2;
     6.5  
     6.6  	/* draw trough */
     6.7 -	glBegin(GL_QUADS);
     6.8 -	glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
     6.9 -	glVertex2f(x, y - 2);
    6.10 -	glVertex2f(x + SLIDER_SIZE, y - 2);
    6.11 -	glVertex2f(x + SLIDER_SIZE, y + 2);
    6.12 -	glVertex2f(x, y + 2);
    6.13 -	glEnd();
    6.14 +	imtk_draw_rect(x, y - 2, SLIDER_SIZE, 4, imtk_get_color(IMTK_BASE_COLOR));
    6.15  	imtk_draw_frame(x, y - 2, SLIDER_SIZE, 4, FRAME_INSET);
    6.16  
    6.17  	if(imtk_hit_test(thumb_x, thumb_y, THUMB_WIDTH, THUMB_HEIGHT)) {
    6.18 @@ -89,12 +83,7 @@
    6.19  	}
    6.20  
    6.21  	/* draw handle */
    6.22 -	glBegin(GL_QUADS);
    6.23 -	glVertex2f(thumb_x, thumb_y);
    6.24 -	glVertex2f(thumb_x + THUMB_WIDTH, thumb_y);
    6.25 -	glVertex2f(thumb_x + THUMB_WIDTH, thumb_y + THUMB_HEIGHT);
    6.26 -	glVertex2f(thumb_x, thumb_y + THUMB_HEIGHT);
    6.27 -	glEnd();
    6.28 +	imtk_draw_rect(thumb_x, thumb_y, THUMB_WIDTH, THUMB_HEIGHT, 0);
    6.29  	imtk_draw_frame(thumb_x, thumb_y, THUMB_WIDTH, THUMB_HEIGHT, FRAME_OUTSET);
    6.30  
    6.31  	/* draw display */
     7.1 --- a/src/textbox.c	Thu Apr 14 23:04:07 2011 +0300
     7.2 +++ b/src/textbox.c	Thu Apr 14 23:21:56 2011 +0300
     7.3 @@ -72,22 +72,19 @@
     7.4  		glColor4fv(imtk_get_color(IMTK_BASE_COLOR));
     7.5  	}
     7.6  
     7.7 -	glBegin(GL_QUADS);
     7.8 -	glVertex2f(x, y);
     7.9 -	glVertex2f(x + TEXTBOX_SIZE, y);
    7.10 -	glVertex2f(x + TEXTBOX_SIZE, y + 20);
    7.11 -	glVertex2f(x, y + 20);
    7.12 -	glEnd();
    7.13 -
    7.14 -	glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));
    7.15 +	imtk_draw_rect(x, y, TEXTBOX_SIZE, 20, 0);
    7.16  
    7.17  	if(imtk_has_focus(id)) {
    7.18  		glBegin(GL_LINES);
    7.19 -		glVertex2f(x + strsz + 2, y + 2);
    7.20 -		glVertex2f(x + strsz + 2, y + 18);
    7.21 +		glColor4f(0.8, 0.25, 0.18, imtk_get_color(IMTK_TEXT_COLOR)[3]);
    7.22 +		glVertex2f(x + strsz + 3, y + 2);
    7.23 +		glVertex2f(x + strsz + 3, y + 18);
    7.24 +		glVertex2f(x + strsz + 4, y + 2);
    7.25 +		glVertex2f(x + strsz + 4, y + 18);
    7.26  		glEnd();
    7.27  	}
    7.28  
    7.29 +	glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));
    7.30  	imtk_draw_string(x + 2, y + 15, text);
    7.31  
    7.32  	imtk_draw_frame(x, y, TEXTBOX_SIZE, 20, FRAME_INSET);