istereo2
changeset 13:ea928c313344
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 28 Sep 2015 19:04:50 +0300 |
parents | 57188f7d9304 |
children | 018f997dc646 |
files | src/istereo.c src/ui.cc src/uitheme.cc |
diffstat | 3 files changed, 72 insertions(+), 18 deletions(-) [+] |
line diff
1.1 --- a/src/istereo.c Mon Sep 28 06:53:31 2015 +0300 1.2 +++ b/src/istereo.c Mon Sep 28 19:04:50 2015 +0300 1.3 @@ -47,6 +47,7 @@ 1.4 struct dtx_font *font; 1.5 1.6 int view_xsz, view_ysz; 1.7 +float view_aspect; 1.8 1.9 int stereo = 0; 1.10 int use_bump = 0; 1.11 @@ -408,6 +409,7 @@ 1.12 1.13 view_xsz = x; 1.14 view_ysz = y; 1.15 + view_aspect = aspect; 1.16 1.17 ui_reshape(x, y); 1.18 }
2.1 --- a/src/ui.cc Mon Sep 28 06:53:31 2015 +0300 2.2 +++ b/src/ui.cc Mon Sep 28 19:04:50 2015 +0300 2.3 @@ -5,30 +5,39 @@ 2.4 #include "sanegl.h" 2.5 #include "sdr.h" 2.6 2.7 +using namespace goatkit; 2.8 + 2.9 +static void done_bn_handler(Widget *w, const Event &ev, void *cls) 2.10 +{ 2.11 + printf("done\n"); 2.12 +} 2.13 + 2.14 static goatkit::Screen scr; 2.15 +static float aspect; 2.16 static int width, height; 2.17 2.18 extern unsigned int prog_color, prog_ui; 2.19 2.20 int ui_init(void) 2.21 { 2.22 - float ypos = 0; 2.23 + float xpos = 0.25; 2.24 + float ypos = 0.8; 2.25 float vsep = 0.1; 2.26 2.27 - goatkit::Label *label = new goatkit::Label; 2.28 - label->set_position(0.5, ypos += vsep); 2.29 + /*goatkit::Label *label = new goatkit::Label; 2.30 + label->set_position(xpos, ypos); 2.31 label->set_size(0.1, 0.1); 2.32 label->set_text("Stereoscopic rendering"); 2.33 - scr.add_widget(label); 2.34 + scr.add_widget(label);*/ 2.35 + 2.36 + goatkit::Button *button = new goatkit::Button; 2.37 + button->set_position(xpos, ypos); 2.38 + button->set_size(0.2, 0.1); 2.39 + button->set_text("Done"); 2.40 + button->set_callback(goatkit::EV_CLICK, done_bn_handler); 2.41 + scr.add_widget(button); 2.42 2.43 /* 2.44 - goatkit::Button *button = new goatkit::Button; 2.45 - button->set_position(300, ypos += vsep); 2.46 - button->set_size(200, 40); 2.47 - button->set_text("a button!"); 2.48 - button->set_callback(goatkit::EV_CLICK, callback); 2.49 - scr.add_widget(button); 2.50 - 2.51 goatkit::TextBox *text = new goatkit::TextBox; 2.52 text->set_position(300, ypos += vsep); 2.53 text->set_size(200, 30); 2.54 @@ -81,12 +90,11 @@ 2.55 { 2.56 width = x; 2.57 height = y; 2.58 + aspect = (float)width / (float)height; 2.59 } 2.60 2.61 void ui_draw(void) 2.62 { 2.63 - float aspect = (float)width / (float)height; 2.64 - 2.65 bind_program(prog_ui); 2.66 2.67 gl_matrix_mode(GL_PROJECTION); 2.68 @@ -128,10 +136,16 @@ 2.69 2.70 void ui_button(int bn, int press, int x, int y) 2.71 { 2.72 - scr.sysev_mouse_button(bn, press != 0, (float)x / (float)width, (float)y / (float)height); 2.73 + float normx = aspect * (float)x / (float)width; 2.74 + float normy = 1.0 - (float)y / (float)height; 2.75 + 2.76 + scr.sysev_mouse_button(bn, press != 0, normx, normy); 2.77 } 2.78 2.79 void ui_motion(int x, int y) 2.80 { 2.81 - scr.sysev_mouse_motion((float)x / (float)width, (float)y / (float)height); 2.82 + float normx = aspect * (float)x / (float)width; 2.83 + float normy = 1.0 - (float)y / (float)height; 2.84 + 2.85 + scr.sysev_mouse_motion(normx, normy); 2.86 }
3.1 --- a/src/uitheme.cc Mon Sep 28 06:53:31 2015 +0300 3.2 +++ b/src/uitheme.cc Mon Sep 28 19:04:50 2015 +0300 3.3 @@ -11,10 +11,13 @@ 3.4 using namespace goatkit; 3.5 3.6 extern int view_xsz, view_ysz; 3.7 -extern unsigned int prog_ui, prog_font; 3.8 +extern float view_aspect; 3.9 +extern unsigned int prog_ui, prog_font, prog_color; 3.10 extern struct dtx_font *font; 3.11 3.12 static void draw_label(const Widget *w); 3.13 +static void draw_button(const Widget *w); 3.14 +static void draw_rect(const Vec2 &pos, const Vec2 &sz, float r, float g, float b, float a = 1.0f); 3.15 static void draw_text(float x, float y, const char *text); 3.16 3.17 static struct { 3.18 @@ -22,6 +25,7 @@ 3.19 WidgetDrawFunc func; 3.20 } widget_funcs[] = { 3.21 { "label", draw_label }, 3.22 + { "button", draw_button }, 3.23 {0, 0} 3.24 }; 3.25 3.26 @@ -75,13 +79,47 @@ 3.27 end_drawing(w); 3.28 } 3.29 3.30 +static void draw_button(const Widget *w) 3.31 +{ 3.32 + Vec2 pos = w->get_position(); 3.33 + Vec2 sz = w->get_size(); 3.34 + float vis = w->get_visibility(); 3.35 + if(vis < VIS_THRES) return; 3.36 + 3.37 + begin_drawing(w); 3.38 + 3.39 + draw_rect(pos, sz, 1.0, 0.3, 0.2); 3.40 + draw_text(pos.x, pos.y, w->get_text()); 3.41 + 3.42 + end_drawing(w); 3.43 +} 3.44 + 3.45 +static void draw_rect(const Vec2 &pos, const Vec2 &sz, float r, float g, float b, float a) 3.46 +{ 3.47 + float aspect = sz.x / sz.y; 3.48 + 3.49 + bind_program(prog_color); 3.50 + gl_apply_xform(prog_color); 3.51 + 3.52 + gl_begin(GL_QUADS); 3.53 + gl_color4f(r, g, b, a); 3.54 + gl_texcoord2f(0, 1); 3.55 + gl_vertex2f(pos.x, pos.y); 3.56 + gl_texcoord2f(aspect, 1); 3.57 + gl_vertex2f(pos.x + sz.x, pos.y); 3.58 + gl_texcoord2f(aspect, 0); 3.59 + gl_vertex2f(pos.x + sz.x, pos.y + sz.y); 3.60 + gl_texcoord2f(0, 0); 3.61 + gl_vertex2f(pos.x, pos.y + sz.y); 3.62 + gl_end(); 3.63 +} 3.64 + 3.65 static void draw_text(float x, float y, const char *text) 3.66 { 3.67 struct dtx_glyphmap *gmap = dtx_get_font_glyphmap_idx(font, 0); 3.68 dtx_use_font(font, dtx_get_glyphmap_ptsize(gmap)); 3.69 3.70 - float aspect = (float)view_xsz / (float)view_ysz; 3.71 - float virt_xsz = 420.0 * aspect; 3.72 + float virt_xsz = 420.0 * view_aspect; 3.73 float virt_ysz = 420.0; 3.74 3.75 gl_matrix_mode(GL_PROJECTION);