imtk
diff src/draw.c @ 14:df2bc9406561
added gradients
author | John Tsiombikas <nuclear@siggraph.org> |
---|---|
date | Tue, 19 Apr 2011 03:01:46 +0300 |
parents | 9c7987064bb0 |
children | 6893b4dca5a3 |
line diff
1.1 --- a/src/draw.c Mon Apr 18 06:15:46 2011 +0300 1.2 +++ b/src/draw.c Tue Apr 19 03:01:46 2011 +0300 1.3 @@ -3,35 +3,52 @@ 1.4 #include "draw.h" 1.5 #include "imtk.h" 1.6 1.7 +#define COLOR_MASK 0xff 1.8 + 1.9 /* default colors, can be changed with imtk_set_color */ 1.10 static float colors[][4] = { 1.11 {0.0, 0.0, 0.0, 1.0}, /* text color */ 1.12 - {0.7, 0.7, 0.7, 1.0}, /* base color */ 1.13 - {0.85, 0.85, 0.85, 1.0}, /* focus color */ 1.14 - {1.0, 1.0, 1.0, 1.0}, /* lit bevel */ 1.15 + {0.75, 0.75, 0.75, 1.0}, /* top color */ 1.16 + {0.56, 0.56, 0.56, 1.0}, /* bot color */ 1.17 + {0.9, 0.9, 0.9, 1.0}, /* lit bevel */ 1.18 {0.3, 0.3, 0.3, 1.0}, /* shadowed bevel */ 1.19 {0.8, 0.25, 0.18, 1.0}, /* cursor color */ 1.20 {0.4, 0.5, 0.9, 1.0}, /* selection color */ 1.21 - {0.63, 0.078, 0.078, 1.0} /* check color */ 1.22 + {0.75, 0.1, 0.095, 1.0} /* check color */ 1.23 }; 1.24 1.25 +static float focus_factor = 1.1; 1.26 +static float press_factor = 0.8; 1.27 static float alpha = 1.0; 1.28 static float bevel = 1.0; 1.29 1.30 -void imtk_set_color(int col, float r, float g, float b, float a) 1.31 +void imtk_set_color(unsigned int col, float r, float g, float b, float a) 1.32 { 1.33 - assert(col >= 0 && col < sizeof colors / sizeof *colors); 1.34 + int idx = col & COLOR_MASK; 1.35 + assert(idx >= 0 && idx < sizeof colors / sizeof *colors); 1.36 1.37 - colors[col][0] = r; 1.38 - colors[col][1] = g; 1.39 - colors[col][2] = b; 1.40 - colors[col][3] = a; 1.41 + colors[idx][0] = r; 1.42 + colors[idx][1] = g; 1.43 + colors[idx][2] = b; 1.44 + colors[idx][3] = a; 1.45 } 1.46 1.47 -float *imtk_get_color(int col) 1.48 +float *imtk_get_color(unsigned int col) 1.49 { 1.50 static float ret[4]; 1.51 - memcpy(ret, colors + col, sizeof ret); 1.52 + int idx = col & COLOR_MASK; 1.53 + 1.54 + memcpy(ret, colors + idx, sizeof ret); 1.55 + if(col & IMTK_FOCUS_BIT) { 1.56 + ret[0] *= focus_factor; 1.57 + ret[1] *= focus_factor; 1.58 + ret[2] *= focus_factor; 1.59 + } 1.60 + if(col & IMTK_PRESS_BIT) { 1.61 + ret[0] *= press_factor; 1.62 + ret[1] *= press_factor; 1.63 + ret[2] *= press_factor; 1.64 + } 1.65 ret[3] *= alpha; 1.66 return ret; 1.67 } 1.68 @@ -56,14 +73,38 @@ 1.69 return bevel; 1.70 } 1.71 1.72 -void imtk_draw_rect(int x, int y, int w, int h, float *color_rgba) 1.73 +void imtk_set_focus_factor(float fact) 1.74 +{ 1.75 + focus_factor = fact; 1.76 +} 1.77 + 1.78 +float imtk_get_focus_factor(void) 1.79 +{ 1.80 + return focus_factor; 1.81 +} 1.82 + 1.83 +void imtk_set_press_factor(float fact) 1.84 +{ 1.85 + press_factor = fact; 1.86 +} 1.87 + 1.88 +float imtk_get_press_factor(void) 1.89 +{ 1.90 + return press_factor; 1.91 +} 1.92 + 1.93 +void imtk_draw_rect(int x, int y, int w, int h, float *ctop, float *cbot) 1.94 { 1.95 glBegin(GL_QUADS); 1.96 - if(color_rgba) { 1.97 - glColor4fv(color_rgba); 1.98 + if(ctop) { 1.99 + glColor4fv(ctop); 1.100 } 1.101 glVertex2f(x, y); 1.102 glVertex2f(x + w, y); 1.103 + 1.104 + if(cbot) { 1.105 + glColor4fv(cbot); 1.106 + } 1.107 glVertex2f(x + w, y + h); 1.108 glVertex2f(x, y + h); 1.109 glEnd(); 1.110 @@ -74,6 +115,15 @@ 1.111 float tcol[4], bcol[4]; 1.112 float b = imtk_get_bevel_width(); 1.113 1.114 + if(!b) { 1.115 + return; 1.116 + } 1.117 + 1.118 + x -= b; 1.119 + y -= b; 1.120 + w += b * 2; 1.121 + h += b * 2; 1.122 + 1.123 switch(style) { 1.124 case FRAME_INSET: 1.125 memcpy(tcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof tcol); 1.126 @@ -109,20 +159,6 @@ 1.127 glVertex2f(x + w, y + h); 1.128 glVertex2f(x + w - b, y + h - b); 1.129 glEnd(); 1.130 - 1.131 - /*glBegin(GL_LINES); 1.132 - glColor4fv(tcol); 1.133 - glVertex2f(x, y + h); 1.134 - glVertex2f(x, y); 1.135 - glVertex2f(x, y); 1.136 - glVertex2f(x + w, y); 1.137 - glColor4fv(bcol); 1.138 - glVertex2f(x + w, y); 1.139 - glVertex2f(x + w, y + h); 1.140 - glVertex2f(x + w, y + h); 1.141 - glVertex2f(x, y + h); 1.142 - glEnd();*/ 1.143 - 1.144 } 1.145 1.146 void imtk_draw_string(int x, int y, const char *str)