nuclear@7: #include nuclear@6: #include "ui.h" nuclear@6: #include "goatkit/goatkit.h" nuclear@6: #include "opengl.h" nuclear@9: #include "sanegl.h" nuclear@6: #include "sdr.h" nuclear@6: nuclear@13: using namespace goatkit; nuclear@13: nuclear@16: extern "C" void ad_banner_show(void); nuclear@16: extern "C" void ad_banner_hide(void); nuclear@16: extern "C" void use_retina_res(int enable); nuclear@16: extern "C" int using_retina_res(void); nuclear@16: extern "C" int have_retina(void); nuclear@13: nuclear@15: static void done_bn_handler(Widget *w, const Event &ev, void *cls); nuclear@15: static void stereo_cbox_handler(Widget *w, const Event &ev, void *cls); nuclear@15: static void bump_cbox_handler(Widget *w, const Event &ev, void *cls); nuclear@15: static void split_slider_handler(Widget *w, const Event &ev, void *cls); nuclear@16: #ifdef IPHONE nuclear@16: static void retina_cbox_handler(Widget *w, const Event &ev, void *cls); nuclear@16: #endif nuclear@16: nuclear@16: extern int stereo; nuclear@16: extern int show_opt; nuclear@16: extern int use_bump; nuclear@16: extern float split; nuclear@15: nuclear@15: static Screen scr; nuclear@13: static float aspect; nuclear@6: static int width, height; nuclear@14: static int virt_width, virt_height; nuclear@15: static Slider *slider_split; nuclear@15: static Label *label_split; nuclear@6: nuclear@6: extern unsigned int prog_color, prog_ui; nuclear@6: nuclear@6: int ui_init(void) nuclear@6: { nuclear@16: float ypos = 280; nuclear@16: float vsep = 75; nuclear@16: float vsz = 36; nuclear@6: nuclear@16: CheckBox *cbox; nuclear@16: nuclear@21: #ifdef IPHONE nuclear@21: if(have_retina()) { nuclear@16: cbox = new CheckBox; nuclear@16: cbox->set_position(300, ypos + vsep); nuclear@16: cbox->set_size(300, vsz); nuclear@16: cbox->set_text("Retina quality rendering"); nuclear@21: if(using_retina_res()) { nuclear@16: cbox->check(); nuclear@21: } else { nuclear@21: cbox->uncheck(); nuclear@21: } nuclear@21: cbox->set_callback(EV_CHANGE, retina_cbox_handler); nuclear@16: scr.add_widget(cbox); nuclear@21: } nuclear@21: #endif nuclear@16: nuclear@16: cbox = new CheckBox; nuclear@15: cbox->set_position(300, ypos); nuclear@15: cbox->set_size(300, vsz); nuclear@15: cbox->set_text("Stereoscopic rendering"); nuclear@15: cbox->set_callback(EV_CHANGE, stereo_cbox_handler); nuclear@15: scr.add_widget(cbox); nuclear@15: ypos -= vsep; nuclear@13: nuclear@15: label_split = new Label; nuclear@18: label_split->set_position(70, ypos); nuclear@15: label_split->set_size(20, vsz); nuclear@15: label_split->set_text("Stereo split"); nuclear@15: if(!stereo) label_split->deactivate(); nuclear@15: scr.add_widget(label_split); nuclear@15: nuclear@15: slider_split = new Slider; nuclear@18: slider_split->set_position(200, ypos); nuclear@18: slider_split->set_size(400, vsz); nuclear@15: slider_split->set_continuous_change(true); nuclear@15: slider_split->set_range(0, 1.0); nuclear@15: slider_split->set_value(split); nuclear@18: slider_split->set_callback(EV_CHANGE, split_slider_handler); nuclear@15: if(!stereo) slider_split->deactivate(); nuclear@15: scr.add_widget(slider_split); nuclear@15: ypos -= vsep; nuclear@15: nuclear@15: cbox = new CheckBox; nuclear@15: cbox->set_position(300, ypos); nuclear@15: cbox->set_size(300, vsz); nuclear@15: cbox->set_text("Bump mapping"); nuclear@15: cbox->set_callback(EV_CHANGE, bump_cbox_handler); nuclear@15: scr.add_widget(cbox); nuclear@15: ypos -= vsep; nuclear@15: nuclear@16: ypos -= vsep * 0.25; nuclear@15: Button *button = new Button; nuclear@15: button->set_position(450, ypos); nuclear@15: button->set_size(150, vsz); nuclear@16: button->set_text("Ok"); nuclear@15: button->set_callback(EV_CLICK, done_bn_handler); nuclear@13: scr.add_widget(button); nuclear@15: ypos -= vsep; nuclear@6: nuclear@15: scr.set_visibility_transition(400); nuclear@6: nuclear@15: if(!(theme = get_theme("istereo"))) { nuclear@7: return -1; nuclear@7: } nuclear@6: nuclear@6: return 0; nuclear@6: } nuclear@6: nuclear@6: void ui_shutdown(void) nuclear@6: { nuclear@6: } nuclear@6: nuclear@15: void ui_show() nuclear@15: { nuclear@15: scr.show(); nuclear@16: ad_banner_show(); nuclear@15: } nuclear@15: nuclear@15: void ui_hide() nuclear@15: { nuclear@15: scr.hide(); nuclear@16: ad_banner_hide(); nuclear@15: } nuclear@15: nuclear@15: int ui_visible() nuclear@15: { nuclear@15: return scr.get_visibility() > 0.01; nuclear@15: } nuclear@15: nuclear@6: void ui_reshape(int x, int y) nuclear@6: { nuclear@6: width = x; nuclear@6: height = y; nuclear@13: aspect = (float)width / (float)height; nuclear@14: nuclear@14: virt_width = 500.0 * aspect; nuclear@14: virt_height = 500.0; nuclear@6: } nuclear@6: nuclear@6: void ui_draw(void) nuclear@6: { nuclear@6: bind_program(prog_ui); nuclear@6: nuclear@6: gl_matrix_mode(GL_PROJECTION); nuclear@6: gl_push_matrix(); nuclear@6: gl_load_identity(); nuclear@14: gl_ortho(0, virt_width, 0, virt_height, -1, 1); nuclear@6: gl_matrix_mode(GL_MODELVIEW); nuclear@6: gl_push_matrix(); nuclear@6: gl_load_identity(); nuclear@6: nuclear@6: glDisable(GL_CULL_FACE); nuclear@6: glDisable(GL_DEPTH_TEST); nuclear@7: glEnable(GL_BLEND); nuclear@7: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); nuclear@6: nuclear@15: set_uniform_float4(prog_ui, "ucolor", 0, 0, 0, 0.5 * scr.get_visibility()); nuclear@7: nuclear@7: gl_begin(GL_QUADS); nuclear@7: //gl_color4f(0, 0, 0, 0.5); nuclear@6: gl_vertex3f(0, 0, 0); nuclear@14: gl_vertex3f(0, virt_height, 0); nuclear@14: gl_vertex3f(virt_width, virt_height, 0); nuclear@14: gl_vertex3f(virt_width, 0, 0); nuclear@6: gl_end(); nuclear@6: nuclear@6: scr.draw(); nuclear@6: nuclear@7: glDisable(GL_BLEND); nuclear@6: glEnable(GL_CULL_FACE); nuclear@6: glEnable(GL_DEPTH_TEST); nuclear@6: nuclear@6: nuclear@6: gl_matrix_mode(GL_PROJECTION); nuclear@6: gl_pop_matrix(); nuclear@6: gl_matrix_mode(GL_MODELVIEW); nuclear@6: gl_pop_matrix(); nuclear@6: } nuclear@6: nuclear@6: void ui_button(int bn, int press, int x, int y) nuclear@6: { nuclear@14: float normx = virt_width * (float)x / (float)width; nuclear@14: float normy = virt_height - virt_height * (float)y / (float)height; nuclear@13: nuclear@13: scr.sysev_mouse_button(bn, press != 0, normx, normy); nuclear@6: } nuclear@6: nuclear@6: void ui_motion(int x, int y) nuclear@6: { nuclear@14: float normx = virt_width * (float)x / (float)width; nuclear@14: float normy = virt_height - virt_height * (float)y / (float)height; nuclear@13: nuclear@13: scr.sysev_mouse_motion(normx, normy); nuclear@9: } nuclear@15: nuclear@15: nuclear@15: static void done_bn_handler(Widget *w, const Event &ev, void *cls) nuclear@15: { nuclear@15: show_opt = 0; nuclear@15: ui_hide(); nuclear@15: } nuclear@15: nuclear@15: static void stereo_cbox_handler(Widget *w, const Event &ev, void *cls) nuclear@15: { nuclear@15: stereo = ((CheckBox*)w)->is_checked() ? 1 : 0; nuclear@15: nuclear@15: if(stereo) { nuclear@15: slider_split->activate(); nuclear@15: label_split->activate(); nuclear@15: } else { nuclear@15: slider_split->deactivate(); nuclear@15: label_split->deactivate(); nuclear@15: } nuclear@15: } nuclear@15: nuclear@15: static void bump_cbox_handler(Widget *w, const Event &ev, void *cls) nuclear@15: { nuclear@15: use_bump = ((CheckBox*)w)->is_checked() ? 1 : 0; nuclear@15: } nuclear@15: nuclear@15: static void split_slider_handler(Widget *w, const Event &ev, void *cls) nuclear@15: { nuclear@15: split = ((Slider*)w)->get_value(); nuclear@15: } nuclear@15: nuclear@16: #ifdef IPHONE nuclear@16: static void retina_cbox_handler(Widget *w, const Event &ev, void *cls) nuclear@16: { nuclear@16: use_retina_res(((CheckBox*)w)->is_checked() ? 1 : 0); nuclear@16: } nuclear@16: #endif nuclear@16: