imtk

view src/imtk.c @ 7:6d35e6c7b2ca

reorganization finished
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 14 Apr 2011 23:04:07 +0300
parents 09b6e8a5dc14
children 9c7987064bb0
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <ctype.h>
5 #include <stdarg.h>
6 #include <assert.h>
7 #ifndef __APPLE__
8 #include <GL/glut.h>
9 #else
10 #include <GLUT/glut.h>
11 #endif
12 #include "imtk.h"
13 #include "state.h"
16 void imtk_begin(void)
17 {
18 int width, height;
20 imtk_get_viewport(&width, &height);
22 glMatrixMode(GL_PROJECTION);
23 glPushMatrix();
24 glLoadIdentity();
25 glTranslatef(-1, 1, 0);
26 glScalef(2.0 / width, -2.0 / height, 1.0);
28 glMatrixMode(GL_MODELVIEW);
29 glPushMatrix();
30 glLoadIdentity();
32 glPushAttrib(GL_ENABLE_BIT);
33 glDisable(GL_DEPTH_TEST);
34 glDisable(GL_CULL_FACE);
35 glDisable(GL_LIGHTING);
36 }
38 void imtk_end(void)
39 {
40 glPopAttrib();
42 glMatrixMode(GL_PROJECTION);
43 glPopMatrix();
44 glMatrixMode(GL_MODELVIEW);
45 glPopMatrix();
46 }
49 void imtk_post_redisplay(void)
50 {
51 glutPostRedisplay();
52 }
55 /*int imtk_listbox(int id, const char *list, int sel, int x, int y)
56 {
57 int i;
58 assert(id >= 0);
60 if(!list) {
61 return -1;
62 }
64 if(id & 1) {
65 id++;
66 }
68 for(i=0; *list; i++) {
69 if(imtk_button(id + i * 2 + 1, list, x, y + i * 20)) {
70 sel = i;
71 }
72 list += strlen(list) + 1;
73 }
74 return sel;
75 }
77 int imtk_combobox(int id, char *textbuf, size_t buf_sz, const char *list, int sel, int x, int y)
78 {
79 imtk_textbox(id + 1, textbuf, buf_sz, x, y);
80 imtk_button(id + 3, "V", x + TEXTBOX_SIZE, y);
82 if(prev_active == id + 3) {
83 sel = imtk_listbox(id + 5, list, sel, x, y + 20);
84 }
85 return sel;
86 }
88 char *imtk_create_list(const char *first, ...)
89 {
90 int sz;
91 char *buf, *item;
92 va_list ap;
94 if(!first) {
95 return 0;
96 }
98 sz = strlen(first) + 2;
99 if(!(buf = malloc(sz))) {
100 return 0;
101 }
102 memcpy(buf, first, sz - 2);
103 buf[sz - 1] = buf[sz - 2] = 0;
105 va_start(ap, first);
106 while((item = va_arg(ap, char*))) {
107 int len = strlen(item);
108 char *tmp = realloc(buf, sz + len + 1);
109 if(!tmp) {
110 free(buf);
111 return 0;
112 }
113 buf = tmp;
115 memcpy(buf + sz - 1, item, len);
116 sz += len + 1;
117 buf[sz - 1] = buf[sz - 2] = 0;
118 }
119 va_end(ap);
121 return buf;
122 }
124 void imtk_free_list(char *list)
125 {
126 free(list);
127 }*/