# HG changeset patch # User John Tsiombikas # Date 1302812516 -10800 # Node ID 10604ff9552782477fbc16a7c3470011e8dddd26 # Parent 6d35e6c7b2ca1cedc49f1b2cf492c641e849de0f imtk_draw_rect diff -r 6d35e6c7b2ca -r 10604ff95527 src/button.c --- a/src/button.c Thu Apr 14 23:04:07 2011 +0300 +++ b/src/button.c Thu Apr 14 23:21:56 2011 +0300 @@ -43,18 +43,13 @@ calc_button_size(label, &width, &height); - glBegin(GL_QUADS); if(imtk_hit_test(x, y, width, height)) { glColor4fv(imtk_get_color(IMTK_FOCUS_COLOR)); } else { glColor4fv(imtk_get_color(IMTK_BASE_COLOR)); } - glVertex2f(x, y); - glVertex2f(x + width, y); - glVertex2f(x + width, y + height); - glVertex2f(x, y + height); - glEnd(); + imtk_draw_rect(x, y, width, height, 0); imtk_draw_frame(x, y, width, height, imtk_is_active(id) ? FRAME_INSET : FRAME_OUTSET); glColor4fv(imtk_get_color(IMTK_TEXT_COLOR)); diff -r 6d35e6c7b2ca -r 10604ff95527 src/checkbox.c --- a/src/checkbox.c Thu Apr 14 23:04:07 2011 +0300 +++ b/src/checkbox.c Thu Apr 14 23:21:56 2011 +0300 @@ -49,13 +49,7 @@ glColor4fv(imtk_get_color(IMTK_BASE_COLOR)); } - glBegin(GL_QUADS); - glVertex2f(x, y); - glVertex2f(x + sz, y); - glVertex2f(x + sz, y + sz); - glVertex2f(x, y + sz); - glEnd(); - + imtk_draw_rect(x, y, sz, sz, 0); imtk_draw_frame(x, y, sz, sz, FRAME_INSET); glColor4fv(imtk_get_color(IMTK_TEXT_COLOR)); diff -r 6d35e6c7b2ca -r 10604ff95527 src/draw.c --- a/src/draw.c Thu Apr 14 23:04:07 2011 +0300 +++ b/src/draw.c Thu Apr 14 23:21:56 2011 +0300 @@ -27,6 +27,19 @@ return colors[col]; } +void imtk_draw_rect(int x, int y, int w, int h, float *color_rgba) +{ + glBegin(GL_QUADS); + if(color_rgba) { + glColor4fv(color_rgba); + } + glVertex2f(x, y); + glVertex2f(x + w, y); + glVertex2f(x + w, y + h); + glVertex2f(x, y + h); + glEnd(); +} + void imtk_draw_frame(int x, int y, int w, int h, int style) { float tcol[4], bcol[4]; diff -r 6d35e6c7b2ca -r 10604ff95527 src/draw.h --- a/src/draw.h Thu Apr 14 23:04:07 2011 +0300 +++ b/src/draw.h Thu Apr 14 23:21:56 2011 +0300 @@ -23,6 +23,7 @@ void imtk_set_color(int col, float r, float g, float b, float a); float *imtk_get_color(int col); +void imtk_draw_rect(int x, int y, int w, int h, float *color_rgba); void imtk_draw_frame(int x, int y, int w, int h, int style); void imtk_draw_string(int x, int y, const char *str); int imtk_string_size(const char *str); diff -r 6d35e6c7b2ca -r 10604ff95527 src/progress.c --- a/src/progress.c Thu Apr 14 23:04:07 2011 +0300 +++ b/src/progress.c Thu Apr 14 23:21:56 2011 +0300 @@ -18,24 +18,12 @@ if(pos > 1.0) pos = 1.0; /* through */ - glBegin(GL_QUADS); - glColor4fv(imtk_get_color(IMTK_BASE_COLOR)); - glVertex2f(x - 1, y - 1); - glVertex2f(x + SLIDER_SIZE + 1, y - 1); - glVertex2f(x + SLIDER_SIZE + 1, y + 17); - glVertex2f(x - 1, y + 17); - glEnd(); + imtk_draw_rect(x - 1, y - 1, SLIDER_SIZE + 1, 18, imtk_get_color(IMTK_BASE_COLOR)); imtk_draw_frame(x - 1, y - 1, SLIDER_SIZE + 2, 17, FRAME_INSET); if(pos > 0.0) { /* bar */ - glBegin(GL_QUADS); - glColor4fv(imtk_get_color(IMTK_BASE_COLOR)); - glVertex2f(x, y); - glVertex2f(x + bar_size, y); - glVertex2f(x + bar_size, y + 15); - glVertex2f(x, y + 15); - glEnd(); + imtk_draw_rect(x, y, bar_size, 15, imtk_get_color(IMTK_BASE_COLOR)); imtk_draw_frame(x, y, bar_size, 15, FRAME_OUTSET); } } diff -r 6d35e6c7b2ca -r 10604ff95527 src/slider.c --- a/src/slider.c Thu Apr 14 23:04:07 2011 +0300 +++ b/src/slider.c Thu Apr 14 23:21:56 2011 +0300 @@ -73,13 +73,7 @@ thumb_y = y - THUMB_HEIGHT / 2; /* draw trough */ - glBegin(GL_QUADS); - glColor4fv(imtk_get_color(IMTK_BASE_COLOR)); - glVertex2f(x, y - 2); - glVertex2f(x + SLIDER_SIZE, y - 2); - glVertex2f(x + SLIDER_SIZE, y + 2); - glVertex2f(x, y + 2); - glEnd(); + imtk_draw_rect(x, y - 2, SLIDER_SIZE, 4, imtk_get_color(IMTK_BASE_COLOR)); imtk_draw_frame(x, y - 2, SLIDER_SIZE, 4, FRAME_INSET); if(imtk_hit_test(thumb_x, thumb_y, THUMB_WIDTH, THUMB_HEIGHT)) { @@ -89,12 +83,7 @@ } /* draw handle */ - glBegin(GL_QUADS); - glVertex2f(thumb_x, thumb_y); - glVertex2f(thumb_x + THUMB_WIDTH, thumb_y); - glVertex2f(thumb_x + THUMB_WIDTH, thumb_y + THUMB_HEIGHT); - glVertex2f(thumb_x, thumb_y + THUMB_HEIGHT); - glEnd(); + imtk_draw_rect(thumb_x, thumb_y, THUMB_WIDTH, THUMB_HEIGHT, 0); imtk_draw_frame(thumb_x, thumb_y, THUMB_WIDTH, THUMB_HEIGHT, FRAME_OUTSET); /* draw display */ diff -r 6d35e6c7b2ca -r 10604ff95527 src/textbox.c --- a/src/textbox.c Thu Apr 14 23:04:07 2011 +0300 +++ b/src/textbox.c Thu Apr 14 23:21:56 2011 +0300 @@ -72,22 +72,19 @@ glColor4fv(imtk_get_color(IMTK_BASE_COLOR)); } - glBegin(GL_QUADS); - glVertex2f(x, y); - glVertex2f(x + TEXTBOX_SIZE, y); - glVertex2f(x + TEXTBOX_SIZE, y + 20); - glVertex2f(x, y + 20); - glEnd(); - - glColor4fv(imtk_get_color(IMTK_TEXT_COLOR)); + imtk_draw_rect(x, y, TEXTBOX_SIZE, 20, 0); if(imtk_has_focus(id)) { glBegin(GL_LINES); - glVertex2f(x + strsz + 2, y + 2); - glVertex2f(x + strsz + 2, y + 18); + glColor4f(0.8, 0.25, 0.18, imtk_get_color(IMTK_TEXT_COLOR)[3]); + glVertex2f(x + strsz + 3, y + 2); + glVertex2f(x + strsz + 3, y + 18); + glVertex2f(x + strsz + 4, y + 2); + glVertex2f(x + strsz + 4, y + 18); glEnd(); } + glColor4fv(imtk_get_color(IMTK_TEXT_COLOR)); imtk_draw_string(x + 2, y + 15, text); imtk_draw_frame(x, y, TEXTBOX_SIZE, 20, FRAME_INSET);