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