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@4
|
5 #include <stdarg.h>
|
nuclear@0
|
6 #include <assert.h>
|
nuclear@0
|
7 #ifndef __APPLE__
|
nuclear@0
|
8 #include <GL/glut.h>
|
nuclear@0
|
9 #else
|
nuclear@0
|
10 #include <GLUT/glut.h>
|
nuclear@0
|
11 #endif
|
nuclear@0
|
12 #include "imtk.h"
|
nuclear@0
|
13
|
nuclear@1
|
14
|
nuclear@5
|
15 static void draw_progress(int id, float pos, int x, int y);
|
nuclear@1
|
16
|
nuclear@0
|
17
|
nuclear@0
|
18 void imtk_begin(void)
|
nuclear@0
|
19 {
|
nuclear@0
|
20 glMatrixMode(GL_PROJECTION);
|
nuclear@0
|
21 glPushMatrix();
|
nuclear@0
|
22 glLoadIdentity();
|
nuclear@0
|
23 glTranslatef(-1, 1, 0);
|
nuclear@0
|
24 glScalef(2.0 / scr_width, -2.0 / scr_height, 1.0);
|
nuclear@2
|
25
|
nuclear@2
|
26 glMatrixMode(GL_MODELVIEW);
|
nuclear@2
|
27 glPushMatrix();
|
nuclear@2
|
28 glLoadIdentity();
|
nuclear@2
|
29
|
nuclear@2
|
30 glPushAttrib(GL_ENABLE_BIT);
|
nuclear@2
|
31 glDisable(GL_DEPTH_TEST);
|
nuclear@2
|
32 glDisable(GL_CULL_FACE);
|
nuclear@2
|
33 glDisable(GL_LIGHTING);
|
nuclear@0
|
34 }
|
nuclear@0
|
35
|
nuclear@0
|
36 void imtk_end(void)
|
nuclear@0
|
37 {
|
nuclear@2
|
38 glPopAttrib();
|
nuclear@2
|
39
|
nuclear@0
|
40 glMatrixMode(GL_PROJECTION);
|
nuclear@0
|
41 glPopMatrix();
|
nuclear@2
|
42 glMatrixMode(GL_MODELVIEW);
|
nuclear@2
|
43 glPopMatrix();
|
nuclear@0
|
44 }
|
nuclear@0
|
45
|
nuclear@5
|
46
|
nuclear@5
|
47 void imtk_post_redisplay(void)
|
nuclear@0
|
48 {
|
nuclear@5
|
49 glutPostRedisplay();
|
nuclear@0
|
50 }
|
nuclear@0
|
51
|
nuclear@1
|
52
|
nuclear@3
|
53
|
nuclear@3
|
54 void imtk_progress(int id, float pos, int x, int y)
|
nuclear@3
|
55 {
|
nuclear@3
|
56 draw_progress(id, pos, x, y);
|
nuclear@3
|
57 }
|
nuclear@3
|
58
|
nuclear@4
|
59 int imtk_listbox(int id, const char *list, int sel, int x, int y)
|
nuclear@4
|
60 {
|
nuclear@4
|
61 int i;
|
nuclear@4
|
62 assert(id >= 0);
|
nuclear@4
|
63
|
nuclear@4
|
64 if(!list) {
|
nuclear@4
|
65 return -1;
|
nuclear@4
|
66 }
|
nuclear@4
|
67
|
nuclear@4
|
68 if(id & 1) {
|
nuclear@4
|
69 id++;
|
nuclear@4
|
70 }
|
nuclear@4
|
71
|
nuclear@4
|
72 for(i=0; *list; i++) {
|
nuclear@4
|
73 if(imtk_button(id + i * 2 + 1, list, x, y + i * 20)) {
|
nuclear@4
|
74 sel = i;
|
nuclear@4
|
75 }
|
nuclear@4
|
76 list += strlen(list) + 1;
|
nuclear@4
|
77 }
|
nuclear@4
|
78 return sel;
|
nuclear@4
|
79 }
|
nuclear@4
|
80
|
nuclear@4
|
81 int imtk_combobox(int id, char *textbuf, size_t buf_sz, const char *list, int sel, int x, int y)
|
nuclear@4
|
82 {
|
nuclear@4
|
83 imtk_textbox(id + 1, textbuf, buf_sz, x, y);
|
nuclear@4
|
84 imtk_button(id + 3, "V", x + TEXTBOX_SIZE, y);
|
nuclear@4
|
85
|
nuclear@4
|
86 if(prev_active == id + 3) {
|
nuclear@4
|
87 sel = imtk_listbox(id + 5, list, sel, x, y + 20);
|
nuclear@4
|
88 }
|
nuclear@4
|
89 return sel;
|
nuclear@4
|
90 }
|
nuclear@4
|
91
|
nuclear@4
|
92 char *imtk_create_list(const char *first, ...)
|
nuclear@4
|
93 {
|
nuclear@4
|
94 int sz;
|
nuclear@4
|
95 char *buf, *item;
|
nuclear@4
|
96 va_list ap;
|
nuclear@4
|
97
|
nuclear@4
|
98 if(!first) {
|
nuclear@4
|
99 return 0;
|
nuclear@4
|
100 }
|
nuclear@4
|
101
|
nuclear@4
|
102 sz = strlen(first) + 2;
|
nuclear@4
|
103 if(!(buf = malloc(sz))) {
|
nuclear@4
|
104 return 0;
|
nuclear@4
|
105 }
|
nuclear@4
|
106 memcpy(buf, first, sz - 2);
|
nuclear@4
|
107 buf[sz - 1] = buf[sz - 2] = 0;
|
nuclear@4
|
108
|
nuclear@4
|
109 va_start(ap, first);
|
nuclear@4
|
110 while((item = va_arg(ap, char*))) {
|
nuclear@4
|
111 int len = strlen(item);
|
nuclear@4
|
112 char *tmp = realloc(buf, sz + len + 1);
|
nuclear@4
|
113 if(!tmp) {
|
nuclear@4
|
114 free(buf);
|
nuclear@4
|
115 return 0;
|
nuclear@4
|
116 }
|
nuclear@4
|
117 buf = tmp;
|
nuclear@4
|
118
|
nuclear@4
|
119 memcpy(buf + sz - 1, item, len);
|
nuclear@4
|
120 sz += len + 1;
|
nuclear@4
|
121 buf[sz - 1] = buf[sz - 2] = 0;
|
nuclear@4
|
122 }
|
nuclear@4
|
123 va_end(ap);
|
nuclear@4
|
124
|
nuclear@4
|
125 return buf;
|
nuclear@4
|
126 }
|
nuclear@4
|
127
|
nuclear@4
|
128 void imtk_free_list(char *list)
|
nuclear@4
|
129 {
|
nuclear@4
|
130 free(list);
|
nuclear@4
|
131 }
|
nuclear@4
|
132
|
nuclear@3
|
133
|
nuclear@3
|
134 static void draw_progress(int id, float pos, int x, int y)
|
nuclear@3
|
135 {
|
nuclear@3
|
136 int bar_size = SLIDER_SIZE * pos;
|
nuclear@3
|
137
|
nuclear@3
|
138 if(pos < 0.0) pos = 0.0;
|
nuclear@3
|
139 if(pos > 1.0) pos = 1.0;
|
nuclear@3
|
140
|
nuclear@3
|
141 /* through */
|
nuclear@3
|
142 glBegin(GL_QUADS);
|
nuclear@3
|
143 glColor3fv(colors[IMTK_BASE_COLOR]);
|
nuclear@3
|
144 glVertex2f(x - 1, y - 1);
|
nuclear@3
|
145 glVertex2f(x + SLIDER_SIZE + 1, y - 1);
|
nuclear@3
|
146 glVertex2f(x + SLIDER_SIZE + 1, y + 17);
|
nuclear@3
|
147 glVertex2f(x - 1, y + 17);
|
nuclear@3
|
148 glEnd();
|
nuclear@3
|
149 draw_frame(x - 1, y - 1, SLIDER_SIZE + 2, 17, FRAME_INSET);
|
nuclear@3
|
150
|
nuclear@3
|
151 if(pos > 0.0) {
|
nuclear@3
|
152 /* bar */
|
nuclear@3
|
153 glBegin(GL_QUADS);
|
nuclear@3
|
154 glColor3fv(colors[IMTK_BASE_COLOR]);
|
nuclear@3
|
155 glVertex2f(x, y);
|
nuclear@3
|
156 glVertex2f(x + bar_size, y);
|
nuclear@3
|
157 glVertex2f(x + bar_size, y + 15);
|
nuclear@3
|
158 glVertex2f(x, y + 15);
|
nuclear@3
|
159 glEnd();
|
nuclear@3
|
160 draw_frame(x, y, bar_size, 15, FRAME_OUTSET);
|
nuclear@3
|
161 }
|
nuclear@3
|
162 }
|