istereo2

view src/ui.cc @ 20:2b85d05df3f2

animation controls for easier screenshot grabbing
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 02 Oct 2015 04:54:55 +0300
parents 25d821ab1ca2
children 8f41da60b9f5
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 #endif
24 extern int stereo;
25 extern int show_opt;
26 extern int use_bump;
27 extern float split;
29 static Screen scr;
30 static float aspect;
31 static int width, height;
32 static int virt_width, virt_height;
33 static Slider *slider_split;
34 static Label *label_split;
36 extern unsigned int prog_color, prog_ui;
38 int ui_init(void)
39 {
40 float ypos = 280;
41 float vsep = 75;
42 float vsz = 36;
44 CheckBox *cbox;
46 //#ifdef IPHONE
47 // if(have_retina()) {
48 cbox = new CheckBox;
49 cbox->set_position(300, ypos + vsep);
50 cbox->set_size(300, vsz);
51 cbox->set_text("Retina quality rendering");
52 //if(using_retina_res()) {
53 cbox->check();
54 //} else {
55 // cbox->uncheck();
56 //}
57 // cbox->set_callback(EV_CHANGE, retina_cbox_handler);
58 scr.add_widget(cbox);
59 // }
60 //#endif
62 cbox = new CheckBox;
63 cbox->set_position(300, ypos);
64 cbox->set_size(300, vsz);
65 cbox->set_text("Stereoscopic rendering");
66 cbox->set_callback(EV_CHANGE, stereo_cbox_handler);
67 scr.add_widget(cbox);
68 ypos -= vsep;
70 label_split = new Label;
71 label_split->set_position(70, ypos);
72 label_split->set_size(20, vsz);
73 label_split->set_text("Stereo split");
74 if(!stereo) label_split->deactivate();
75 scr.add_widget(label_split);
77 slider_split = new Slider;
78 slider_split->set_position(200, ypos);
79 slider_split->set_size(400, vsz);
80 slider_split->set_continuous_change(true);
81 slider_split->set_range(0, 1.0);
82 slider_split->set_value(split);
83 slider_split->set_callback(EV_CHANGE, split_slider_handler);
84 if(!stereo) slider_split->deactivate();
85 scr.add_widget(slider_split);
86 ypos -= vsep;
88 cbox = new CheckBox;
89 cbox->set_position(300, ypos);
90 cbox->set_size(300, vsz);
91 cbox->set_text("Bump mapping");
92 cbox->set_callback(EV_CHANGE, bump_cbox_handler);
93 scr.add_widget(cbox);
94 ypos -= vsep;
96 ypos -= vsep * 0.25;
97 Button *button = new Button;
98 button->set_position(450, ypos);
99 button->set_size(150, vsz);
100 button->set_text("Ok");
101 button->set_callback(EV_CLICK, done_bn_handler);
102 scr.add_widget(button);
103 ypos -= vsep;
105 scr.set_visibility_transition(400);
107 if(!(theme = get_theme("istereo"))) {
108 return -1;
109 }
111 return 0;
112 }
114 void ui_shutdown(void)
115 {
116 }
118 void ui_show()
119 {
120 scr.show();
121 ad_banner_show();
122 }
124 void ui_hide()
125 {
126 scr.hide();
127 ad_banner_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 }
231 #ifdef IPHONE
232 static void retina_cbox_handler(Widget *w, const Event &ev, void *cls)
233 {
234 use_retina_res(((CheckBox*)w)->is_checked() ? 1 : 0);
235 }
236 #endif