imtk

annotate src/draw.c @ 9:1b27a69603ac

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