istereo2
diff src/ui.cc @ 6:3bccfc7d10fe
goatkit is drawing
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 23 Sep 2015 05:44:58 +0300 |
parents | |
children | a3c4fcc9f8f3 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/ui.cc Wed Sep 23 05:44:58 2015 +0300 1.3 @@ -0,0 +1,131 @@ 1.4 +#include "ui.h" 1.5 +#include "goatkit/goatkit.h" 1.6 +#include "opengl.h" 1.7 +#include "sdr.h" 1.8 + 1.9 +static goatkit::Screen scr; 1.10 +static int width, height; 1.11 + 1.12 +extern unsigned int prog_color, prog_ui; 1.13 + 1.14 +int ui_init(void) 1.15 +{ 1.16 + float ypos = 0; 1.17 + float vsep = 0.1; 1.18 + 1.19 + goatkit::Label *label = new goatkit::Label; 1.20 + label->set_position(0.5, ypos += vsep); 1.21 + label->set_size(0.1, 0.1); 1.22 + label->set_text("Stereoscopic rendering"); 1.23 + scr.add_widget(label); 1.24 + 1.25 + /* 1.26 + goatkit::Button *button = new goatkit::Button; 1.27 + button->set_position(300, ypos += vsep); 1.28 + button->set_size(200, 40); 1.29 + button->set_text("a button!"); 1.30 + button->set_callback(goatkit::EV_CLICK, callback); 1.31 + scr.add_widget(button); 1.32 + 1.33 + goatkit::TextBox *text = new goatkit::TextBox; 1.34 + text->set_position(300, ypos += vsep); 1.35 + text->set_size(200, 30); 1.36 + text->set_text("foo"); 1.37 + text->set_callback(goatkit::EV_CHANGE, callback); 1.38 + scr.add_widget(text); 1.39 + 1.40 + goatkit::CheckBox *cbox = new goatkit::CheckBox; 1.41 + cbox->set_position(300, ypos += vsep); 1.42 + cbox->set_size(200, 20); 1.43 + cbox->set_text("a checkbox!"); 1.44 + cbox->set_callback(goatkit::EV_CHANGE, callback); 1.45 + scr.add_widget(cbox); 1.46 + 1.47 + goatkit::Slider *slider = new goatkit::Slider; 1.48 + slider->set_position(300, ypos += vsep); 1.49 + slider->set_size(200, 40); 1.50 + slider->set_callback(goatkit::EV_CHANGE, callback); 1.51 + slider->set_continuous_change(false); 1.52 + slider->set_range(0, 100.0); 1.53 + scr.add_widget(slider); 1.54 + 1.55 + goatkit::Slider *intslider = new goatkit::Slider; 1.56 + intslider->set_position(300, ypos += vsep); 1.57 + intslider->set_size(200, 40); 1.58 + intslider->set_callback(goatkit::EV_CHANGE, callback); 1.59 + intslider->set_continuous_change(false); 1.60 + intslider->set_range(0, 100.0); 1.61 + intslider->set_step(10); 1.62 + scr.add_widget(intslider); 1.63 + */ 1.64 + 1.65 + scr.show(); 1.66 + 1.67 + // load the theme 1.68 + //goatkit::add_theme_path("themes/simple"); 1.69 + 1.70 + //goatkit::theme = new goatkit::Theme; 1.71 + //goatkit::theme->load("simple"); 1.72 + 1.73 + return 0; 1.74 +} 1.75 + 1.76 +void ui_shutdown(void) 1.77 +{ 1.78 +} 1.79 + 1.80 +void ui_reshape(int x, int y) 1.81 +{ 1.82 + width = x; 1.83 + height = y; 1.84 +} 1.85 + 1.86 +void ui_draw(void) 1.87 +{ 1.88 + float aspect = (float)width / (float)height; 1.89 + 1.90 + bind_program(prog_ui); 1.91 + 1.92 + gl_matrix_mode(GL_PROJECTION); 1.93 + gl_push_matrix(); 1.94 + gl_load_identity(); 1.95 + gl_scalef(2.0 / aspect, 2.0, 1); 1.96 + gl_translatef(-1, -1, 0); 1.97 + gl_scalef(1, -1, 1); 1.98 + gl_matrix_mode(GL_MODELVIEW); 1.99 + gl_push_matrix(); 1.100 + gl_load_identity(); 1.101 + 1.102 + glDisable(GL_CULL_FACE); 1.103 + glDisable(GL_DEPTH_TEST); 1.104 + 1.105 + /*gl_begin(GL_QUADS); 1.106 + gl_color3f(1, 0, 0); 1.107 + gl_vertex3f(0, 0, 0); 1.108 + gl_vertex3f(0, 0.5, 0); 1.109 + gl_vertex3f(0.5 * aspect, 0.5, 0); 1.110 + gl_vertex3f(0.5 * aspect, 0, 0); 1.111 + gl_end(); 1.112 + */ 1.113 + 1.114 + scr.draw(); 1.115 + 1.116 + glEnable(GL_CULL_FACE); 1.117 + glEnable(GL_DEPTH_TEST); 1.118 + 1.119 + 1.120 + gl_matrix_mode(GL_PROJECTION); 1.121 + gl_pop_matrix(); 1.122 + gl_matrix_mode(GL_MODELVIEW); 1.123 + gl_pop_matrix(); 1.124 +} 1.125 + 1.126 +void ui_button(int bn, int press, int x, int y) 1.127 +{ 1.128 + scr.sysev_mouse_button(bn, press != 0, (float)x / (float)width, 1.0 - (float)y / (float)height); 1.129 +} 1.130 + 1.131 +void ui_motion(int x, int y) 1.132 +{ 1.133 + scr.sysev_mouse_motion((float)x / (float)width, 1.0 - (float)y / (float)height); 1.134 +} 1.135 \ No newline at end of file