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@7
|
13 #include "state.h"
|
nuclear@1
|
14
|
nuclear@0
|
15
|
nuclear@0
|
16 void imtk_begin(void)
|
nuclear@0
|
17 {
|
nuclear@7
|
18 int width, height;
|
nuclear@7
|
19
|
nuclear@7
|
20 imtk_get_viewport(&width, &height);
|
nuclear@7
|
21
|
nuclear@0
|
22 glMatrixMode(GL_PROJECTION);
|
nuclear@0
|
23 glPushMatrix();
|
nuclear@0
|
24 glLoadIdentity();
|
nuclear@0
|
25 glTranslatef(-1, 1, 0);
|
nuclear@7
|
26 glScalef(2.0 / width, -2.0 / height, 1.0);
|
nuclear@2
|
27
|
nuclear@2
|
28 glMatrixMode(GL_MODELVIEW);
|
nuclear@2
|
29 glPushMatrix();
|
nuclear@2
|
30 glLoadIdentity();
|
nuclear@2
|
31
|
nuclear@2
|
32 glPushAttrib(GL_ENABLE_BIT);
|
nuclear@2
|
33 glDisable(GL_DEPTH_TEST);
|
nuclear@2
|
34 glDisable(GL_CULL_FACE);
|
nuclear@2
|
35 glDisable(GL_LIGHTING);
|
nuclear@0
|
36 }
|
nuclear@0
|
37
|
nuclear@0
|
38 void imtk_end(void)
|
nuclear@0
|
39 {
|
nuclear@2
|
40 glPopAttrib();
|
nuclear@2
|
41
|
nuclear@0
|
42 glMatrixMode(GL_PROJECTION);
|
nuclear@0
|
43 glPopMatrix();
|
nuclear@2
|
44 glMatrixMode(GL_MODELVIEW);
|
nuclear@2
|
45 glPopMatrix();
|
nuclear@0
|
46 }
|
nuclear@0
|
47
|
nuclear@5
|
48
|
nuclear@5
|
49 void imtk_post_redisplay(void)
|
nuclear@0
|
50 {
|
nuclear@5
|
51 glutPostRedisplay();
|
nuclear@0
|
52 }
|
nuclear@0
|
53
|
nuclear@1
|
54
|
nuclear@7
|
55 /*int imtk_listbox(int id, const char *list, int sel, int x, int y)
|
nuclear@4
|
56 {
|
nuclear@4
|
57 int i;
|
nuclear@4
|
58 assert(id >= 0);
|
nuclear@4
|
59
|
nuclear@4
|
60 if(!list) {
|
nuclear@4
|
61 return -1;
|
nuclear@4
|
62 }
|
nuclear@4
|
63
|
nuclear@4
|
64 if(id & 1) {
|
nuclear@4
|
65 id++;
|
nuclear@4
|
66 }
|
nuclear@4
|
67
|
nuclear@4
|
68 for(i=0; *list; i++) {
|
nuclear@4
|
69 if(imtk_button(id + i * 2 + 1, list, x, y + i * 20)) {
|
nuclear@4
|
70 sel = i;
|
nuclear@4
|
71 }
|
nuclear@4
|
72 list += strlen(list) + 1;
|
nuclear@4
|
73 }
|
nuclear@4
|
74 return sel;
|
nuclear@4
|
75 }
|
nuclear@4
|
76
|
nuclear@4
|
77 int imtk_combobox(int id, char *textbuf, size_t buf_sz, const char *list, int sel, int x, int y)
|
nuclear@4
|
78 {
|
nuclear@4
|
79 imtk_textbox(id + 1, textbuf, buf_sz, x, y);
|
nuclear@4
|
80 imtk_button(id + 3, "V", x + TEXTBOX_SIZE, y);
|
nuclear@4
|
81
|
nuclear@4
|
82 if(prev_active == id + 3) {
|
nuclear@4
|
83 sel = imtk_listbox(id + 5, list, sel, x, y + 20);
|
nuclear@4
|
84 }
|
nuclear@4
|
85 return sel;
|
nuclear@4
|
86 }
|
nuclear@4
|
87
|
nuclear@4
|
88 char *imtk_create_list(const char *first, ...)
|
nuclear@4
|
89 {
|
nuclear@4
|
90 int sz;
|
nuclear@4
|
91 char *buf, *item;
|
nuclear@4
|
92 va_list ap;
|
nuclear@4
|
93
|
nuclear@4
|
94 if(!first) {
|
nuclear@4
|
95 return 0;
|
nuclear@4
|
96 }
|
nuclear@4
|
97
|
nuclear@4
|
98 sz = strlen(first) + 2;
|
nuclear@4
|
99 if(!(buf = malloc(sz))) {
|
nuclear@4
|
100 return 0;
|
nuclear@4
|
101 }
|
nuclear@4
|
102 memcpy(buf, first, sz - 2);
|
nuclear@4
|
103 buf[sz - 1] = buf[sz - 2] = 0;
|
nuclear@4
|
104
|
nuclear@4
|
105 va_start(ap, first);
|
nuclear@4
|
106 while((item = va_arg(ap, char*))) {
|
nuclear@4
|
107 int len = strlen(item);
|
nuclear@4
|
108 char *tmp = realloc(buf, sz + len + 1);
|
nuclear@4
|
109 if(!tmp) {
|
nuclear@4
|
110 free(buf);
|
nuclear@4
|
111 return 0;
|
nuclear@4
|
112 }
|
nuclear@4
|
113 buf = tmp;
|
nuclear@4
|
114
|
nuclear@4
|
115 memcpy(buf + sz - 1, item, len);
|
nuclear@4
|
116 sz += len + 1;
|
nuclear@4
|
117 buf[sz - 1] = buf[sz - 2] = 0;
|
nuclear@4
|
118 }
|
nuclear@4
|
119 va_end(ap);
|
nuclear@4
|
120
|
nuclear@4
|
121 return buf;
|
nuclear@4
|
122 }
|
nuclear@4
|
123
|
nuclear@4
|
124 void imtk_free_list(char *list)
|
nuclear@4
|
125 {
|
nuclear@4
|
126 free(list);
|
nuclear@7
|
127 }*/
|