7 #define COLOR_MASK 0xff
9 /* default colors, can be changed with imtk_set_color */
10 static float colors[][4] = {
11 {0.0, 0.0, 0.0, 1.0}, /* text color */
12 {0.75, 0.75, 0.75, 1.0}, /* top color */
13 {0.56, 0.56, 0.56, 1.0}, /* bot color */
14 {0.9, 0.9, 0.9, 1.0}, /* lit bevel */
15 {0.3, 0.3, 0.3, 1.0}, /* shadowed bevel */
16 {0.8, 0.25, 0.18, 1.0}, /* cursor color */
17 {0.68, 0.85, 1.3, 1.0}, /* selection color */
18 {0.75, 0.1, 0.095, 1.0} /* check color */
21 static float focus_factor = 1.15;
22 static float press_factor = 0.8;
23 static float alpha = 1.0;
24 static float bevel = 1.0;
26 void imtk_set_color(unsigned int col, float r, float g, float b, float a)
28 int idx = col & COLOR_MASK;
29 assert(idx >= 0 && idx < sizeof colors / sizeof *colors);
37 float *imtk_get_color(unsigned int col)
40 int idx = col & COLOR_MASK;
42 memcpy(ret, colors + idx, sizeof ret);
43 if(col & IMTK_FOCUS_BIT) {
44 ret[0] *= focus_factor;
45 ret[1] *= focus_factor;
46 ret[2] *= focus_factor;
48 if(col & IMTK_PRESS_BIT) {
49 ret[0] *= press_factor;
50 ret[1] *= press_factor;
51 ret[2] *= press_factor;
53 if(col & IMTK_SEL_BIT) {
54 ret[0] *= colors[IMTK_SELECTION_COLOR][0];
55 ret[1] *= colors[IMTK_SELECTION_COLOR][1];
56 ret[2] *= colors[IMTK_SELECTION_COLOR][2];
62 void imtk_set_alpha(float a)
67 float imtk_get_alpha(void)
72 void imtk_set_bevel_width(float b)
77 float imtk_get_bevel_width(void)
82 void imtk_set_focus_factor(float fact)
87 float imtk_get_focus_factor(void)
92 void imtk_set_press_factor(float fact)
97 float imtk_get_press_factor(void)
102 void imtk_draw_rect(int x, int y, int w, int h, float *ctop, float *cbot)
109 glVertex2f(x + w, y);
114 glVertex2f(x + w, y + h);
115 glVertex2f(x, y + h);
119 void imtk_draw_frame(int x, int y, int w, int h, int style)
121 float tcol[4], bcol[4];
122 float b = imtk_get_bevel_width();
135 memcpy(tcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof tcol);
136 memcpy(bcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof bcol);
141 memcpy(tcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof tcol);
142 memcpy(bcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof bcol);
148 glVertex2f(x + b, y + b);
149 glVertex2f(x + w - b, y + b);
150 glVertex2f(x + w, y);
152 glVertex2f(x + b, y + b);
154 glVertex2f(x, y + h);
155 glVertex2f(x + b, y + h - b);
158 glVertex2f(x + b, y + h - b);
159 glVertex2f(x + w - b, y + h - b);
160 glVertex2f(x + w, y + h);
161 glVertex2f(x, y + h);
163 glVertex2f(x + w - b, y + b);
164 glVertex2f(x + w, y);
165 glVertex2f(x + w, y + h);
166 glVertex2f(x + w - b, y + h - b);
170 void imtk_draw_disc(int x, int y, float rad, int subdiv, float *ctop, float *cbot)
173 float t, dtheta, theta = 0.0;
179 dtheta = 2.0 * M_PI / subdiv;
181 color[0] = (ctop[0] + cbot[0]) * 0.5;
182 color[1] = (ctop[1] + cbot[1]) * 0.5;
183 color[2] = (ctop[2] + cbot[2]) * 0.5;
184 color[3] = (ctop[3] + cbot[3]) * 0.5;
186 glBegin(GL_TRIANGLE_FAN);
190 for(i=0; i<=subdiv; i++) {
197 t = (vy + 1.0) / 2.0;
198 color[0] = ctop[0] + (cbot[0] - ctop[0]) * t;
199 color[1] = ctop[1] + (cbot[1] - ctop[1]) * t;
200 color[2] = ctop[2] + (cbot[2] - ctop[2]) * t;
201 color[3] = ctop[3] + (cbot[3] - ctop[3]) * t;
204 glVertex2f(cx + vx * rad, cy + vy * rad);
209 void imtk_draw_disc_frame(int x, int y, float inner, float outer, int subdiv, int style)
212 float t, dtheta, theta = 0.0;
213 float color[4], tcol[4], bcol[4];
219 memcpy(tcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof tcol);
220 memcpy(bcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof bcol);
225 memcpy(tcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof tcol);
226 memcpy(bcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof bcol);
230 dtheta = 2.0 * M_PI / subdiv;
232 glBegin(GL_QUAD_STRIP);
234 for(i=0; i<=subdiv; i++) {
240 t = (vy + 1.0) / 2.0;
241 color[0] = tcol[0] + (bcol[0] - tcol[0]) * t;
242 color[1] = tcol[1] + (bcol[1] - tcol[1]) * t;
243 color[2] = tcol[2] + (bcol[2] - tcol[2]) * t;
244 color[3] = tcol[3] + (bcol[3] - tcol[3]) * t;
246 vx = cos(theta - M_PI / 4.0);
247 vy = sin(theta - M_PI / 4.0);
251 glVertex2f(cx + vx * inner, cy + vy * inner);
252 glVertex2f(cx + vx * outer, cy + vy * outer);
257 void imtk_draw_string(int x, int y, const char *str)
262 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *str++);
267 int imtk_string_size(const char *str)