rev |
line source |
nuclear@7
|
1 #include <stdio.h>
|
nuclear@6
|
2 #include "ui.h"
|
nuclear@6
|
3 #include "goatkit/goatkit.h"
|
nuclear@6
|
4 #include "opengl.h"
|
nuclear@6
|
5 #include "sdr.h"
|
nuclear@6
|
6
|
nuclear@6
|
7 static goatkit::Screen scr;
|
nuclear@6
|
8 static int width, height;
|
nuclear@6
|
9
|
nuclear@6
|
10 extern unsigned int prog_color, prog_ui;
|
nuclear@6
|
11
|
nuclear@6
|
12 int ui_init(void)
|
nuclear@6
|
13 {
|
nuclear@6
|
14 float ypos = 0;
|
nuclear@6
|
15 float vsep = 0.1;
|
nuclear@6
|
16
|
nuclear@6
|
17 goatkit::Label *label = new goatkit::Label;
|
nuclear@6
|
18 label->set_position(0.5, ypos += vsep);
|
nuclear@6
|
19 label->set_size(0.1, 0.1);
|
nuclear@6
|
20 label->set_text("Stereoscopic rendering");
|
nuclear@6
|
21 scr.add_widget(label);
|
nuclear@6
|
22
|
nuclear@6
|
23 /*
|
nuclear@6
|
24 goatkit::Button *button = new goatkit::Button;
|
nuclear@6
|
25 button->set_position(300, ypos += vsep);
|
nuclear@6
|
26 button->set_size(200, 40);
|
nuclear@6
|
27 button->set_text("a button!");
|
nuclear@6
|
28 button->set_callback(goatkit::EV_CLICK, callback);
|
nuclear@6
|
29 scr.add_widget(button);
|
nuclear@6
|
30
|
nuclear@6
|
31 goatkit::TextBox *text = new goatkit::TextBox;
|
nuclear@6
|
32 text->set_position(300, ypos += vsep);
|
nuclear@6
|
33 text->set_size(200, 30);
|
nuclear@6
|
34 text->set_text("foo");
|
nuclear@6
|
35 text->set_callback(goatkit::EV_CHANGE, callback);
|
nuclear@6
|
36 scr.add_widget(text);
|
nuclear@6
|
37
|
nuclear@6
|
38 goatkit::CheckBox *cbox = new goatkit::CheckBox;
|
nuclear@6
|
39 cbox->set_position(300, ypos += vsep);
|
nuclear@6
|
40 cbox->set_size(200, 20);
|
nuclear@6
|
41 cbox->set_text("a checkbox!");
|
nuclear@6
|
42 cbox->set_callback(goatkit::EV_CHANGE, callback);
|
nuclear@6
|
43 scr.add_widget(cbox);
|
nuclear@6
|
44
|
nuclear@6
|
45 goatkit::Slider *slider = new goatkit::Slider;
|
nuclear@6
|
46 slider->set_position(300, ypos += vsep);
|
nuclear@6
|
47 slider->set_size(200, 40);
|
nuclear@6
|
48 slider->set_callback(goatkit::EV_CHANGE, callback);
|
nuclear@6
|
49 slider->set_continuous_change(false);
|
nuclear@6
|
50 slider->set_range(0, 100.0);
|
nuclear@6
|
51 scr.add_widget(slider);
|
nuclear@6
|
52
|
nuclear@6
|
53 goatkit::Slider *intslider = new goatkit::Slider;
|
nuclear@6
|
54 intslider->set_position(300, ypos += vsep);
|
nuclear@6
|
55 intslider->set_size(200, 40);
|
nuclear@6
|
56 intslider->set_callback(goatkit::EV_CHANGE, callback);
|
nuclear@6
|
57 intslider->set_continuous_change(false);
|
nuclear@6
|
58 intslider->set_range(0, 100.0);
|
nuclear@6
|
59 intslider->set_step(10);
|
nuclear@6
|
60 scr.add_widget(intslider);
|
nuclear@6
|
61 */
|
nuclear@6
|
62
|
nuclear@6
|
63 scr.show();
|
nuclear@6
|
64
|
nuclear@6
|
65 // load the theme
|
nuclear@6
|
66 //goatkit::add_theme_path("themes/simple");
|
nuclear@6
|
67
|
nuclear@7
|
68 goatkit::theme = new goatkit::Theme;
|
nuclear@7
|
69 if(!goatkit::theme->load(GOATKIT_THEME_BUILTIN)) {
|
nuclear@7
|
70 fprintf(stderr, "no builitn theme\n");
|
nuclear@7
|
71 return -1;
|
nuclear@7
|
72 }
|
nuclear@6
|
73
|
nuclear@6
|
74 return 0;
|
nuclear@6
|
75 }
|
nuclear@6
|
76
|
nuclear@6
|
77 void ui_shutdown(void)
|
nuclear@6
|
78 {
|
nuclear@6
|
79 }
|
nuclear@6
|
80
|
nuclear@6
|
81 void ui_reshape(int x, int y)
|
nuclear@6
|
82 {
|
nuclear@6
|
83 width = x;
|
nuclear@6
|
84 height = y;
|
nuclear@6
|
85 }
|
nuclear@6
|
86
|
nuclear@6
|
87 void ui_draw(void)
|
nuclear@6
|
88 {
|
nuclear@6
|
89 float aspect = (float)width / (float)height;
|
nuclear@6
|
90
|
nuclear@6
|
91 bind_program(prog_ui);
|
nuclear@6
|
92
|
nuclear@6
|
93 gl_matrix_mode(GL_PROJECTION);
|
nuclear@6
|
94 gl_push_matrix();
|
nuclear@6
|
95 gl_load_identity();
|
nuclear@6
|
96 gl_scalef(2.0 / aspect, 2.0, 1);
|
nuclear@6
|
97 gl_translatef(-1, -1, 0);
|
nuclear@6
|
98 gl_matrix_mode(GL_MODELVIEW);
|
nuclear@6
|
99 gl_push_matrix();
|
nuclear@6
|
100 gl_load_identity();
|
nuclear@6
|
101
|
nuclear@6
|
102 glDisable(GL_CULL_FACE);
|
nuclear@6
|
103 glDisable(GL_DEPTH_TEST);
|
nuclear@7
|
104 glEnable(GL_BLEND);
|
nuclear@7
|
105 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
nuclear@6
|
106
|
nuclear@7
|
107 set_uniform_float4(prog_ui, "ucolor", 0, 0, 0, 0.5);
|
nuclear@7
|
108
|
nuclear@7
|
109 gl_begin(GL_QUADS);
|
nuclear@7
|
110 //gl_color4f(0, 0, 0, 0.5);
|
nuclear@6
|
111 gl_vertex3f(0, 0, 0);
|
nuclear@7
|
112 gl_vertex3f(0, 1.0, 0);
|
nuclear@7
|
113 gl_vertex3f(1.0 * aspect, 1.0, 0);
|
nuclear@7
|
114 gl_vertex3f(1.0 * aspect, 0, 0);
|
nuclear@6
|
115 gl_end();
|
nuclear@6
|
116
|
nuclear@6
|
117 scr.draw();
|
nuclear@6
|
118
|
nuclear@7
|
119 glDisable(GL_BLEND);
|
nuclear@6
|
120 glEnable(GL_CULL_FACE);
|
nuclear@6
|
121 glEnable(GL_DEPTH_TEST);
|
nuclear@6
|
122
|
nuclear@6
|
123
|
nuclear@6
|
124 gl_matrix_mode(GL_PROJECTION);
|
nuclear@6
|
125 gl_pop_matrix();
|
nuclear@6
|
126 gl_matrix_mode(GL_MODELVIEW);
|
nuclear@6
|
127 gl_pop_matrix();
|
nuclear@6
|
128 }
|
nuclear@6
|
129
|
nuclear@6
|
130 void ui_button(int bn, int press, int x, int y)
|
nuclear@6
|
131 {
|
nuclear@7
|
132 scr.sysev_mouse_button(bn, press != 0, (float)x / (float)width, (float)y / (float)height);
|
nuclear@6
|
133 }
|
nuclear@6
|
134
|
nuclear@6
|
135 void ui_motion(int x, int y)
|
nuclear@6
|
136 {
|
nuclear@7
|
137 scr.sysev_mouse_motion((float)x / (float)width, (float)y / (float)height);
|
nuclear@6
|
138 } |