istereo2

view src/ui.cc @ 9:64e15874f3bd

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 26 Sep 2015 02:56:07 +0300
parents a3c4fcc9f8f3
children 03cc3b1884d1
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 static goatkit::Screen scr;
9 static int width, height;
11 extern unsigned int prog_color, prog_ui;
13 int ui_init(void)
14 {
15 float ypos = 0;
16 float vsep = 0.1;
18 goatkit::Label *label = new goatkit::Label;
19 label->set_position(0.5, ypos += vsep);
20 label->set_size(0.1, 0.1);
21 label->set_text("Stereoscopic rendering");
22 scr.add_widget(label);
24 /*
25 goatkit::Button *button = new goatkit::Button;
26 button->set_position(300, ypos += vsep);
27 button->set_size(200, 40);
28 button->set_text("a button!");
29 button->set_callback(goatkit::EV_CLICK, callback);
30 scr.add_widget(button);
32 goatkit::TextBox *text = new goatkit::TextBox;
33 text->set_position(300, ypos += vsep);
34 text->set_size(200, 30);
35 text->set_text("foo");
36 text->set_callback(goatkit::EV_CHANGE, callback);
37 scr.add_widget(text);
39 goatkit::CheckBox *cbox = new goatkit::CheckBox;
40 cbox->set_position(300, ypos += vsep);
41 cbox->set_size(200, 20);
42 cbox->set_text("a checkbox!");
43 cbox->set_callback(goatkit::EV_CHANGE, callback);
44 scr.add_widget(cbox);
46 goatkit::Slider *slider = new goatkit::Slider;
47 slider->set_position(300, ypos += vsep);
48 slider->set_size(200, 40);
49 slider->set_callback(goatkit::EV_CHANGE, callback);
50 slider->set_continuous_change(false);
51 slider->set_range(0, 100.0);
52 scr.add_widget(slider);
54 goatkit::Slider *intslider = new goatkit::Slider;
55 intslider->set_position(300, ypos += vsep);
56 intslider->set_size(200, 40);
57 intslider->set_callback(goatkit::EV_CHANGE, callback);
58 intslider->set_continuous_change(false);
59 intslider->set_range(0, 100.0);
60 intslider->set_step(10);
61 scr.add_widget(intslider);
62 */
64 scr.show();
66 // load the theme
67 //goatkit::add_theme_path("themes/simple");
69 goatkit::theme = new goatkit::Theme;
70 if(!goatkit::theme->load(GOATKIT_THEME_BUILTIN)) {
71 fprintf(stderr, "no builitn theme\n");
72 return -1;
73 }
75 return 0;
76 }
78 void ui_shutdown(void)
79 {
80 }
82 void ui_reshape(int x, int y)
83 {
84 width = x;
85 height = y;
86 }
88 void ui_draw(void)
89 {
90 float aspect = (float)width / (float)height;
92 bind_program(prog_ui);
94 gl_matrix_mode(GL_PROJECTION);
95 gl_push_matrix();
96 gl_load_identity();
97 gl_scalef(2.0 / aspect, 2.0, 1);
98 gl_translatef(-1, -1, 0);
99 gl_matrix_mode(GL_MODELVIEW);
100 gl_push_matrix();
101 gl_load_identity();
103 glDisable(GL_CULL_FACE);
104 glDisable(GL_DEPTH_TEST);
105 glEnable(GL_BLEND);
106 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
108 set_uniform_float4(prog_ui, "ucolor", 0, 0, 0, 0.5);
110 gl_begin(GL_QUADS);
111 //gl_color4f(0, 0, 0, 0.5);
112 gl_vertex3f(0, 0, 0);
113 gl_vertex3f(0, 1.0, 0);
114 gl_vertex3f(1.0 * aspect, 1.0, 0);
115 gl_vertex3f(1.0 * aspect, 0, 0);
116 gl_end();
118 scr.draw();
120 glDisable(GL_BLEND);
121 glEnable(GL_CULL_FACE);
122 glEnable(GL_DEPTH_TEST);
125 gl_matrix_mode(GL_PROJECTION);
126 gl_pop_matrix();
127 gl_matrix_mode(GL_MODELVIEW);
128 gl_pop_matrix();
129 }
131 void ui_button(int bn, int press, int x, int y)
132 {
133 scr.sysev_mouse_button(bn, press != 0, (float)x / (float)width, (float)y / (float)height);
134 }
136 void ui_motion(int x, int y)
137 {
138 scr.sysev_mouse_motion((float)x / (float)width, (float)y / (float)height);
139 }