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@6
|
6 /* default colors, can be changed with imtk_set_color */
|
nuclear@6
|
7 static float colors[][4] = {
|
nuclear@6
|
8 {0.0, 0.0, 0.0, 1.0}, /* text color */
|
nuclear@6
|
9 {0.7, 0.7, 0.7, 1.0}, /* base color */
|
nuclear@6
|
10 {0.85, 0.85, 0.85, 1.0}, /* focus color */
|
nuclear@6
|
11 {1.0, 1.0, 1.0, 1.0}, /* lit bevel */
|
nuclear@13
|
12 {0.3, 0.3, 0.3, 1.0}, /* shadowed bevel */
|
nuclear@13
|
13 {0.8, 0.25, 0.18, 1.0}, /* cursor color */
|
nuclear@13
|
14 {0.4, 0.5, 0.9, 1.0}, /* selection color */
|
nuclear@13
|
15 {0.63, 0.078, 0.078, 1.0} /* check color */
|
nuclear@6
|
16 };
|
nuclear@6
|
17
|
nuclear@13
|
18 static float alpha = 1.0;
|
nuclear@13
|
19 static float bevel = 1.0;
|
nuclear@13
|
20
|
nuclear@6
|
21 void imtk_set_color(int col, float r, float g, float b, float a)
|
nuclear@6
|
22 {
|
nuclear@6
|
23 assert(col >= 0 && col < sizeof colors / sizeof *colors);
|
nuclear@6
|
24
|
nuclear@6
|
25 colors[col][0] = r;
|
nuclear@6
|
26 colors[col][1] = g;
|
nuclear@6
|
27 colors[col][2] = b;
|
nuclear@6
|
28 colors[col][3] = a;
|
nuclear@6
|
29 }
|
nuclear@6
|
30
|
nuclear@6
|
31 float *imtk_get_color(int col)
|
nuclear@6
|
32 {
|
nuclear@13
|
33 static float ret[4];
|
nuclear@13
|
34 memcpy(ret, colors + col, sizeof ret);
|
nuclear@13
|
35 ret[3] *= alpha;
|
nuclear@13
|
36 return ret;
|
nuclear@13
|
37 }
|
nuclear@13
|
38
|
nuclear@13
|
39 void imtk_set_alpha(float a)
|
nuclear@13
|
40 {
|
nuclear@13
|
41 alpha = a;
|
nuclear@13
|
42 }
|
nuclear@13
|
43
|
nuclear@13
|
44 float imtk_get_alpha(void)
|
nuclear@13
|
45 {
|
nuclear@13
|
46 return alpha;
|
nuclear@13
|
47 }
|
nuclear@13
|
48
|
nuclear@13
|
49 void imtk_set_bevel_width(float b)
|
nuclear@13
|
50 {
|
nuclear@13
|
51 bevel = b;
|
nuclear@13
|
52 }
|
nuclear@13
|
53
|
nuclear@13
|
54 float imtk_get_bevel_width(void)
|
nuclear@13
|
55 {
|
nuclear@13
|
56 return bevel;
|
nuclear@6
|
57 }
|
nuclear@6
|
58
|
nuclear@8
|
59 void imtk_draw_rect(int x, int y, int w, int h, float *color_rgba)
|
nuclear@8
|
60 {
|
nuclear@8
|
61 glBegin(GL_QUADS);
|
nuclear@8
|
62 if(color_rgba) {
|
nuclear@8
|
63 glColor4fv(color_rgba);
|
nuclear@8
|
64 }
|
nuclear@8
|
65 glVertex2f(x, y);
|
nuclear@8
|
66 glVertex2f(x + w, y);
|
nuclear@8
|
67 glVertex2f(x + w, y + h);
|
nuclear@8
|
68 glVertex2f(x, y + h);
|
nuclear@8
|
69 glEnd();
|
nuclear@8
|
70 }
|
nuclear@8
|
71
|
nuclear@6
|
72 void imtk_draw_frame(int x, int y, int w, int h, int style)
|
nuclear@6
|
73 {
|
nuclear@6
|
74 float tcol[4], bcol[4];
|
nuclear@13
|
75 float b = imtk_get_bevel_width();
|
nuclear@6
|
76
|
nuclear@6
|
77 switch(style) {
|
nuclear@6
|
78 case FRAME_INSET:
|
nuclear@13
|
79 memcpy(tcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof tcol);
|
nuclear@13
|
80 memcpy(bcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof bcol);
|
nuclear@6
|
81 break;
|
nuclear@6
|
82
|
nuclear@6
|
83 case FRAME_OUTSET:
|
nuclear@6
|
84 default:
|
nuclear@13
|
85 memcpy(tcol, imtk_get_color(IMTK_BEVEL_LIT_COLOR), sizeof tcol);
|
nuclear@13
|
86 memcpy(bcol, imtk_get_color(IMTK_BEVEL_SHAD_COLOR), sizeof bcol);
|
nuclear@6
|
87 }
|
nuclear@6
|
88
|
nuclear@13
|
89 glBegin(GL_QUADS);
|
nuclear@13
|
90 glColor4fv(tcol);
|
nuclear@13
|
91 glVertex2f(x, y);
|
nuclear@13
|
92 glVertex2f(x + b, y + b);
|
nuclear@13
|
93 glVertex2f(x + w - b, y + b);
|
nuclear@13
|
94 glVertex2f(x + w, y);
|
nuclear@13
|
95
|
nuclear@13
|
96 glVertex2f(x + b, y + b);
|
nuclear@13
|
97 glVertex2f(x, y);
|
nuclear@13
|
98 glVertex2f(x, y + h);
|
nuclear@13
|
99 glVertex2f(x + b, y + h - b);
|
nuclear@13
|
100
|
nuclear@13
|
101 glColor4fv(bcol);
|
nuclear@13
|
102 glVertex2f(x + b, y + h - b);
|
nuclear@13
|
103 glVertex2f(x + w - b, y + h - b);
|
nuclear@13
|
104 glVertex2f(x + w, y + h);
|
nuclear@13
|
105 glVertex2f(x, y + h);
|
nuclear@13
|
106
|
nuclear@13
|
107 glVertex2f(x + w - b, y + b);
|
nuclear@13
|
108 glVertex2f(x + w, y);
|
nuclear@13
|
109 glVertex2f(x + w, y + h);
|
nuclear@13
|
110 glVertex2f(x + w - b, y + h - b);
|
nuclear@13
|
111 glEnd();
|
nuclear@13
|
112
|
nuclear@13
|
113 /*glBegin(GL_LINES);
|
nuclear@6
|
114 glColor4fv(tcol);
|
nuclear@6
|
115 glVertex2f(x, y + h);
|
nuclear@6
|
116 glVertex2f(x, y);
|
nuclear@6
|
117 glVertex2f(x, y);
|
nuclear@6
|
118 glVertex2f(x + w, y);
|
nuclear@6
|
119 glColor4fv(bcol);
|
nuclear@6
|
120 glVertex2f(x + w, y);
|
nuclear@6
|
121 glVertex2f(x + w, y + h);
|
nuclear@6
|
122 glVertex2f(x + w, y + h);
|
nuclear@6
|
123 glVertex2f(x, y + h);
|
nuclear@13
|
124 glEnd();*/
|
nuclear@6
|
125
|
nuclear@6
|
126 }
|
nuclear@6
|
127
|
nuclear@6
|
128 void imtk_draw_string(int x, int y, const char *str)
|
nuclear@6
|
129 {
|
nuclear@6
|
130 glRasterPos2i(x, y);
|
nuclear@6
|
131 while(*str) {
|
nuclear@6
|
132 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *str++);
|
nuclear@6
|
133 }
|
nuclear@6
|
134 }
|
nuclear@6
|
135
|
nuclear@6
|
136 int imtk_string_size(const char *str)
|
nuclear@6
|
137 {
|
nuclear@6
|
138 return glutBitmapLength(GLUT_BITMAP_HELVETICA_12, (const unsigned char*)str);
|
nuclear@6
|
139 }
|