istereo2

annotate src/ui.cc @ 28:74b50b538858

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