imtk

view src/draw.c @ 6:38609a9f7586

reorganizing ...
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 14 Apr 2011 14:22:42 +0300
parents
children 10604ff95527
line source
1 #include <string.h>
2 #include <assert.h>
3 #include "draw.h"
4 #include "imtk.h"
6 /* default colors, can be changed with imtk_set_color */
7 static float colors[][4] = {
8 {0.0, 0.0, 0.0, 1.0}, /* text color */
9 {0.7, 0.7, 0.7, 1.0}, /* base color */
10 {0.85, 0.85, 0.85, 1.0}, /* focus color */
11 {1.0, 1.0, 1.0, 1.0}, /* lit bevel */
12 {0.3, 0.3, 0.3, 1.0} /* shadowed bevel */
13 };
15 void imtk_set_color(int col, float r, float g, float b, float a)
16 {
17 assert(col >= 0 && col < sizeof colors / sizeof *colors);
19 colors[col][0] = r;
20 colors[col][1] = g;
21 colors[col][2] = b;
22 colors[col][3] = a;
23 }
25 float *imtk_get_color(int col)
26 {
27 return colors[col];
28 }
30 void imtk_draw_frame(int x, int y, int w, int h, int style)
31 {
32 float tcol[4], bcol[4];
34 switch(style) {
35 case FRAME_INSET:
36 memcpy(tcol, colors[IMTK_BEVEL_SHAD_COLOR], sizeof tcol);
37 memcpy(bcol, colors[IMTK_BEVEL_LIT_COLOR], sizeof bcol);
38 break;
40 case FRAME_OUTSET:
41 default:
42 memcpy(tcol, colors[IMTK_BEVEL_LIT_COLOR], sizeof tcol);
43 memcpy(bcol, colors[IMTK_BEVEL_SHAD_COLOR], sizeof bcol);
44 }
46 glBegin(GL_LINES);
47 glColor4fv(tcol);
48 glVertex2f(x, y + h);
49 glVertex2f(x, y);
50 glVertex2f(x, y);
51 glVertex2f(x + w, y);
52 glColor4fv(bcol);
53 glVertex2f(x + w, y);
54 glVertex2f(x + w, y + h);
55 glVertex2f(x + w, y + h);
56 glVertex2f(x, y + h);
57 glEnd();
59 }
61 void imtk_draw_string(int x, int y, const char *str)
62 {
63 glRasterPos2i(x, y);
64 while(*str) {
65 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *str++);
66 }
67 }
69 int imtk_string_size(const char *str)
70 {
71 return glutBitmapLength(GLUT_BITMAP_HELVETICA_12, (const unsigned char*)str);
72 }