9 #define COLOR_MASK 0xff
11 /* default colors, can be changed with imtk_set_color */
12 static float colors[][4] = {
13 {0.0, 0.0, 0.0, 1.0}, /* text color */
14 {0.75, 0.75, 0.75, 1.0}, /* top color */
15 {0.56, 0.56, 0.56, 1.0}, /* bot color */
16 {0.9, 0.9, 0.9, 1.0}, /* lit bevel */
17 {0.3, 0.3, 0.3, 1.0}, /* shadowed bevel */
18 {0.8, 0.25, 0.18, 1.0}, /* cursor color */
19 {0.68, 0.85, 1.3, 1.0}, /* selection color */
20 {0.75, 0.1, 0.095, 1.0} /* check color */
23 static float focus_factor = 1.15;
24 static float press_factor = 0.8;
25 static float alpha = 1.0;
26 static float bevel = 1.0;
28 void imtk_set_color(unsigned int col, float r, float g, float b, float a)
30 int idx = col & COLOR_MASK;
31 assert(idx >= 0 && idx < sizeof colors / sizeof *colors);
39 float *imtk_get_color(unsigned int col)
42 int idx = col & COLOR_MASK;
44 memcpy(ret, colors + idx, sizeof ret);
45 if(col & IMTK_FOCUS_BIT) {
46 ret[0] *= focus_factor;
47 ret[1] *= focus_factor;
48 ret[2] *= focus_factor;
50 if(col & IMTK_PRESS_BIT) {
51 ret[0] *= press_factor;
52 ret[1] *= press_factor;
53 ret[2] *= press_factor;
55 if(col & IMTK_SEL_BIT) {
56 ret[0] *= colors[IMTK_SELECTION_COLOR][0];
57 ret[1] *= colors[IMTK_SELECTION_COLOR][1];
58 ret[2] *= colors[IMTK_SELECTION_COLOR][2];
64 void imtk_set_alpha(float a)
69 float imtk_get_alpha(void)
74 void imtk_set_bevel_width(float b)
79 float imtk_get_bevel_width(void)
84 void imtk_set_focus_factor(float fact)
89 float imtk_get_focus_factor(void)
94 void imtk_set_press_factor(float fact)
99 float imtk_get_press_factor(void)
104 void imtk_draw_rect(int x, int y, int w, int h, float *ctop, float *cbot)
111 glVertex2f(x + w, y);
116 glVertex2f(x + w, y + h);
117 glVertex2f(x, y + h);
121 void imtk_draw_frame(int x, int y, int w, int h, int style)
123 float tcol[4], bcol[4];
124 float b = imtk_get_bevel_width();
137 memcpy(tcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof tcol);
138 memcpy(bcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof bcol);
143 memcpy(tcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof tcol);
144 memcpy(bcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof bcol);
150 glVertex2f(x + b, y + b);
151 glVertex2f(x + w - b, y + b);
152 glVertex2f(x + w, y);
154 glVertex2f(x + b, y + b);
156 glVertex2f(x, y + h);
157 glVertex2f(x + b, y + h - b);
160 glVertex2f(x + b, y + h - b);
161 glVertex2f(x + w - b, y + h - b);
162 glVertex2f(x + w, y + h);
163 glVertex2f(x, y + h);
165 glVertex2f(x + w - b, y + b);
166 glVertex2f(x + w, y);
167 glVertex2f(x + w, y + h);
168 glVertex2f(x + w - b, y + h - b);
172 void imtk_draw_disc(int x, int y, float rad, int subdiv, float *ctop, float *cbot)
175 float t, dtheta, theta = 0.0;
181 dtheta = 2.0 * M_PI / subdiv;
183 color[0] = (ctop[0] + cbot[0]) * 0.5;
184 color[1] = (ctop[1] + cbot[1]) * 0.5;
185 color[2] = (ctop[2] + cbot[2]) * 0.5;
186 color[3] = (ctop[3] + cbot[3]) * 0.5;
188 glBegin(GL_TRIANGLE_FAN);
192 for(i=0; i<=subdiv; i++) {
199 t = (vy + 1.0) / 2.0;
200 color[0] = ctop[0] + (cbot[0] - ctop[0]) * t;
201 color[1] = ctop[1] + (cbot[1] - ctop[1]) * t;
202 color[2] = ctop[2] + (cbot[2] - ctop[2]) * t;
203 color[3] = ctop[3] + (cbot[3] - ctop[3]) * t;
206 glVertex2f(cx + vx * rad, cy + vy * rad);
211 void imtk_draw_disc_frame(int x, int y, float inner, float outer, int subdiv, int style)
214 float t, dtheta, theta = 0.0;
215 float color[4], tcol[4], bcol[4];
221 memcpy(tcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof tcol);
222 memcpy(bcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof bcol);
227 memcpy(tcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof tcol);
228 memcpy(bcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof bcol);
232 dtheta = 2.0 * M_PI / subdiv;
234 glBegin(GL_QUAD_STRIP);
236 for(i=0; i<=subdiv; i++) {
242 t = (vy + 1.0) / 2.0;
243 color[0] = tcol[0] + (bcol[0] - tcol[0]) * t;
244 color[1] = tcol[1] + (bcol[1] - tcol[1]) * t;
245 color[2] = tcol[2] + (bcol[2] - tcol[2]) * t;
246 color[3] = tcol[3] + (bcol[3] - tcol[3]) * t;
248 vx = cos(theta - M_PI / 4.0);
249 vy = sin(theta - M_PI / 4.0);
253 glVertex2f(cx + vx * inner, cy + vy * inner);
254 glVertex2f(cx + vx * outer, cy + vy * outer);
259 void imtk_draw_string(int x, int y, const char *str)
261 dtx_use_font(fnt_ui, fnt_ui_size);
263 glMatrixMode(GL_MODELVIEW);
265 glTranslatef(x, y + dtx_line_height() * 0.2, 0);
268 glColor4fv(colors[IMTK_TEXT_COLOR]);
274 int imtk_string_size(const char *str)
276 dtx_use_font(fnt_ui, fnt_ui_size);
277 return dtx_string_width(str);