istereo2

view src/ui.cc @ 14:018f997dc646

button done
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 29 Sep 2015 01:11:54 +0300
parents ea928c313344
children 7bd4264bf74a
line source
1 #include <stdio.h>
2 #include "ui.h"
3 #include "goatkit/goatkit.h"
4 #include "opengl.h"
5 #include "sanegl.h"
6 #include "sdr.h"
8 using namespace goatkit;
10 static void done_bn_handler(Widget *w, const Event &ev, void *cls)
11 {
12 printf("done\n");
13 }
15 static goatkit::Screen scr;
16 static float aspect;
17 static int width, height;
18 static int virt_width, virt_height;
20 extern unsigned int prog_color, prog_ui;
22 int ui_init(void)
23 {
24 float xpos = 100;
25 float ypos = 50;
26 float vsep = 50;
28 /*goatkit::Label *label = new goatkit::Label;
29 label->set_position(xpos, ypos);
30 label->set_size(20, 20);
31 label->set_text("Stereoscopic rendering");
32 scr.add_widget(label);*/
34 goatkit::Button *button = new goatkit::Button;
35 button->set_position(xpos, ypos);
36 button->set_size(80, 30);
37 button->set_text("Done");
38 button->set_callback(goatkit::EV_CLICK, done_bn_handler);
39 scr.add_widget(button);
41 /*
42 goatkit::TextBox *text = new goatkit::TextBox;
43 text->set_position(300, ypos += vsep);
44 text->set_size(200, 30);
45 text->set_text("foo");
46 text->set_callback(goatkit::EV_CHANGE, callback);
47 scr.add_widget(text);
49 goatkit::CheckBox *cbox = new goatkit::CheckBox;
50 cbox->set_position(300, ypos += vsep);
51 cbox->set_size(200, 20);
52 cbox->set_text("a checkbox!");
53 cbox->set_callback(goatkit::EV_CHANGE, callback);
54 scr.add_widget(cbox);
56 goatkit::Slider *slider = new goatkit::Slider;
57 slider->set_position(300, ypos += vsep);
58 slider->set_size(200, 40);
59 slider->set_callback(goatkit::EV_CHANGE, callback);
60 slider->set_continuous_change(false);
61 slider->set_range(0, 100.0);
62 scr.add_widget(slider);
64 goatkit::Slider *intslider = new goatkit::Slider;
65 intslider->set_position(300, ypos += vsep);
66 intslider->set_size(200, 40);
67 intslider->set_callback(goatkit::EV_CHANGE, callback);
68 intslider->set_continuous_change(false);
69 intslider->set_range(0, 100.0);
70 intslider->set_step(10);
71 scr.add_widget(intslider);
72 */
74 scr.show();
76 // load the theme
77 //goatkit::add_theme_path("themes/simple");
79 if(!(goatkit::theme = goatkit::get_theme("istereo"))) {
80 return -1;
81 }
83 return 0;
84 }
86 void ui_shutdown(void)
87 {
88 }
90 void ui_reshape(int x, int y)
91 {
92 width = x;
93 height = y;
94 aspect = (float)width / (float)height;
96 virt_width = 500.0 * aspect;
97 virt_height = 500.0;
98 }
100 void ui_draw(void)
101 {
102 bind_program(prog_ui);
104 gl_matrix_mode(GL_PROJECTION);
105 gl_push_matrix();
106 gl_load_identity();
107 gl_ortho(0, virt_width, 0, virt_height, -1, 1);
108 gl_matrix_mode(GL_MODELVIEW);
109 gl_push_matrix();
110 gl_load_identity();
112 glDisable(GL_CULL_FACE);
113 glDisable(GL_DEPTH_TEST);
114 glEnable(GL_BLEND);
115 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
117 set_uniform_float4(prog_ui, "ucolor", 0, 0, 0, 0.5);
119 gl_begin(GL_QUADS);
120 //gl_color4f(0, 0, 0, 0.5);
121 gl_vertex3f(0, 0, 0);
122 gl_vertex3f(0, virt_height, 0);
123 gl_vertex3f(virt_width, virt_height, 0);
124 gl_vertex3f(virt_width, 0, 0);
125 gl_end();
127 scr.draw();
129 glDisable(GL_BLEND);
130 glEnable(GL_CULL_FACE);
131 glEnable(GL_DEPTH_TEST);
134 gl_matrix_mode(GL_PROJECTION);
135 gl_pop_matrix();
136 gl_matrix_mode(GL_MODELVIEW);
137 gl_pop_matrix();
138 }
140 void ui_button(int bn, int press, int x, int y)
141 {
142 float normx = virt_width * (float)x / (float)width;
143 float normy = virt_height - virt_height * (float)y / (float)height;
145 scr.sysev_mouse_button(bn, press != 0, normx, normy);
146 }
148 void ui_motion(int x, int y)
149 {
150 float normx = virt_width * (float)x / (float)width;
151 float normy = virt_height - virt_height * (float)y / (float)height;
153 scr.sysev_mouse_motion(normx, normy);
154 }