# HG changeset patch # User John Tsiombikas # Date 1443456290 -10800 # Node ID ea928c313344a6fe781facff81905ee8cb157555 # Parent 57188f7d930459e9266e318b3d1b224100c2e2bb foo diff -r 57188f7d9304 -r ea928c313344 src/istereo.c --- a/src/istereo.c Mon Sep 28 06:53:31 2015 +0300 +++ b/src/istereo.c Mon Sep 28 19:04:50 2015 +0300 @@ -47,6 +47,7 @@ struct dtx_font *font; int view_xsz, view_ysz; +float view_aspect; int stereo = 0; int use_bump = 0; @@ -408,6 +409,7 @@ view_xsz = x; view_ysz = y; + view_aspect = aspect; ui_reshape(x, y); } diff -r 57188f7d9304 -r ea928c313344 src/ui.cc --- a/src/ui.cc Mon Sep 28 06:53:31 2015 +0300 +++ b/src/ui.cc Mon Sep 28 19:04:50 2015 +0300 @@ -5,30 +5,39 @@ #include "sanegl.h" #include "sdr.h" +using namespace goatkit; + +static void done_bn_handler(Widget *w, const Event &ev, void *cls) +{ + printf("done\n"); +} + static goatkit::Screen scr; +static float aspect; static int width, height; extern unsigned int prog_color, prog_ui; int ui_init(void) { - float ypos = 0; + float xpos = 0.25; + float ypos = 0.8; float vsep = 0.1; - goatkit::Label *label = new goatkit::Label; - label->set_position(0.5, ypos += vsep); + /*goatkit::Label *label = new goatkit::Label; + label->set_position(xpos, ypos); label->set_size(0.1, 0.1); label->set_text("Stereoscopic rendering"); - scr.add_widget(label); + scr.add_widget(label);*/ + + goatkit::Button *button = new goatkit::Button; + button->set_position(xpos, ypos); + button->set_size(0.2, 0.1); + button->set_text("Done"); + button->set_callback(goatkit::EV_CLICK, done_bn_handler); + scr.add_widget(button); /* - goatkit::Button *button = new goatkit::Button; - button->set_position(300, ypos += vsep); - button->set_size(200, 40); - button->set_text("a button!"); - button->set_callback(goatkit::EV_CLICK, callback); - scr.add_widget(button); - goatkit::TextBox *text = new goatkit::TextBox; text->set_position(300, ypos += vsep); text->set_size(200, 30); @@ -81,12 +90,11 @@ { width = x; height = y; + aspect = (float)width / (float)height; } void ui_draw(void) { - float aspect = (float)width / (float)height; - bind_program(prog_ui); gl_matrix_mode(GL_PROJECTION); @@ -128,10 +136,16 @@ void ui_button(int bn, int press, int x, int y) { - scr.sysev_mouse_button(bn, press != 0, (float)x / (float)width, (float)y / (float)height); + float normx = aspect * (float)x / (float)width; + float normy = 1.0 - (float)y / (float)height; + + scr.sysev_mouse_button(bn, press != 0, normx, normy); } void ui_motion(int x, int y) { - scr.sysev_mouse_motion((float)x / (float)width, (float)y / (float)height); + float normx = aspect * (float)x / (float)width; + float normy = 1.0 - (float)y / (float)height; + + scr.sysev_mouse_motion(normx, normy); } diff -r 57188f7d9304 -r ea928c313344 src/uitheme.cc --- a/src/uitheme.cc Mon Sep 28 06:53:31 2015 +0300 +++ b/src/uitheme.cc Mon Sep 28 19:04:50 2015 +0300 @@ -11,10 +11,13 @@ using namespace goatkit; extern int view_xsz, view_ysz; -extern unsigned int prog_ui, prog_font; +extern float view_aspect; +extern unsigned int prog_ui, prog_font, prog_color; extern struct dtx_font *font; static void draw_label(const Widget *w); +static void draw_button(const Widget *w); +static void draw_rect(const Vec2 &pos, const Vec2 &sz, float r, float g, float b, float a = 1.0f); static void draw_text(float x, float y, const char *text); static struct { @@ -22,6 +25,7 @@ WidgetDrawFunc func; } widget_funcs[] = { { "label", draw_label }, + { "button", draw_button }, {0, 0} }; @@ -75,13 +79,47 @@ end_drawing(w); } +static void draw_button(const Widget *w) +{ + Vec2 pos = w->get_position(); + Vec2 sz = w->get_size(); + float vis = w->get_visibility(); + if(vis < VIS_THRES) return; + + begin_drawing(w); + + draw_rect(pos, sz, 1.0, 0.3, 0.2); + draw_text(pos.x, pos.y, w->get_text()); + + end_drawing(w); +} + +static void draw_rect(const Vec2 &pos, const Vec2 &sz, float r, float g, float b, float a) +{ + float aspect = sz.x / sz.y; + + bind_program(prog_color); + gl_apply_xform(prog_color); + + gl_begin(GL_QUADS); + gl_color4f(r, g, b, a); + gl_texcoord2f(0, 1); + gl_vertex2f(pos.x, pos.y); + gl_texcoord2f(aspect, 1); + gl_vertex2f(pos.x + sz.x, pos.y); + gl_texcoord2f(aspect, 0); + gl_vertex2f(pos.x + sz.x, pos.y + sz.y); + gl_texcoord2f(0, 0); + gl_vertex2f(pos.x, pos.y + sz.y); + gl_end(); +} + static void draw_text(float x, float y, const char *text) { struct dtx_glyphmap *gmap = dtx_get_font_glyphmap_idx(font, 0); dtx_use_font(font, dtx_get_glyphmap_ptsize(gmap)); - float aspect = (float)view_xsz / (float)view_ysz; - float virt_xsz = 420.0 * aspect; + float virt_xsz = 420.0 * view_aspect; float virt_ysz = 420.0; gl_matrix_mode(GL_PROJECTION);