imtk
diff src/draw.c @ 13:9c7987064bb0
- fixed the frame drawing a bit
- added global alpha value and various drawing parameters
- backported the checkbox check mark from glamtk
- fixed progress bar drawing so that the bevels of the trough and the bar won't overlap
author | John Tsiombikas <nuclear@siggraph.org> |
---|---|
date | Mon, 18 Apr 2011 06:15:46 +0300 |
parents | 10604ff95527 |
children | df2bc9406561 |
line diff
1.1 --- a/src/draw.c Sun Apr 17 18:20:23 2011 +0300 1.2 +++ b/src/draw.c Mon Apr 18 06:15:46 2011 +0300 1.3 @@ -9,9 +9,15 @@ 1.4 {0.7, 0.7, 0.7, 1.0}, /* base color */ 1.5 {0.85, 0.85, 0.85, 1.0}, /* focus color */ 1.6 {1.0, 1.0, 1.0, 1.0}, /* lit bevel */ 1.7 - {0.3, 0.3, 0.3, 1.0} /* shadowed bevel */ 1.8 + {0.3, 0.3, 0.3, 1.0}, /* shadowed bevel */ 1.9 + {0.8, 0.25, 0.18, 1.0}, /* cursor color */ 1.10 + {0.4, 0.5, 0.9, 1.0}, /* selection color */ 1.11 + {0.63, 0.078, 0.078, 1.0} /* check color */ 1.12 }; 1.13 1.14 +static float alpha = 1.0; 1.15 +static float bevel = 1.0; 1.16 + 1.17 void imtk_set_color(int col, float r, float g, float b, float a) 1.18 { 1.19 assert(col >= 0 && col < sizeof colors / sizeof *colors); 1.20 @@ -24,7 +30,30 @@ 1.21 1.22 float *imtk_get_color(int col) 1.23 { 1.24 - return colors[col]; 1.25 + static float ret[4]; 1.26 + memcpy(ret, colors + col, sizeof ret); 1.27 + ret[3] *= alpha; 1.28 + return ret; 1.29 +} 1.30 + 1.31 +void imtk_set_alpha(float a) 1.32 +{ 1.33 + alpha = a; 1.34 +} 1.35 + 1.36 +float imtk_get_alpha(void) 1.37 +{ 1.38 + return alpha; 1.39 +} 1.40 + 1.41 +void imtk_set_bevel_width(float b) 1.42 +{ 1.43 + bevel = b; 1.44 +} 1.45 + 1.46 +float imtk_get_bevel_width(void) 1.47 +{ 1.48 + return bevel; 1.49 } 1.50 1.51 void imtk_draw_rect(int x, int y, int w, int h, float *color_rgba) 1.52 @@ -43,20 +72,45 @@ 1.53 void imtk_draw_frame(int x, int y, int w, int h, int style) 1.54 { 1.55 float tcol[4], bcol[4]; 1.56 + float b = imtk_get_bevel_width(); 1.57 1.58 switch(style) { 1.59 case FRAME_INSET: 1.60 - memcpy(tcol, colors[IMTK_BEVEL_SHAD_COLOR], sizeof tcol); 1.61 - memcpy(bcol, colors[IMTK_BEVEL_LIT_COLOR], sizeof bcol); 1.62 + memcpy(tcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof tcol); 1.63 + memcpy(bcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof bcol); 1.64 break; 1.65 1.66 case FRAME_OUTSET: 1.67 default: 1.68 - memcpy(tcol, colors[IMTK_BEVEL_LIT_COLOR], sizeof tcol); 1.69 - memcpy(bcol, colors[IMTK_BEVEL_SHAD_COLOR], sizeof bcol); 1.70 + memcpy(tcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof tcol); 1.71 + memcpy(bcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof bcol); 1.72 } 1.73 1.74 - glBegin(GL_LINES); 1.75 + glBegin(GL_QUADS); 1.76 + glColor4fv(tcol); 1.77 + glVertex2f(x, y); 1.78 + glVertex2f(x + b, y + b); 1.79 + glVertex2f(x + w - b, y + b); 1.80 + glVertex2f(x + w, y); 1.81 + 1.82 + glVertex2f(x + b, y + b); 1.83 + glVertex2f(x, y); 1.84 + glVertex2f(x, y + h); 1.85 + glVertex2f(x + b, y + h - b); 1.86 + 1.87 + glColor4fv(bcol); 1.88 + glVertex2f(x + b, y + h - b); 1.89 + glVertex2f(x + w - b, y + h - b); 1.90 + glVertex2f(x + w, y + h); 1.91 + glVertex2f(x, y + h); 1.92 + 1.93 + glVertex2f(x + w - b, y + b); 1.94 + glVertex2f(x + w, y); 1.95 + glVertex2f(x + w, y + h); 1.96 + glVertex2f(x + w - b, y + h - b); 1.97 + glEnd(); 1.98 + 1.99 + /*glBegin(GL_LINES); 1.100 glColor4fv(tcol); 1.101 glVertex2f(x, y + h); 1.102 glVertex2f(x, y); 1.103 @@ -67,7 +121,7 @@ 1.104 glVertex2f(x + w, y + h); 1.105 glVertex2f(x + w, y + h); 1.106 glVertex2f(x, y + h); 1.107 - glEnd(); 1.108 + glEnd();*/ 1.109 1.110 } 1.111