istereo2
view src/ui.cc @ 35:643f4ab609a4
added readme and license
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 31 Oct 2015 05:45:35 +0200 |
parents | 8f41da60b9f5 |
children |
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 "C" void ad_banner_show(void);
11 extern "C" void ad_banner_hide(void);
12 extern "C" void use_retina_res(int enable);
13 extern "C" int using_retina_res(void);
14 extern "C" int have_retina(void);
16 static void done_bn_handler(Widget *w, const Event &ev, void *cls);
17 static void stereo_cbox_handler(Widget *w, const Event &ev, void *cls);
18 static void bump_cbox_handler(Widget *w, const Event &ev, void *cls);
19 static void split_slider_handler(Widget *w, const Event &ev, void *cls);
20 #ifdef IPHONE
21 static void retina_cbox_handler(Widget *w, const Event &ev, void *cls);
22 #else
23 static void qual_slider_handler(Widget *w, const Event &ev, void *cls);
24 #endif
26 extern int stereo;
27 extern int show_opt;
28 extern int use_bump;
29 extern float split;
30 extern float draw_quality;
32 static Screen scr;
33 static float aspect;
34 static int width, height;
35 static int virt_width, virt_height;
36 static Slider *slider_split;
37 static Label *label_split;
39 extern unsigned int prog_color, prog_ui;
41 int ui_init(void)
42 {
43 float ypos = 280;
44 float vsep = 75;
45 float vsz = 36;
47 CheckBox *cbox;
49 #ifdef IPHONE
50 if(have_retina()) {
51 cbox = new CheckBox;
52 cbox->set_position(300, ypos + vsep);
53 cbox->set_size(300, vsz);
54 cbox->set_text("Retina quality rendering");
55 if(using_retina_res()) {
56 cbox->check();
57 } else {
58 cbox->uncheck();
59 }
60 cbox->set_callback(EV_CHANGE, retina_cbox_handler);
61 scr.add_widget(cbox);
62 }
63 #else
64 /*
65 label_split = new Label;
66 label_split->set_position(100, ypos + vsep);
67 label_split->set_size(20, vsz);
68 label_split->set_text("Rendering quality");
69 scr.add_widget(label_split);
71 Slider *slider = new Slider;
72 slider->set_position(300, ypos + vsep);
73 slider->set_size(300, vsz);
74 slider->set_range(0.5, 1);
75 slider->set_step(0.25);
76 slider->set_value(1.0);
77 slider->set_continuous_change(true);
78 slider->set_callback(EV_CHANGE, qual_slider_handler);
79 scr.add_widget(slider);
80 */
81 #endif
83 cbox = new CheckBox;
84 cbox->set_position(300, ypos);
85 cbox->set_size(300, vsz);
86 cbox->set_text("Stereoscopic rendering");
87 cbox->set_callback(EV_CHANGE, stereo_cbox_handler);
88 scr.add_widget(cbox);
89 ypos -= vsep;
91 label_split = new Label;
92 label_split->set_position(70, ypos);
93 label_split->set_size(20, vsz);
94 label_split->set_text("Stereo split");
95 if(!stereo) label_split->deactivate();
96 scr.add_widget(label_split);
98 slider_split = new Slider;
99 slider_split->set_position(200, ypos);
100 slider_split->set_size(400, vsz);
101 slider_split->set_continuous_change(true);
102 slider_split->set_range(0, 1.0);
103 slider_split->set_value(split);
104 slider_split->set_callback(EV_CHANGE, split_slider_handler);
105 if(!stereo) slider_split->deactivate();
106 scr.add_widget(slider_split);
107 ypos -= vsep;
109 cbox = new CheckBox;
110 cbox->set_position(300, ypos);
111 cbox->set_size(300, vsz);
112 cbox->set_text("Bump mapping");
113 cbox->set_callback(EV_CHANGE, bump_cbox_handler);
114 scr.add_widget(cbox);
115 ypos -= vsep;
117 ypos -= vsep * 0.25;
118 Button *button = new Button;
119 button->set_position(450, ypos);
120 button->set_size(150, vsz);
121 button->set_text("Ok");
122 button->set_callback(EV_CLICK, done_bn_handler);
123 scr.add_widget(button);
124 ypos -= vsep;
126 scr.set_visibility_transition(400);
128 if(!(theme = get_theme("istereo"))) {
129 return -1;
130 }
132 return 0;
133 }
135 void ui_shutdown(void)
136 {
137 }
139 void ui_show()
140 {
141 scr.show();
142 ad_banner_show();
143 }
145 void ui_hide()
146 {
147 scr.hide();
148 ad_banner_hide();
149 }
151 int ui_visible()
152 {
153 return scr.get_visibility() > 0.01;
154 }
156 void ui_reshape(int x, int y)
157 {
158 width = x;
159 height = y;
160 aspect = (float)width / (float)height;
162 virt_width = 500.0 * aspect;
163 virt_height = 500.0;
164 }
166 void ui_draw(void)
167 {
168 bind_program(prog_ui);
170 gl_matrix_mode(GL_PROJECTION);
171 gl_push_matrix();
172 gl_load_identity();
173 gl_ortho(0, virt_width, 0, virt_height, -1, 1);
174 gl_matrix_mode(GL_MODELVIEW);
175 gl_push_matrix();
176 gl_load_identity();
178 glDisable(GL_CULL_FACE);
179 glDisable(GL_DEPTH_TEST);
180 glEnable(GL_BLEND);
181 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
183 set_uniform_float4(prog_ui, "ucolor", 0, 0, 0, 0.5 * scr.get_visibility());
185 gl_begin(GL_QUADS);
186 //gl_color4f(0, 0, 0, 0.5);
187 gl_vertex3f(0, 0, 0);
188 gl_vertex3f(0, virt_height, 0);
189 gl_vertex3f(virt_width, virt_height, 0);
190 gl_vertex3f(virt_width, 0, 0);
191 gl_end();
193 scr.draw();
195 glDisable(GL_BLEND);
196 glEnable(GL_CULL_FACE);
197 glEnable(GL_DEPTH_TEST);
200 gl_matrix_mode(GL_PROJECTION);
201 gl_pop_matrix();
202 gl_matrix_mode(GL_MODELVIEW);
203 gl_pop_matrix();
204 }
206 void ui_button(int bn, int press, int x, int y)
207 {
208 float normx = virt_width * (float)x / (float)width;
209 float normy = virt_height - virt_height * (float)y / (float)height;
211 scr.sysev_mouse_button(bn, press != 0, normx, normy);
212 }
214 void ui_motion(int x, int y)
215 {
216 float normx = virt_width * (float)x / (float)width;
217 float normy = virt_height - virt_height * (float)y / (float)height;
219 scr.sysev_mouse_motion(normx, normy);
220 }
223 static void done_bn_handler(Widget *w, const Event &ev, void *cls)
224 {
225 show_opt = 0;
226 ui_hide();
227 }
229 static void stereo_cbox_handler(Widget *w, const Event &ev, void *cls)
230 {
231 stereo = ((CheckBox*)w)->is_checked() ? 1 : 0;
233 if(stereo) {
234 slider_split->activate();
235 label_split->activate();
236 } else {
237 slider_split->deactivate();
238 label_split->deactivate();
239 }
240 }
242 static void bump_cbox_handler(Widget *w, const Event &ev, void *cls)
243 {
244 use_bump = ((CheckBox*)w)->is_checked() ? 1 : 0;
245 }
247 static void split_slider_handler(Widget *w, const Event &ev, void *cls)
248 {
249 split = ((Slider*)w)->get_value();
250 }
252 #ifdef IPHONE
253 static void retina_cbox_handler(Widget *w, const Event &ev, void *cls)
254 {
255 use_retina_res(((CheckBox*)w)->is_checked() ? 1 : 0);
256 }
257 #else
258 static void qual_slider_handler(Widget *w, const Event &ev, void *cls)
259 {
260 draw_quality = ((Slider*)w)->get_value();
261 }
262 #endif