imtk

view src/imtk.c @ 21:3138c38433e2

minor change
author John Tsiombikas <nuclear@siggraph.org>
date Sat, 30 Apr 2011 05:36:56 +0300
parents c7a7ddbe7714
children 17f5ff624da3
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <ctype.h>
5 #include <assert.h>
6 #ifndef __APPLE__
7 #include <GL/glut.h>
8 #else
9 #include <GLUT/glut.h>
10 #endif
11 #include "imtk.h"
12 #include "state.h"
13 #include "draw.h"
16 void imtk_post_redisplay(void)
17 {
18 glutPostRedisplay();
19 }
21 void imtk_begin(void)
22 {
23 int width, height;
25 glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
27 glDisable(GL_DEPTH_TEST);
28 glDisable(GL_STENCIL_TEST);
29 glDisable(GL_ALPHA_TEST);
30 glDisable(GL_TEXTURE_1D);
31 glDisable(GL_TEXTURE_2D);
32 glDisable(GL_CULL_FACE);
33 glDisable(GL_SCISSOR_TEST);
34 glDisable(GL_LIGHTING);
35 glEnable(GL_BLEND);
36 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
39 imtk_get_viewport(&width, &height);
41 glMatrixMode(GL_PROJECTION);
42 glPushMatrix();
43 glLoadIdentity();
44 glTranslatef(-1, 1, 0);
45 glScalef(2.0 / width, -2.0 / height, 1.0);
47 glMatrixMode(GL_MODELVIEW);
48 glPushMatrix();
49 glLoadIdentity();
50 }
52 void imtk_end(void)
53 {
54 glMatrixMode(GL_PROJECTION);
55 glPopMatrix();
56 glMatrixMode(GL_MODELVIEW);
57 glPopMatrix();
59 glPopAttrib();
60 }
62 void imtk_label(const char *str, int x, int y)
63 {
64 if(x == IMTK_AUTO || y == IMTK_AUTO) {
65 imtk_layout_get_pos(&x, &y);
66 }
68 glColor4fv(imtk_get_color(IMTK_TEXT_COLOR));
69 imtk_draw_string(x, y + 14, str);
70 imtk_layout_advance(imtk_string_size(str), 12);
71 }
74 static int box[4], span[4];
75 static int spacing;
76 static int layout;
78 void imtk_layout_start(int x, int y, int sp, int dir)
79 {
80 box[0] = span[0] = x;
81 box[1] = span[1] = y;
82 box[2] = box[3] = span[2] = span[3] = 0;
83 spacing = sp;
84 layout = dir;
85 }
87 void imtk_layout_dir(int dir)
88 {
89 layout = dir;
90 if(dir == IMTK_VERTICAL) {
91 imtk_layout_newline();
92 }
93 }
95 void imtk_layout_advance(int width, int height)
96 {
97 int max_span_y, max_box_y;
99 box[2] += width + spacing;
100 span[2] += width + spacing;
102 if(height > span[3]) {
103 span[3] = height;
104 }
106 max_span_y = span[1] + span[3];
107 max_box_y = box[1] + box[3];
109 if(max_span_y > max_box_y) {
110 box[3] = max_span_y - box[1];
111 }
113 if(layout == IMTK_VERTICAL) {
114 imtk_layout_newline();
115 }
116 }
118 void imtk_layout_newline(void)
119 {
120 span[0] = box[0];
121 span[1] = box[1] + box[3] + spacing;
122 span[2] = span[3] = 0;
123 }
125 void imtk_layout_get_pos(int *x, int *y)
126 {
127 *x = span[0] + span[2];
128 *y = span[1];
129 }
131 void imtk_layout_get_bounds(int *bbox)
132 {
133 memcpy(bbox, box, sizeof box);
134 }