istereo2

view 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 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;
19 extern unsigned int prog_color, prog_ui;
21 int ui_init(void)
22 {
23 float xpos = 0.25;
24 float ypos = 0.8;
25 float vsep = 0.1;
27 /*goatkit::Label *label = new goatkit::Label;
28 label->set_position(xpos, ypos);
29 label->set_size(0.1, 0.1);
30 label->set_text("Stereoscopic rendering");
31 scr.add_widget(label);*/
33 goatkit::Button *button = new goatkit::Button;
34 button->set_position(xpos, ypos);
35 button->set_size(0.2, 0.1);
36 button->set_text("Done");
37 button->set_callback(goatkit::EV_CLICK, done_bn_handler);
38 scr.add_widget(button);
40 /*
41 goatkit::TextBox *text = new goatkit::TextBox;
42 text->set_position(300, ypos += vsep);
43 text->set_size(200, 30);
44 text->set_text("foo");
45 text->set_callback(goatkit::EV_CHANGE, callback);
46 scr.add_widget(text);
48 goatkit::CheckBox *cbox = new goatkit::CheckBox;
49 cbox->set_position(300, ypos += vsep);
50 cbox->set_size(200, 20);
51 cbox->set_text("a checkbox!");
52 cbox->set_callback(goatkit::EV_CHANGE, callback);
53 scr.add_widget(cbox);
55 goatkit::Slider *slider = new goatkit::Slider;
56 slider->set_position(300, ypos += vsep);
57 slider->set_size(200, 40);
58 slider->set_callback(goatkit::EV_CHANGE, callback);
59 slider->set_continuous_change(false);
60 slider->set_range(0, 100.0);
61 scr.add_widget(slider);
63 goatkit::Slider *intslider = new goatkit::Slider;
64 intslider->set_position(300, ypos += vsep);
65 intslider->set_size(200, 40);
66 intslider->set_callback(goatkit::EV_CHANGE, callback);
67 intslider->set_continuous_change(false);
68 intslider->set_range(0, 100.0);
69 intslider->set_step(10);
70 scr.add_widget(intslider);
71 */
73 scr.show();
75 // load the theme
76 //goatkit::add_theme_path("themes/simple");
78 if(!(goatkit::theme = goatkit::get_theme("istereo"))) {
79 return -1;
80 }
82 return 0;
83 }
85 void ui_shutdown(void)
86 {
87 }
89 void ui_reshape(int x, int y)
90 {
91 width = x;
92 height = y;
93 aspect = (float)width / (float)height;
94 }
96 void ui_draw(void)
97 {
98 bind_program(prog_ui);
100 gl_matrix_mode(GL_PROJECTION);
101 gl_push_matrix();
102 gl_load_identity();
103 gl_scalef(2.0 / aspect, 2.0, 1);
104 gl_translatef(-1, -1, 0);
105 gl_matrix_mode(GL_MODELVIEW);
106 gl_push_matrix();
107 gl_load_identity();
109 glDisable(GL_CULL_FACE);
110 glDisable(GL_DEPTH_TEST);
111 glEnable(GL_BLEND);
112 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
114 set_uniform_float4(prog_ui, "ucolor", 0, 0, 0, 0.5);
116 gl_begin(GL_QUADS);
117 //gl_color4f(0, 0, 0, 0.5);
118 gl_vertex3f(0, 0, 0);
119 gl_vertex3f(0, 1.0, 0);
120 gl_vertex3f(1.0 * aspect, 1.0, 0);
121 gl_vertex3f(1.0 * aspect, 0, 0);
122 gl_end();
124 scr.draw();
126 glDisable(GL_BLEND);
127 glEnable(GL_CULL_FACE);
128 glEnable(GL_DEPTH_TEST);
131 gl_matrix_mode(GL_PROJECTION);
132 gl_pop_matrix();
133 gl_matrix_mode(GL_MODELVIEW);
134 gl_pop_matrix();
135 }
137 void ui_button(int bn, int press, int x, int y)
138 {
139 float normx = aspect * (float)x / (float)width;
140 float normy = 1.0 - (float)y / (float)height;
142 scr.sysev_mouse_button(bn, press != 0, normx, normy);
143 }
145 void ui_motion(int x, int y)
146 {
147 float normx = aspect * (float)x / (float)width;
148 float normy = 1.0 - (float)y / (float)height;
150 scr.sysev_mouse_motion(normx, normy);
151 }