istereo2
view src/ui.cc @ 15:7bd4264bf74a
gui done?
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 30 Sep 2015 04:41:21 +0300 |
parents | 018f997dc646 |
children | 1b7776cb800b |
line source
1 #include <stdio.h>
2 #include "ui.h"
3 #include "goatkit/goatkit.h"
4 #include "opengl.h"
5 #include "sanegl.h"
6 #include "sdr.h"
8 using namespace goatkit;
10 extern int stereo;
11 extern int show_opt;
12 extern int use_bump;
13 extern float split;
15 static void done_bn_handler(Widget *w, const Event &ev, void *cls);
16 static void stereo_cbox_handler(Widget *w, const Event &ev, void *cls);
17 static void bump_cbox_handler(Widget *w, const Event &ev, void *cls);
18 static void split_slider_handler(Widget *w, const Event &ev, void *cls);
20 static Screen scr;
21 static float aspect;
22 static int width, height;
23 static int virt_width, virt_height;
24 static Slider *slider_split;
25 static Label *label_split;
27 extern unsigned int prog_color, prog_ui;
29 int ui_init(void)
30 {
31 float ypos = 300;
32 float vsep = 70;
33 float vsz = 35;
35 CheckBox *cbox = new CheckBox;
36 cbox->set_position(300, ypos);
37 cbox->set_size(300, vsz);
38 cbox->set_text("Stereoscopic rendering");
39 cbox->set_callback(EV_CHANGE, stereo_cbox_handler);
40 //cbox->set_toggle_transition(80);
41 scr.add_widget(cbox);
42 ypos -= vsep;
44 label_split = new Label;
45 label_split->set_position(170, ypos);
46 label_split->set_size(20, vsz);
47 label_split->set_text("Stereo split");
48 if(!stereo) label_split->deactivate();
49 scr.add_widget(label_split);
51 slider_split = new Slider;
52 slider_split->set_position(300, ypos);
53 slider_split->set_size(300, vsz);
54 slider_split->set_callback(EV_CHANGE, split_slider_handler);
55 slider_split->set_continuous_change(true);
56 slider_split->set_range(0, 1.0);
57 slider_split->set_value(split);
58 if(!stereo) slider_split->deactivate();
59 scr.add_widget(slider_split);
60 ypos -= vsep;
62 cbox = new CheckBox;
63 cbox->set_position(300, ypos);
64 cbox->set_size(300, vsz);
65 cbox->set_text("Bump mapping");
66 cbox->set_callback(EV_CHANGE, bump_cbox_handler);
67 scr.add_widget(cbox);
68 ypos -= vsep;
70 ypos -= vsep * 0.5;
71 Button *button = new Button;
72 button->set_position(450, ypos);
73 button->set_size(150, vsz);
74 button->set_text("Done");
75 button->set_callback(EV_CLICK, done_bn_handler);
76 scr.add_widget(button);
77 ypos -= vsep;
79 /*
80 TextBox *text = new TextBox;
81 text->set_position(300, ypos += vsep);
82 text->set_size(200, 30);
83 text->set_text("foo");
84 text->set_callback(EV_CHANGE, callback);
85 scr.add_widget(text);
87 CheckBox *cbox = new CheckBox;
88 cbox->set_position(300, ypos += vsep);
89 cbox->set_size(200, 20);
90 cbox->set_text("a checkbox!");
91 cbox->set_callback(EV_CHANGE, callback);
92 scr.add_widget(cbox);
94 Slider *intslider = new Slider;
95 intslider->set_position(300, ypos += vsep);
96 intslider->set_size(200, 40);
97 intslider->set_callback(EV_CHANGE, callback);
98 intslider->set_continuous_change(false);
99 intslider->set_range(0, 100.0);
100 intslider->set_step(10);
101 scr.add_widget(intslider);
102 */
104 scr.set_visibility_transition(400);
106 // load the theme
107 //add_theme_path("themes/simple");
109 if(!(theme = get_theme("istereo"))) {
110 return -1;
111 }
113 return 0;
114 }
116 void ui_shutdown(void)
117 {
118 }
120 void ui_show()
121 {
122 scr.show();
123 }
125 void ui_hide()
126 {
127 scr.hide();
128 }
130 int ui_visible()
131 {
132 return scr.get_visibility() > 0.01;
133 }
135 void ui_reshape(int x, int y)
136 {
137 width = x;
138 height = y;
139 aspect = (float)width / (float)height;
141 virt_width = 500.0 * aspect;
142 virt_height = 500.0;
143 }
145 void ui_draw(void)
146 {
147 bind_program(prog_ui);
149 gl_matrix_mode(GL_PROJECTION);
150 gl_push_matrix();
151 gl_load_identity();
152 gl_ortho(0, virt_width, 0, virt_height, -1, 1);
153 gl_matrix_mode(GL_MODELVIEW);
154 gl_push_matrix();
155 gl_load_identity();
157 glDisable(GL_CULL_FACE);
158 glDisable(GL_DEPTH_TEST);
159 glEnable(GL_BLEND);
160 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
162 set_uniform_float4(prog_ui, "ucolor", 0, 0, 0, 0.5 * scr.get_visibility());
164 gl_begin(GL_QUADS);
165 //gl_color4f(0, 0, 0, 0.5);
166 gl_vertex3f(0, 0, 0);
167 gl_vertex3f(0, virt_height, 0);
168 gl_vertex3f(virt_width, virt_height, 0);
169 gl_vertex3f(virt_width, 0, 0);
170 gl_end();
172 scr.draw();
174 glDisable(GL_BLEND);
175 glEnable(GL_CULL_FACE);
176 glEnable(GL_DEPTH_TEST);
179 gl_matrix_mode(GL_PROJECTION);
180 gl_pop_matrix();
181 gl_matrix_mode(GL_MODELVIEW);
182 gl_pop_matrix();
183 }
185 void ui_button(int bn, int press, int x, int y)
186 {
187 float normx = virt_width * (float)x / (float)width;
188 float normy = virt_height - virt_height * (float)y / (float)height;
190 scr.sysev_mouse_button(bn, press != 0, normx, normy);
191 }
193 void ui_motion(int x, int y)
194 {
195 float normx = virt_width * (float)x / (float)width;
196 float normy = virt_height - virt_height * (float)y / (float)height;
198 scr.sysev_mouse_motion(normx, normy);
199 }
202 static void done_bn_handler(Widget *w, const Event &ev, void *cls)
203 {
204 show_opt = 0;
205 ui_hide();
206 }
208 static void stereo_cbox_handler(Widget *w, const Event &ev, void *cls)
209 {
210 stereo = ((CheckBox*)w)->is_checked() ? 1 : 0;
212 if(stereo) {
213 slider_split->activate();
214 label_split->activate();
215 } else {
216 slider_split->deactivate();
217 label_split->deactivate();
218 }
219 }
221 static void bump_cbox_handler(Widget *w, const Event &ev, void *cls)
222 {
223 use_bump = ((CheckBox*)w)->is_checked() ? 1 : 0;
224 }
226 static void split_slider_handler(Widget *w, const Event &ev, void *cls)
227 {
228 split = ((Slider*)w)->get_value();
229 }