imtk

annotate 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
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@6 12 {0.3, 0.3, 0.3, 1.0} /* shadowed bevel */
nuclear@6 13 };
nuclear@6 14
nuclear@6 15 void imtk_set_color(int col, float r, float g, float b, float a)
nuclear@6 16 {
nuclear@6 17 assert(col >= 0 && col < sizeof colors / sizeof *colors);
nuclear@6 18
nuclear@6 19 colors[col][0] = r;
nuclear@6 20 colors[col][1] = g;
nuclear@6 21 colors[col][2] = b;
nuclear@6 22 colors[col][3] = a;
nuclear@6 23 }
nuclear@6 24
nuclear@6 25 float *imtk_get_color(int col)
nuclear@6 26 {
nuclear@6 27 return colors[col];
nuclear@6 28 }
nuclear@6 29
nuclear@6 30 void imtk_draw_frame(int x, int y, int w, int h, int style)
nuclear@6 31 {
nuclear@6 32 float tcol[4], bcol[4];
nuclear@6 33
nuclear@6 34 switch(style) {
nuclear@6 35 case FRAME_INSET:
nuclear@6 36 memcpy(tcol, colors[IMTK_BEVEL_SHAD_COLOR], sizeof tcol);
nuclear@6 37 memcpy(bcol, colors[IMTK_BEVEL_LIT_COLOR], sizeof bcol);
nuclear@6 38 break;
nuclear@6 39
nuclear@6 40 case FRAME_OUTSET:
nuclear@6 41 default:
nuclear@6 42 memcpy(tcol, colors[IMTK_BEVEL_LIT_COLOR], sizeof tcol);
nuclear@6 43 memcpy(bcol, colors[IMTK_BEVEL_SHAD_COLOR], sizeof bcol);
nuclear@6 44 }
nuclear@6 45
nuclear@6 46 glBegin(GL_LINES);
nuclear@6 47 glColor4fv(tcol);
nuclear@6 48 glVertex2f(x, y + h);
nuclear@6 49 glVertex2f(x, y);
nuclear@6 50 glVertex2f(x, y);
nuclear@6 51 glVertex2f(x + w, y);
nuclear@6 52 glColor4fv(bcol);
nuclear@6 53 glVertex2f(x + w, y);
nuclear@6 54 glVertex2f(x + w, y + h);
nuclear@6 55 glVertex2f(x + w, y + h);
nuclear@6 56 glVertex2f(x, y + h);
nuclear@6 57 glEnd();
nuclear@6 58
nuclear@6 59 }
nuclear@6 60
nuclear@6 61 void imtk_draw_string(int x, int y, const char *str)
nuclear@6 62 {
nuclear@6 63 glRasterPos2i(x, y);
nuclear@6 64 while(*str) {
nuclear@6 65 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *str++);
nuclear@6 66 }
nuclear@6 67 }
nuclear@6 68
nuclear@6 69 int imtk_string_size(const char *str)
nuclear@6 70 {
nuclear@6 71 return glutBitmapLength(GLUT_BITMAP_HELVETICA_12, (const unsigned char*)str);
nuclear@6 72 }