imtk

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/draw.c	Thu Apr 14 14:22:42 2011 +0300
     1.3 @@ -0,0 +1,72 @@
     1.4 +#include <string.h>
     1.5 +#include <assert.h>
     1.6 +#include "draw.h"
     1.7 +#include "imtk.h"
     1.8 +
     1.9 +/* default colors, can be changed with imtk_set_color */
    1.10 +static float colors[][4] = {
    1.11 +	{0.0, 0.0, 0.0, 1.0},		/* text color */
    1.12 +	{0.7, 0.7, 0.7, 1.0},		/* base color */
    1.13 +	{0.85, 0.85, 0.85, 1.0},	/* focus color */
    1.14 +	{1.0, 1.0, 1.0, 1.0},		/* lit bevel */
    1.15 +	{0.3, 0.3, 0.3, 1.0}		/* shadowed bevel */
    1.16 +};
    1.17 +
    1.18 +void imtk_set_color(int col, float r, float g, float b, float a)
    1.19 +{
    1.20 +	assert(col >= 0 && col < sizeof colors / sizeof *colors);
    1.21 +
    1.22 +	colors[col][0] = r;
    1.23 +	colors[col][1] = g;
    1.24 +	colors[col][2] = b;
    1.25 +	colors[col][3] = a;
    1.26 +}
    1.27 +
    1.28 +float *imtk_get_color(int col)
    1.29 +{
    1.30 +	return colors[col];
    1.31 +}
    1.32 +
    1.33 +void imtk_draw_frame(int x, int y, int w, int h, int style)
    1.34 +{
    1.35 +	float tcol[4], bcol[4];
    1.36 +
    1.37 +	switch(style) {
    1.38 +	case FRAME_INSET:
    1.39 +		memcpy(tcol, colors[IMTK_BEVEL_SHAD_COLOR], sizeof tcol);
    1.40 +		memcpy(bcol, colors[IMTK_BEVEL_LIT_COLOR], sizeof bcol);
    1.41 +		break;
    1.42 +
    1.43 +	case FRAME_OUTSET:
    1.44 +	default:
    1.45 +		memcpy(tcol, colors[IMTK_BEVEL_LIT_COLOR], sizeof tcol);
    1.46 +		memcpy(bcol, colors[IMTK_BEVEL_SHAD_COLOR], sizeof bcol);
    1.47 +	}
    1.48 +
    1.49 +	glBegin(GL_LINES);
    1.50 +	glColor4fv(tcol);
    1.51 +	glVertex2f(x, y + h);
    1.52 +	glVertex2f(x, y);
    1.53 +	glVertex2f(x, y);
    1.54 +	glVertex2f(x + w, y);
    1.55 +	glColor4fv(bcol);
    1.56 +	glVertex2f(x + w, y);
    1.57 +	glVertex2f(x + w, y + h);
    1.58 +	glVertex2f(x + w, y + h);
    1.59 +	glVertex2f(x, y + h);
    1.60 +	glEnd();
    1.61 +
    1.62 +}
    1.63 +
    1.64 +void imtk_draw_string(int x, int y, const char *str)
    1.65 +{
    1.66 +	glRasterPos2i(x, y);
    1.67 +	while(*str) {
    1.68 +		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *str++);
    1.69 +	}
    1.70 +}
    1.71 +
    1.72 +int imtk_string_size(const char *str)
    1.73 +{
    1.74 +	return glutBitmapLength(GLUT_BITMAP_HELVETICA_12, (const unsigned char*)str);
    1.75 +}