nuclear@6: #include nuclear@6: #include nuclear@6: #include "draw.h" nuclear@6: #include "imtk.h" nuclear@6: nuclear@6: /* default colors, can be changed with imtk_set_color */ nuclear@6: static float colors[][4] = { nuclear@6: {0.0, 0.0, 0.0, 1.0}, /* text color */ nuclear@6: {0.7, 0.7, 0.7, 1.0}, /* base color */ nuclear@6: {0.85, 0.85, 0.85, 1.0}, /* focus color */ nuclear@6: {1.0, 1.0, 1.0, 1.0}, /* lit bevel */ nuclear@6: {0.3, 0.3, 0.3, 1.0} /* shadowed bevel */ nuclear@6: }; nuclear@6: nuclear@6: void imtk_set_color(int col, float r, float g, float b, float a) nuclear@6: { nuclear@6: assert(col >= 0 && col < sizeof colors / sizeof *colors); nuclear@6: nuclear@6: colors[col][0] = r; nuclear@6: colors[col][1] = g; nuclear@6: colors[col][2] = b; nuclear@6: colors[col][3] = a; nuclear@6: } nuclear@6: nuclear@6: float *imtk_get_color(int col) nuclear@6: { nuclear@6: return colors[col]; nuclear@6: } nuclear@6: nuclear@8: void imtk_draw_rect(int x, int y, int w, int h, float *color_rgba) nuclear@8: { nuclear@8: glBegin(GL_QUADS); nuclear@8: if(color_rgba) { nuclear@8: glColor4fv(color_rgba); nuclear@8: } nuclear@8: glVertex2f(x, y); nuclear@8: glVertex2f(x + w, y); nuclear@8: glVertex2f(x + w, y + h); nuclear@8: glVertex2f(x, y + h); nuclear@8: glEnd(); nuclear@8: } nuclear@8: nuclear@6: void imtk_draw_frame(int x, int y, int w, int h, int style) nuclear@6: { nuclear@6: float tcol[4], bcol[4]; nuclear@6: nuclear@6: switch(style) { nuclear@6: case FRAME_INSET: nuclear@6: memcpy(tcol, colors[IMTK_BEVEL_SHAD_COLOR], sizeof tcol); nuclear@6: memcpy(bcol, colors[IMTK_BEVEL_LIT_COLOR], sizeof bcol); nuclear@6: break; nuclear@6: nuclear@6: case FRAME_OUTSET: nuclear@6: default: nuclear@6: memcpy(tcol, colors[IMTK_BEVEL_LIT_COLOR], sizeof tcol); nuclear@6: memcpy(bcol, colors[IMTK_BEVEL_SHAD_COLOR], sizeof bcol); nuclear@6: } nuclear@6: nuclear@6: glBegin(GL_LINES); nuclear@6: glColor4fv(tcol); nuclear@6: glVertex2f(x, y + h); nuclear@6: glVertex2f(x, y); nuclear@6: glVertex2f(x, y); nuclear@6: glVertex2f(x + w, y); nuclear@6: glColor4fv(bcol); nuclear@6: glVertex2f(x + w, y); nuclear@6: glVertex2f(x + w, y + h); nuclear@6: glVertex2f(x + w, y + h); nuclear@6: glVertex2f(x, y + h); nuclear@6: glEnd(); nuclear@6: nuclear@6: } nuclear@6: nuclear@6: void imtk_draw_string(int x, int y, const char *str) nuclear@6: { nuclear@6: glRasterPos2i(x, y); nuclear@6: while(*str) { nuclear@6: glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *str++); nuclear@6: } nuclear@6: } nuclear@6: nuclear@6: int imtk_string_size(const char *str) nuclear@6: { nuclear@6: return glutBitmapLength(GLUT_BITMAP_HELVETICA_12, (const unsigned char*)str); nuclear@6: }