istereo2

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