# HG changeset patch # User John Tsiombikas # Date 1299803149 -7200 # Node ID a115dff39a540e56eb0d6b86b5cae40e94f8763b # Parent 9b623dc0f2962dc0d92d9af67d6b718f67088edb rounded crappy buttons diff -r 9b623dc0f296 -r a115dff39a54 src/draw.c --- a/src/draw.c Wed Mar 09 10:12:31 2011 +0200 +++ b/src/draw.c Fri Mar 11 02:25:49 2011 +0200 @@ -1,3 +1,5 @@ +#include + #ifndef __APPLE__ #include #else @@ -10,8 +12,15 @@ float r, g, b, a; }; -static struct color fgcolor = {0, 0, 0, 1}; -static struct color bgcolor = {0.4, 0.4, 0.4, 1}; + +static void linestart(int x, int y); +static void lineto(int x, int y); +static void arcto(int x, int y, int cx, int cy, int rad); +static void arc(float x0, float y0, float x1, float y1, float cx, float cy, float rad, int subdiv); + + +static struct color fgcolor = {0, 0, 0, 0.5}; +static struct color bgcolor = {0.4, 0.4, 0.4, 0.5}; void imtk_draw_color(float r, float g, float b, float a) { @@ -21,6 +30,14 @@ fgcolor.a = a; } +void imtk_draw_colorv(float *v) +{ + fgcolor.r = v[0]; + fgcolor.g = v[1]; + fgcolor.b = v[2]; + fgcolor.a = v[3]; +} + void imtk_draw_background(float r, float g, float b, float a) { bgcolor.r = r; @@ -29,21 +46,49 @@ bgcolor.a = a; } +void imtk_draw_backgroundv(float *v) +{ + bgcolor.r = v[0]; + bgcolor.g = v[1]; + bgcolor.b = v[2]; + bgcolor.a = v[3]; +} + void imtk_draw_rect(int x, int y, int w, int h, int rad) { - glBegin(GL_LINE_LOOP); - linestart(x + rad, y); - lineto(x + w - rad, y); - arcto(x + w, y + rad); - lineto(x + w, y + h - rad); - arcto(x + w - rad, y + h); - lineto(x + rad, y + h); - arcto(x, y + h - rad); - lineto(x, y + rad); - arcto(x + rad, y); - glEnd(); + int i; + + glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT); + glEnable(GL_LINE_SMOOTH); + glEnable(GL_POLYGON_SMOOTH); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glLineWidth(1.5); + + for(i=0; i<2; i++) { + if(i == 0) { + glBegin(GL_POLYGON); + glColor4f(bgcolor.r, bgcolor.g, bgcolor.b, bgcolor.a); + } else { + glBegin(GL_LINE_STRIP); + glColor4f(fgcolor.r, fgcolor.g, fgcolor.b, fgcolor.a); + } + linestart(x + rad, y); + lineto(x + w - rad, y); + arcto(x + w, y + rad, x + w - rad, y + rad, rad); + lineto(x + w, y + h - rad); + arcto(x + w - rad, y + h, x + w - rad, y + h - rad, rad); + lineto(x + rad, y + h); + arcto(x, y + h - rad, x + rad, y + h - rad, rad); + lineto(x, y + rad); + arcto(x + rad, y, x + rad, y + rad, rad); + glEnd(); + } + + glPopAttrib(); } + static int px, py; static void linestart(int x, int y) @@ -60,6 +105,29 @@ glVertex2i(x, y); } -static void arcto(int x, int y, int rad) +static void arcto(int x, int y, int cx, int cy, int rad) { + arc(px, py, x, y, cx, cy, rad, 1); } + +static void arc(float x0, float y0, float x1, float y1, float cx, float cy, float rad, int subdiv) +{ + float x, y, vx, vy, len; + + x = x0 + (x1 - x0) * 0.5; + y = y0 + (y1 - y0) * 0.5; + vx = x - cx; + vy = y - cy; + len = sqrt(vx * vx + vy * vy); + x = cx + vx * rad / len; + y = cy + vy * rad / len; + + if(!subdiv) { + glVertex2f(x, y); + glVertex2f(x1, y1); + return; + } + + arc(x0, y0, x, y, cx, cy, rad, subdiv - 1); + arc(x, y, x1, y1, cx, cy, rad, subdiv - 1); +} diff -r 9b623dc0f296 -r a115dff39a54 src/draw.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/draw.h Fri Mar 11 02:25:49 2011 +0200 @@ -0,0 +1,11 @@ +#ifndef DRAW_H_ +#define DRAW_H_ + +void imtk_draw_color(float r, float g, float b, float a); +void imtk_draw_colorv(float *v); +void imtk_draw_background(float r, float g, float b, float a); +void imtk_draw_backgroundv(float *v); + +void imtk_draw_rect(int x, int y, int w, int h, int rad); + +#endif /* DRAW_H_ */ diff -r 9b623dc0f296 -r a115dff39a54 src/imtk.c --- a/src/imtk.c Wed Mar 09 10:12:31 2011 +0200 +++ b/src/imtk.c Fri Mar 11 02:25:49 2011 +0200 @@ -10,6 +10,7 @@ #include #endif #include "imtk.h" +#include "draw.h" #define CHECKBOX_SIZE 14 #define TEXTBOX_SIZE 100 @@ -44,11 +45,11 @@ /* default colors, can be changed with imtk_set_color */ static float colors[][4] = { - {0.0, 0.0, 0.0}, /* text color */ - {0.7, 0.7, 0.7}, /* base color */ - {0.85, 0.85, 0.85}, /* focus color */ - {1.0, 1.0, 1.0}, /* lit bevel */ - {0.3, 0.3, 0.3} /* shadowed bevel */ + {0.0, 0.0, 0.0, 0.7}, /* text color */ + {0.6, 0.6, 0.6, 0.7}, /* base color */ + {0.7, 0.7, 0.7, 0.7}, /* focus color */ + {1.0, 1.0, 1.0, 1.0}, /* lit bevel */ + {0.3, 0.3, 0.3, 1.0} /* shadowed bevel */ }; static int scr_width = 1, scr_height = 1; @@ -409,6 +410,7 @@ calc_button_size(label, &width, &height); + /* glBegin(GL_QUADS); if(hit_test(x, y, width, height)) { glColor3fv(colors[IMTK_FOCUS_COLOR]); @@ -422,6 +424,14 @@ glEnd(); draw_frame(x, y, width, height, active == id ? FRAME_INSET : FRAME_OUTSET); + */ + + if(hit_test(x, y, width, height)) { + imtk_draw_backgroundv(colors[IMTK_FOCUS_COLOR]); + } else { + imtk_draw_backgroundv(colors[IMTK_BASE_COLOR]); + } + imtk_draw_rect(x, y, width, height, 8); glColor3fv(colors[IMTK_TEXT_COLOR]); draw_string(x + 20, y + 15, label);