imtk

view src/draw.c @ 8:10604ff95527

imtk_draw_rect
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 14 Apr 2011 23:21:56 +0300
parents 38609a9f7586
children 9c7987064bb0
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_rect(int x, int y, int w, int h, float *color_rgba)
31 {
32 glBegin(GL_QUADS);
33 if(color_rgba) {
34 glColor4fv(color_rgba);
35 }
36 glVertex2f(x, y);
37 glVertex2f(x + w, y);
38 glVertex2f(x + w, y + h);
39 glVertex2f(x, y + h);
40 glEnd();
41 }
43 void imtk_draw_frame(int x, int y, int w, int h, int style)
44 {
45 float tcol[4], bcol[4];
47 switch(style) {
48 case FRAME_INSET:
49 memcpy(tcol, colors[IMTK_BEVEL_SHAD_COLOR], sizeof tcol);
50 memcpy(bcol, colors[IMTK_BEVEL_LIT_COLOR], sizeof bcol);
51 break;
53 case FRAME_OUTSET:
54 default:
55 memcpy(tcol, colors[IMTK_BEVEL_LIT_COLOR], sizeof tcol);
56 memcpy(bcol, colors[IMTK_BEVEL_SHAD_COLOR], sizeof bcol);
57 }
59 glBegin(GL_LINES);
60 glColor4fv(tcol);
61 glVertex2f(x, y + h);
62 glVertex2f(x, y);
63 glVertex2f(x, y);
64 glVertex2f(x + w, y);
65 glColor4fv(bcol);
66 glVertex2f(x + w, y);
67 glVertex2f(x + w, y + h);
68 glVertex2f(x + w, y + h);
69 glVertex2f(x, y + h);
70 glEnd();
72 }
74 void imtk_draw_string(int x, int y, const char *str)
75 {
76 glRasterPos2i(x, y);
77 while(*str) {
78 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *str++);
79 }
80 }
82 int imtk_string_size(const char *str)
83 {
84 return glutBitmapLength(GLUT_BITMAP_HELVETICA_12, (const unsigned char*)str);
85 }