istereo2

view src/ui.cc @ 11:03cc3b1884d1

implemented builtin themes registration and lookup in goatkit
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Sep 2015 06:53:06 +0300
parents 64e15874f3bd
children ea928c313344
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 if(!(goatkit::theme = goatkit::get_theme("istereo"))) {
70 return -1;
71 }
73 return 0;
74 }
76 void ui_shutdown(void)
77 {
78 }
80 void ui_reshape(int x, int y)
81 {
82 width = x;
83 height = y;
84 }
86 void ui_draw(void)
87 {
88 float aspect = (float)width / (float)height;
90 bind_program(prog_ui);
92 gl_matrix_mode(GL_PROJECTION);
93 gl_push_matrix();
94 gl_load_identity();
95 gl_scalef(2.0 / aspect, 2.0, 1);
96 gl_translatef(-1, -1, 0);
97 gl_matrix_mode(GL_MODELVIEW);
98 gl_push_matrix();
99 gl_load_identity();
101 glDisable(GL_CULL_FACE);
102 glDisable(GL_DEPTH_TEST);
103 glEnable(GL_BLEND);
104 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
106 set_uniform_float4(prog_ui, "ucolor", 0, 0, 0, 0.5);
108 gl_begin(GL_QUADS);
109 //gl_color4f(0, 0, 0, 0.5);
110 gl_vertex3f(0, 0, 0);
111 gl_vertex3f(0, 1.0, 0);
112 gl_vertex3f(1.0 * aspect, 1.0, 0);
113 gl_vertex3f(1.0 * aspect, 0, 0);
114 gl_end();
116 scr.draw();
118 glDisable(GL_BLEND);
119 glEnable(GL_CULL_FACE);
120 glEnable(GL_DEPTH_TEST);
123 gl_matrix_mode(GL_PROJECTION);
124 gl_pop_matrix();
125 gl_matrix_mode(GL_MODELVIEW);
126 gl_pop_matrix();
127 }
129 void ui_button(int bn, int press, int x, int y)
130 {
131 scr.sysev_mouse_button(bn, press != 0, (float)x / (float)width, (float)y / (float)height);
132 }
134 void ui_motion(int x, int y)
135 {
136 scr.sysev_mouse_motion((float)x / (float)width, (float)y / (float)height);
137 }