rev |
line source |
nuclear@6
|
1 #include <string.h>
|
nuclear@6
|
2 #include <assert.h>
|
nuclear@6
|
3 #include "draw.h"
|
nuclear@6
|
4 #include "imtk.h"
|
nuclear@6
|
5
|
nuclear@14
|
6 #define COLOR_MASK 0xff
|
nuclear@14
|
7
|
nuclear@6
|
8 /* default colors, can be changed with imtk_set_color */
|
nuclear@6
|
9 static float colors[][4] = {
|
nuclear@6
|
10 {0.0, 0.0, 0.0, 1.0}, /* text color */
|
nuclear@14
|
11 {0.75, 0.75, 0.75, 1.0}, /* top color */
|
nuclear@14
|
12 {0.56, 0.56, 0.56, 1.0}, /* bot color */
|
nuclear@14
|
13 {0.9, 0.9, 0.9, 1.0}, /* lit bevel */
|
nuclear@13
|
14 {0.3, 0.3, 0.3, 1.0}, /* shadowed bevel */
|
nuclear@13
|
15 {0.8, 0.25, 0.18, 1.0}, /* cursor color */
|
nuclear@15
|
16 {0.68, 0.85, 1.3, 1.0}, /* selection color */
|
nuclear@14
|
17 {0.75, 0.1, 0.095, 1.0} /* check color */
|
nuclear@6
|
18 };
|
nuclear@6
|
19
|
nuclear@15
|
20 static float focus_factor = 1.15;
|
nuclear@14
|
21 static float press_factor = 0.8;
|
nuclear@13
|
22 static float alpha = 1.0;
|
nuclear@13
|
23 static float bevel = 1.0;
|
nuclear@13
|
24
|
nuclear@14
|
25 void imtk_set_color(unsigned int col, float r, float g, float b, float a)
|
nuclear@6
|
26 {
|
nuclear@14
|
27 int idx = col & COLOR_MASK;
|
nuclear@14
|
28 assert(idx >= 0 && idx < sizeof colors / sizeof *colors);
|
nuclear@6
|
29
|
nuclear@14
|
30 colors[idx][0] = r;
|
nuclear@14
|
31 colors[idx][1] = g;
|
nuclear@14
|
32 colors[idx][2] = b;
|
nuclear@14
|
33 colors[idx][3] = a;
|
nuclear@6
|
34 }
|
nuclear@6
|
35
|
nuclear@14
|
36 float *imtk_get_color(unsigned int col)
|
nuclear@6
|
37 {
|
nuclear@13
|
38 static float ret[4];
|
nuclear@14
|
39 int idx = col & COLOR_MASK;
|
nuclear@14
|
40
|
nuclear@14
|
41 memcpy(ret, colors + idx, sizeof ret);
|
nuclear@14
|
42 if(col & IMTK_FOCUS_BIT) {
|
nuclear@14
|
43 ret[0] *= focus_factor;
|
nuclear@14
|
44 ret[1] *= focus_factor;
|
nuclear@14
|
45 ret[2] *= focus_factor;
|
nuclear@14
|
46 }
|
nuclear@14
|
47 if(col & IMTK_PRESS_BIT) {
|
nuclear@14
|
48 ret[0] *= press_factor;
|
nuclear@14
|
49 ret[1] *= press_factor;
|
nuclear@14
|
50 ret[2] *= press_factor;
|
nuclear@14
|
51 }
|
nuclear@15
|
52 if(col & IMTK_SEL_BIT) {
|
nuclear@15
|
53 ret[0] *= colors[IMTK_SELECTION_COLOR][0];
|
nuclear@15
|
54 ret[1] *= colors[IMTK_SELECTION_COLOR][1];
|
nuclear@15
|
55 ret[2] *= colors[IMTK_SELECTION_COLOR][2];
|
nuclear@15
|
56 }
|
nuclear@13
|
57 ret[3] *= alpha;
|
nuclear@13
|
58 return ret;
|
nuclear@13
|
59 }
|
nuclear@13
|
60
|
nuclear@13
|
61 void imtk_set_alpha(float a)
|
nuclear@13
|
62 {
|
nuclear@13
|
63 alpha = a;
|
nuclear@13
|
64 }
|
nuclear@13
|
65
|
nuclear@13
|
66 float imtk_get_alpha(void)
|
nuclear@13
|
67 {
|
nuclear@13
|
68 return alpha;
|
nuclear@13
|
69 }
|
nuclear@13
|
70
|
nuclear@13
|
71 void imtk_set_bevel_width(float b)
|
nuclear@13
|
72 {
|
nuclear@13
|
73 bevel = b;
|
nuclear@13
|
74 }
|
nuclear@13
|
75
|
nuclear@13
|
76 float imtk_get_bevel_width(void)
|
nuclear@13
|
77 {
|
nuclear@13
|
78 return bevel;
|
nuclear@6
|
79 }
|
nuclear@6
|
80
|
nuclear@14
|
81 void imtk_set_focus_factor(float fact)
|
nuclear@14
|
82 {
|
nuclear@14
|
83 focus_factor = fact;
|
nuclear@14
|
84 }
|
nuclear@14
|
85
|
nuclear@14
|
86 float imtk_get_focus_factor(void)
|
nuclear@14
|
87 {
|
nuclear@14
|
88 return focus_factor;
|
nuclear@14
|
89 }
|
nuclear@14
|
90
|
nuclear@14
|
91 void imtk_set_press_factor(float fact)
|
nuclear@14
|
92 {
|
nuclear@14
|
93 press_factor = fact;
|
nuclear@14
|
94 }
|
nuclear@14
|
95
|
nuclear@14
|
96 float imtk_get_press_factor(void)
|
nuclear@14
|
97 {
|
nuclear@14
|
98 return press_factor;
|
nuclear@14
|
99 }
|
nuclear@14
|
100
|
nuclear@14
|
101 void imtk_draw_rect(int x, int y, int w, int h, float *ctop, float *cbot)
|
nuclear@8
|
102 {
|
nuclear@8
|
103 glBegin(GL_QUADS);
|
nuclear@14
|
104 if(ctop) {
|
nuclear@14
|
105 glColor4fv(ctop);
|
nuclear@8
|
106 }
|
nuclear@8
|
107 glVertex2f(x, y);
|
nuclear@8
|
108 glVertex2f(x + w, y);
|
nuclear@14
|
109
|
nuclear@14
|
110 if(cbot) {
|
nuclear@14
|
111 glColor4fv(cbot);
|
nuclear@14
|
112 }
|
nuclear@8
|
113 glVertex2f(x + w, y + h);
|
nuclear@8
|
114 glVertex2f(x, y + h);
|
nuclear@8
|
115 glEnd();
|
nuclear@8
|
116 }
|
nuclear@8
|
117
|
nuclear@6
|
118 void imtk_draw_frame(int x, int y, int w, int h, int style)
|
nuclear@6
|
119 {
|
nuclear@6
|
120 float tcol[4], bcol[4];
|
nuclear@13
|
121 float b = imtk_get_bevel_width();
|
nuclear@6
|
122
|
nuclear@14
|
123 if(!b) {
|
nuclear@14
|
124 return;
|
nuclear@14
|
125 }
|
nuclear@14
|
126
|
nuclear@14
|
127 x -= b;
|
nuclear@14
|
128 y -= b;
|
nuclear@14
|
129 w += b * 2;
|
nuclear@14
|
130 h += b * 2;
|
nuclear@14
|
131
|
nuclear@6
|
132 switch(style) {
|
nuclear@6
|
133 case FRAME_INSET:
|
nuclear@13
|
134 memcpy(tcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof tcol);
|
nuclear@13
|
135 memcpy(bcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof bcol);
|
nuclear@6
|
136 break;
|
nuclear@6
|
137
|
nuclear@6
|
138 case FRAME_OUTSET:
|
nuclear@6
|
139 default:
|
nuclear@13
|
140 memcpy(tcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof tcol);
|
nuclear@13
|
141 memcpy(bcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof bcol);
|
nuclear@6
|
142 }
|
nuclear@6
|
143
|
nuclear@13
|
144 glBegin(GL_QUADS);
|
nuclear@13
|
145 glColor4fv(tcol);
|
nuclear@13
|
146 glVertex2f(x, y);
|
nuclear@13
|
147 glVertex2f(x + b, y + b);
|
nuclear@13
|
148 glVertex2f(x + w - b, y + b);
|
nuclear@13
|
149 glVertex2f(x + w, y);
|
nuclear@13
|
150
|
nuclear@13
|
151 glVertex2f(x + b, y + b);
|
nuclear@13
|
152 glVertex2f(x, y);
|
nuclear@13
|
153 glVertex2f(x, y + h);
|
nuclear@13
|
154 glVertex2f(x + b, y + h - b);
|
nuclear@13
|
155
|
nuclear@13
|
156 glColor4fv(bcol);
|
nuclear@13
|
157 glVertex2f(x + b, y + h - b);
|
nuclear@13
|
158 glVertex2f(x + w - b, y + h - b);
|
nuclear@13
|
159 glVertex2f(x + w, y + h);
|
nuclear@13
|
160 glVertex2f(x, y + h);
|
nuclear@13
|
161
|
nuclear@13
|
162 glVertex2f(x + w - b, y + b);
|
nuclear@13
|
163 glVertex2f(x + w, y);
|
nuclear@13
|
164 glVertex2f(x + w, y + h);
|
nuclear@13
|
165 glVertex2f(x + w - b, y + h - b);
|
nuclear@13
|
166 glEnd();
|
nuclear@6
|
167 }
|
nuclear@6
|
168
|
nuclear@6
|
169 void imtk_draw_string(int x, int y, const char *str)
|
nuclear@6
|
170 {
|
nuclear@6
|
171 glRasterPos2i(x, y);
|
nuclear@6
|
172 while(*str) {
|
nuclear@6
|
173 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *str++);
|
nuclear@6
|
174 }
|
nuclear@6
|
175 }
|
nuclear@6
|
176
|
nuclear@6
|
177 int imtk_string_size(const char *str)
|
nuclear@6
|
178 {
|
nuclear@6
|
179 return glutBitmapLength(GLUT_BITMAP_HELVETICA_12, (const unsigned char*)str);
|
nuclear@6
|
180 }
|