istereo2

diff src/ui.cc @ 13:ea928c313344

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Sep 2015 19:04:50 +0300
parents 03cc3b1884d1
children 018f997dc646
line diff
     1.1 --- a/src/ui.cc	Mon Sep 28 06:53:31 2015 +0300
     1.2 +++ b/src/ui.cc	Mon Sep 28 19:04:50 2015 +0300
     1.3 @@ -5,30 +5,39 @@
     1.4  #include "sanegl.h"
     1.5  #include "sdr.h"
     1.6  
     1.7 +using namespace goatkit;
     1.8 +
     1.9 +static void done_bn_handler(Widget *w, const Event &ev, void *cls)
    1.10 +{
    1.11 +	printf("done\n");
    1.12 +}
    1.13 +
    1.14  static goatkit::Screen scr;
    1.15 +static float aspect;
    1.16  static int width, height;
    1.17  
    1.18  extern unsigned int prog_color, prog_ui;
    1.19  
    1.20  int ui_init(void)
    1.21  {
    1.22 -	float ypos = 0;
    1.23 +	float xpos = 0.25;
    1.24 +	float ypos = 0.8;
    1.25  	float vsep = 0.1;
    1.26  
    1.27 -	goatkit::Label *label = new goatkit::Label;
    1.28 -	label->set_position(0.5, ypos += vsep);
    1.29 +	/*goatkit::Label *label = new goatkit::Label;
    1.30 +	label->set_position(xpos, ypos);
    1.31  	label->set_size(0.1, 0.1);
    1.32  	label->set_text("Stereoscopic rendering");
    1.33 -	scr.add_widget(label);
    1.34 +	scr.add_widget(label);*/
    1.35 +
    1.36 +	goatkit::Button *button = new goatkit::Button;
    1.37 +	button->set_position(xpos, ypos);
    1.38 +	button->set_size(0.2, 0.1);
    1.39 +	button->set_text("Done");
    1.40 +	button->set_callback(goatkit::EV_CLICK, done_bn_handler);
    1.41 +	scr.add_widget(button);
    1.42  
    1.43  	/*
    1.44 -	goatkit::Button *button = new goatkit::Button;
    1.45 -	button->set_position(300, ypos += vsep);
    1.46 -	button->set_size(200, 40);
    1.47 -	button->set_text("a button!");
    1.48 -	button->set_callback(goatkit::EV_CLICK, callback);
    1.49 -	scr.add_widget(button);
    1.50 -
    1.51  	goatkit::TextBox *text = new goatkit::TextBox;
    1.52  	text->set_position(300, ypos += vsep);
    1.53  	text->set_size(200, 30);
    1.54 @@ -81,12 +90,11 @@
    1.55  {
    1.56  	width = x;
    1.57  	height = y;
    1.58 +	aspect = (float)width / (float)height;
    1.59  }
    1.60  
    1.61  void ui_draw(void)
    1.62  {
    1.63 -	float aspect = (float)width / (float)height;
    1.64 -
    1.65  	bind_program(prog_ui);
    1.66  
    1.67  	gl_matrix_mode(GL_PROJECTION);
    1.68 @@ -128,10 +136,16 @@
    1.69  
    1.70  void ui_button(int bn, int press, int x, int y)
    1.71  {
    1.72 -	scr.sysev_mouse_button(bn, press != 0, (float)x / (float)width, (float)y / (float)height);
    1.73 +	float normx = aspect * (float)x / (float)width;
    1.74 +	float normy = 1.0 - (float)y / (float)height;
    1.75 +
    1.76 +	scr.sysev_mouse_button(bn, press != 0, normx, normy);
    1.77  }
    1.78  
    1.79  void ui_motion(int x, int y)
    1.80  {
    1.81 -	scr.sysev_mouse_motion((float)x / (float)width, (float)y / (float)height);
    1.82 +	float normx = aspect * (float)x / (float)width;
    1.83 +	float normy = 1.0 - (float)y / (float)height;
    1.84 +
    1.85 +	scr.sysev_mouse_motion(normx, normy);
    1.86  }