istereo2
changeset 15:7bd4264bf74a
gui done?
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 30 Sep 2015 04:41:21 +0300 |
parents | 018f997dc646 |
children | 1b7776cb800b |
files | libs/drawtext/font.c libs/goatkit/checkbox.cc libs/goatkit/checkbox.h libs/goatkit/screen.cc libs/goatkit/screen.h libs/goatkit/widget.cc src/istereo.c src/ui.cc src/ui.h src/uitheme.cc |
diffstat | 10 files changed, 346 insertions(+), 103 deletions(-) [+] |
line diff
1.1 --- a/libs/drawtext/font.c Tue Sep 29 01:11:54 2015 +0300 1.2 +++ b/libs/drawtext/font.c Wed Sep 30 04:41:21 2015 +0300 1.3 @@ -153,14 +153,14 @@ 1.4 void dtx_prepare(struct dtx_font *fnt, int sz) 1.5 { 1.6 if(!dtx_get_font_glyphmap_range(fnt, sz, 0, 256)) { 1.7 - fprintf(stderr, "%s: failed (sz: %d, range: 0-255 [ascii])\n", __FUNCTION__, sz); 1.8 + fprintf(stderr, "%s: failed (sz: %d, range: 0-255 [ascii])\n", __func__, sz); 1.9 } 1.10 } 1.11 1.12 void dtx_prepare_range(struct dtx_font *fnt, int sz, int cstart, int cend) 1.13 { 1.14 if(!dtx_get_font_glyphmap_range(fnt, sz, cstart, cend)) { 1.15 - fprintf(stderr, "%s: failed (sz: %d, range: %d-%d)\n", __FUNCTION__, sz, cstart, cend); 1.16 + fprintf(stderr, "%s: failed (sz: %d, range: %d-%d)\n", __func__, sz, cstart, cend); 1.17 } 1.18 } 1.19 1.20 @@ -437,7 +437,7 @@ 1.21 } 1.22 1.23 } else { 1.24 - fprintf(stderr, "%s: invalid glyph info line\n", __FUNCTION__); 1.25 + fprintf(stderr, "%s: invalid glyph info line\n", __func__); 1.26 goto err; 1.27 } 1.28 1.29 @@ -445,14 +445,14 @@ 1.30 switch(hdr_lines) { 1.31 case 0: 1.32 if(0[line] != 'P' || 1[line] != '6') { 1.33 - fprintf(stderr, "%s: invalid file format (magic)\n", __FUNCTION__); 1.34 + fprintf(stderr, "%s: invalid file format (magic)\n", __func__); 1.35 goto err; 1.36 } 1.37 break; 1.38 1.39 case 1: 1.40 if(sscanf(line, "%d %d", &gmap->xsz, &gmap->ysz) != 2) { 1.41 - fprintf(stderr, "%s: invalid file format (dim)\n", __FUNCTION__); 1.42 + fprintf(stderr, "%s: invalid file format (dim)\n", __func__); 1.43 goto err; 1.44 } 1.45 break; 1.46 @@ -462,7 +462,7 @@ 1.47 char *endp; 1.48 max_pixval = strtol(line, &endp, 10); 1.49 if(endp == line) { 1.50 - fprintf(stderr, "%s: invalid file format (maxval)\n", __FUNCTION__); 1.51 + fprintf(stderr, "%s: invalid file format (maxval)\n", __func__); 1.52 goto err; 1.53 } 1.54 } 1.55 @@ -476,7 +476,7 @@ 1.56 } 1.57 1.58 if(gmap->ptsize == -1 || gmap->line_advance == FLT_MIN) { 1.59 - fprintf(stderr, "%s: invalid glyphmap, insufficient information in ppm comments\n", __FUNCTION__); 1.60 + fprintf(stderr, "%s: invalid glyphmap, insufficient information in ppm comments\n", __func__); 1.61 goto err; 1.62 } 1.63 1.64 @@ -540,7 +540,7 @@ 1.65 int res; 1.66 1.67 if(!(fp = fopen(fname, "wb"))) { 1.68 - fprintf(stderr, "%s: failed to open file: %s: %s\n", __FUNCTION__, fname, strerror(errno)); 1.69 + fprintf(stderr, "%s: failed to open file: %s: %s\n", __func__, fname, strerror(errno)); 1.70 return -1; 1.71 } 1.72 res = dtx_save_glyphmap_stream(fp, gmap);
2.1 --- a/libs/goatkit/checkbox.cc Tue Sep 29 01:11:54 2015 +0300 2.2 +++ b/libs/goatkit/checkbox.cc Wed Sep 30 04:41:21 2015 +0300 2.3 @@ -71,6 +71,16 @@ 2.4 } 2.5 } 2.6 2.7 +void CheckBox::set_toggle_transition(long msec) 2.8 +{ 2.9 + cbox->checked.set_transition_duration(msec); 2.10 +} 2.11 + 2.12 +long CheckBox::get_toggle_transition() const 2.13 +{ 2.14 + return cbox->checked.get_transition_duration(); 2.15 +} 2.16 + 2.17 void CheckBox::on_click() 2.18 { 2.19 toggle();
3.1 --- a/libs/goatkit/checkbox.h Tue Sep 29 01:11:54 2015 +0300 3.2 +++ b/libs/goatkit/checkbox.h Wed Sep 30 04:41:21 2015 +0300 3.3 @@ -39,6 +39,8 @@ 3.4 virtual float get_checked() const; 3.5 virtual bool is_checked() const; 3.6 virtual void toggle(); 3.7 + virtual void set_toggle_transition(long msec); 3.8 + virtual long get_toggle_transition() const; 3.9 3.10 virtual void on_click(); 3.11 };
4.1 --- a/libs/goatkit/screen.cc Tue Sep 29 01:11:54 2015 +0300 4.2 +++ b/libs/goatkit/screen.cc Wed Sep 30 04:41:21 2015 +0300 4.3 @@ -21,13 +21,14 @@ 4.4 #include <vector> 4.5 #include "screen.h" 4.6 #include "widget.h" 4.7 +#include "boolanm.h" 4.8 4.9 #define MAX_BUTTONS 16 4.10 4.11 namespace goatkit { 4.12 4.13 struct ScreenImpl { 4.14 - bool visible; 4.15 + BoolAnim visible; 4.16 std::vector<Widget*> widgets; 4.17 BBox box; 4.18 4.19 @@ -137,7 +138,7 @@ 4.20 4.21 void Screen::show() 4.22 { 4.23 - scr->visible = true; 4.24 + scr->visible.change(true); 4.25 4.26 for(size_t i=0; i<scr->widgets.size(); i++) { 4.27 scr->widgets[i]->show(); 4.28 @@ -146,7 +147,7 @@ 4.29 4.30 void Screen::hide() 4.31 { 4.32 - scr->visible = false; 4.33 + scr->visible.change(false); 4.34 4.35 for(size_t i=0; i<scr->widgets.size(); i++) { 4.36 scr->widgets[i]->hide(); 4.37 @@ -158,6 +159,24 @@ 4.38 return scr->visible; 4.39 } 4.40 4.41 +float Screen::get_visibility() const 4.42 +{ 4.43 + return scr->visible.get_value(); 4.44 +} 4.45 + 4.46 +void Screen::set_visibility_transition(long msec) 4.47 +{ 4.48 + scr->visible.set_transition_duration(msec); 4.49 + for(size_t i=0; i<scr->widgets.size(); i++) { 4.50 + scr->widgets[i]->set_visibility_transition(msec); 4.51 + } 4.52 +} 4.53 + 4.54 +long Screen::get_visibility_transition() const 4.55 +{ 4.56 + return scr->visible.get_transition_duration(); 4.57 +} 4.58 + 4.59 bool Screen::grab_mouse(Widget *w) 4.60 { 4.61 if(!scr->mgrab || !w) {
5.1 --- a/libs/goatkit/screen.h Tue Sep 29 01:11:54 2015 +0300 5.2 +++ b/libs/goatkit/screen.h Wed Sep 30 04:41:21 2015 +0300 5.3 @@ -49,6 +49,9 @@ 5.4 void show(); 5.5 void hide(); 5.6 bool is_visible() const; 5.7 + float get_visibility() const; 5.8 + void set_visibility_transition(long msec); 5.9 + long get_visibility_transition() const; 5.10 5.11 bool grab_mouse(Widget *w); 5.12
6.1 --- a/libs/goatkit/widget.cc Tue Sep 29 01:11:54 2015 +0300 6.2 +++ b/libs/goatkit/widget.cc Wed Sep 30 04:41:21 2015 +0300 6.3 @@ -161,7 +161,7 @@ 6.4 6.5 long Widget::get_active_transition() const 6.6 { 6.7 - widget->active.get_transition_duration(); 6.8 + return widget->active.get_transition_duration(); 6.9 } 6.10 6.11 void Widget::press()
7.1 --- a/src/istereo.c Tue Sep 29 01:11:54 2015 +0300 7.2 +++ b/src/istereo.c Wed Sep 30 04:41:21 2015 +0300 7.3 @@ -34,6 +34,8 @@ 7.4 #include "drawtext.h" 7.5 #include "timer.h" 7.6 7.7 +#undef STEREO_GUI 7.8 + 7.9 static void render(float t); 7.10 static void draw_tunnel(float t); 7.11 static void tunnel_vertex(float u, float v, float du, float dv, int tang_loc, float t); 7.12 @@ -100,12 +102,11 @@ 7.13 return -1; 7.14 } 7.15 7.16 - if(!(font = dtx_open_font_glyphmap(find_resource("linux-libertine_s24.glyphmap", 0, 0)))) { 7.17 + if(!(font = dtx_open_font_glyphmap(find_resource("droidsans_s24.glyphmap", 0, 0)))) { 7.18 fprintf(stderr, "failed to load font\n"); 7.19 return -1; 7.20 } 7.21 dtx_vertex_attribs(get_attrib_loc(prog_ui, "attr_vertex"), get_attrib_loc(prog_ui, "attr_texcoord")); 7.22 - dtx_use_font(font, 24); 7.23 7.24 glEnable(GL_DEPTH_TEST); 7.25 glEnable(GL_CULL_FACE); 7.26 @@ -113,6 +114,9 @@ 7.27 if(ui_init() == -1) { 7.28 return -1; 7.29 } 7.30 + if(show_opt) { 7.31 + ui_show(); 7.32 + } 7.33 7.34 cam_fov(42.5); 7.35 cam_clip(0.5, 250.0); 7.36 @@ -199,19 +203,12 @@ 7.37 render(tsec); 7.38 } 7.39 7.40 - /* TEST */ 7.41 - /*bind_program(prog_ui); 7.42 - 7.43 - gl_matrix_mode(GL_PROJECTION); 7.44 - gl_load_identity(); 7.45 - gl_ortho(0, view_xsz, 0, view_ysz, -1, 1); 7.46 - gl_matrix_mode(GL_MODELVIEW); 7.47 - gl_load_identity(); 7.48 - gl_apply_xform(prog_ui); 7.49 - 7.50 - glDisable(GL_DEPTH_TEST); 7.51 - dtx_printf("hello world\n"); 7.52 - glEnable(GL_DEPTH_TEST);*/ 7.53 +#ifndef STEREO_GUI 7.54 + if(ui_visible()) { 7.55 + glViewport(0, 0, view_xsz, view_ysz); 7.56 + ui_draw(); 7.57 + } 7.58 +#endif 7.59 7.60 assert(glGetError() == GL_NO_ERROR); 7.61 } 7.62 @@ -233,9 +230,12 @@ 7.63 glDepthMask(1); 7.64 } 7.65 7.66 - if(show_opt) { 7.67 +#ifdef STEREO_GUI 7.68 + if(ui_visible()) { 7.69 + ui_reshape(stereo ? view_xsz / 2.0 : view_xsz, view_ysz); 7.70 ui_draw(); 7.71 } 7.72 +#endif 7.73 } 7.74 7.75 static void draw_tunnel(float t) 7.76 @@ -418,6 +418,11 @@ 7.77 { 7.78 if(show_opt) { 7.79 ui_button(bn, press, x, y); 7.80 + } else { 7.81 + if(press) { 7.82 + show_opt = 1; 7.83 + ui_show(); 7.84 + } 7.85 } 7.86 } 7.87
8.1 --- a/src/ui.cc Tue Sep 29 01:11:54 2015 +0300 8.2 +++ b/src/ui.cc Wed Sep 30 04:41:21 2015 +0300 8.3 @@ -7,76 +7,106 @@ 8.4 8.5 using namespace goatkit; 8.6 8.7 -static void done_bn_handler(Widget *w, const Event &ev, void *cls) 8.8 -{ 8.9 - printf("done\n"); 8.10 -} 8.11 +extern int stereo; 8.12 +extern int show_opt; 8.13 +extern int use_bump; 8.14 +extern float split; 8.15 8.16 -static goatkit::Screen scr; 8.17 +static void done_bn_handler(Widget *w, const Event &ev, void *cls); 8.18 +static void stereo_cbox_handler(Widget *w, const Event &ev, void *cls); 8.19 +static void bump_cbox_handler(Widget *w, const Event &ev, void *cls); 8.20 +static void split_slider_handler(Widget *w, const Event &ev, void *cls); 8.21 + 8.22 +static Screen scr; 8.23 static float aspect; 8.24 static int width, height; 8.25 static int virt_width, virt_height; 8.26 +static Slider *slider_split; 8.27 +static Label *label_split; 8.28 8.29 extern unsigned int prog_color, prog_ui; 8.30 8.31 int ui_init(void) 8.32 { 8.33 - float xpos = 100; 8.34 - float ypos = 50; 8.35 - float vsep = 50; 8.36 + float ypos = 300; 8.37 + float vsep = 70; 8.38 + float vsz = 35; 8.39 8.40 - /*goatkit::Label *label = new goatkit::Label; 8.41 - label->set_position(xpos, ypos); 8.42 - label->set_size(20, 20); 8.43 - label->set_text("Stereoscopic rendering"); 8.44 - scr.add_widget(label);*/ 8.45 + CheckBox *cbox = new CheckBox; 8.46 + cbox->set_position(300, ypos); 8.47 + cbox->set_size(300, vsz); 8.48 + cbox->set_text("Stereoscopic rendering"); 8.49 + cbox->set_callback(EV_CHANGE, stereo_cbox_handler); 8.50 + //cbox->set_toggle_transition(80); 8.51 + scr.add_widget(cbox); 8.52 + ypos -= vsep; 8.53 8.54 - goatkit::Button *button = new goatkit::Button; 8.55 - button->set_position(xpos, ypos); 8.56 - button->set_size(80, 30); 8.57 + label_split = new Label; 8.58 + label_split->set_position(170, ypos); 8.59 + label_split->set_size(20, vsz); 8.60 + label_split->set_text("Stereo split"); 8.61 + if(!stereo) label_split->deactivate(); 8.62 + scr.add_widget(label_split); 8.63 + 8.64 + slider_split = new Slider; 8.65 + slider_split->set_position(300, ypos); 8.66 + slider_split->set_size(300, vsz); 8.67 + slider_split->set_callback(EV_CHANGE, split_slider_handler); 8.68 + slider_split->set_continuous_change(true); 8.69 + slider_split->set_range(0, 1.0); 8.70 + slider_split->set_value(split); 8.71 + if(!stereo) slider_split->deactivate(); 8.72 + scr.add_widget(slider_split); 8.73 + ypos -= vsep; 8.74 + 8.75 + cbox = new CheckBox; 8.76 + cbox->set_position(300, ypos); 8.77 + cbox->set_size(300, vsz); 8.78 + cbox->set_text("Bump mapping"); 8.79 + cbox->set_callback(EV_CHANGE, bump_cbox_handler); 8.80 + scr.add_widget(cbox); 8.81 + ypos -= vsep; 8.82 + 8.83 + ypos -= vsep * 0.5; 8.84 + Button *button = new Button; 8.85 + button->set_position(450, ypos); 8.86 + button->set_size(150, vsz); 8.87 button->set_text("Done"); 8.88 - button->set_callback(goatkit::EV_CLICK, done_bn_handler); 8.89 + button->set_callback(EV_CLICK, done_bn_handler); 8.90 scr.add_widget(button); 8.91 + ypos -= vsep; 8.92 8.93 /* 8.94 - goatkit::TextBox *text = new goatkit::TextBox; 8.95 + TextBox *text = new TextBox; 8.96 text->set_position(300, ypos += vsep); 8.97 text->set_size(200, 30); 8.98 text->set_text("foo"); 8.99 - text->set_callback(goatkit::EV_CHANGE, callback); 8.100 + text->set_callback(EV_CHANGE, callback); 8.101 scr.add_widget(text); 8.102 8.103 - goatkit::CheckBox *cbox = new goatkit::CheckBox; 8.104 + CheckBox *cbox = new CheckBox; 8.105 cbox->set_position(300, ypos += vsep); 8.106 cbox->set_size(200, 20); 8.107 cbox->set_text("a checkbox!"); 8.108 - cbox->set_callback(goatkit::EV_CHANGE, callback); 8.109 + cbox->set_callback(EV_CHANGE, callback); 8.110 scr.add_widget(cbox); 8.111 8.112 - goatkit::Slider *slider = new goatkit::Slider; 8.113 - slider->set_position(300, ypos += vsep); 8.114 - slider->set_size(200, 40); 8.115 - slider->set_callback(goatkit::EV_CHANGE, callback); 8.116 - slider->set_continuous_change(false); 8.117 - slider->set_range(0, 100.0); 8.118 - scr.add_widget(slider); 8.119 - 8.120 - goatkit::Slider *intslider = new goatkit::Slider; 8.121 + Slider *intslider = new Slider; 8.122 intslider->set_position(300, ypos += vsep); 8.123 intslider->set_size(200, 40); 8.124 - intslider->set_callback(goatkit::EV_CHANGE, callback); 8.125 + intslider->set_callback(EV_CHANGE, callback); 8.126 intslider->set_continuous_change(false); 8.127 intslider->set_range(0, 100.0); 8.128 intslider->set_step(10); 8.129 scr.add_widget(intslider); 8.130 */ 8.131 8.132 - scr.show(); 8.133 + scr.set_visibility_transition(400); 8.134 8.135 // load the theme 8.136 - //goatkit::add_theme_path("themes/simple"); 8.137 + //add_theme_path("themes/simple"); 8.138 8.139 - if(!(goatkit::theme = goatkit::get_theme("istereo"))) { 8.140 + if(!(theme = get_theme("istereo"))) { 8.141 return -1; 8.142 } 8.143 8.144 @@ -87,6 +117,21 @@ 8.145 { 8.146 } 8.147 8.148 +void ui_show() 8.149 +{ 8.150 + scr.show(); 8.151 +} 8.152 + 8.153 +void ui_hide() 8.154 +{ 8.155 + scr.hide(); 8.156 +} 8.157 + 8.158 +int ui_visible() 8.159 +{ 8.160 + return scr.get_visibility() > 0.01; 8.161 +} 8.162 + 8.163 void ui_reshape(int x, int y) 8.164 { 8.165 width = x; 8.166 @@ -114,7 +159,7 @@ 8.167 glEnable(GL_BLEND); 8.168 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 8.169 8.170 - set_uniform_float4(prog_ui, "ucolor", 0, 0, 0, 0.5); 8.171 + set_uniform_float4(prog_ui, "ucolor", 0, 0, 0, 0.5 * scr.get_visibility()); 8.172 8.173 gl_begin(GL_QUADS); 8.174 //gl_color4f(0, 0, 0, 0.5); 8.175 @@ -152,3 +197,34 @@ 8.176 8.177 scr.sysev_mouse_motion(normx, normy); 8.178 } 8.179 + 8.180 + 8.181 +static void done_bn_handler(Widget *w, const Event &ev, void *cls) 8.182 +{ 8.183 + show_opt = 0; 8.184 + ui_hide(); 8.185 +} 8.186 + 8.187 +static void stereo_cbox_handler(Widget *w, const Event &ev, void *cls) 8.188 +{ 8.189 + stereo = ((CheckBox*)w)->is_checked() ? 1 : 0; 8.190 + 8.191 + if(stereo) { 8.192 + slider_split->activate(); 8.193 + label_split->activate(); 8.194 + } else { 8.195 + slider_split->deactivate(); 8.196 + label_split->deactivate(); 8.197 + } 8.198 +} 8.199 + 8.200 +static void bump_cbox_handler(Widget *w, const Event &ev, void *cls) 8.201 +{ 8.202 + use_bump = ((CheckBox*)w)->is_checked() ? 1 : 0; 8.203 +} 8.204 + 8.205 +static void split_slider_handler(Widget *w, const Event &ev, void *cls) 8.206 +{ 8.207 + split = ((Slider*)w)->get_value(); 8.208 +} 8.209 +
9.1 --- a/src/ui.h Tue Sep 29 01:11:54 2015 +0300 9.2 +++ b/src/ui.h Wed Sep 30 04:41:21 2015 +0300 9.3 @@ -8,6 +8,10 @@ 9.4 int ui_init(void); 9.5 void ui_shutdown(void); 9.6 9.7 +void ui_show(); 9.8 +void ui_hide(); 9.9 +int ui_visible(); 9.10 + 9.11 void ui_reshape(int x, int y); 9.12 void ui_draw(void); 9.13
10.1 --- a/src/uitheme.cc Tue Sep 29 01:11:54 2015 +0300 10.2 +++ b/src/uitheme.cc Wed Sep 30 04:41:21 2015 +0300 10.3 @@ -6,7 +6,7 @@ 10.4 #include "drawtext.h" 10.5 #include "sdr.h" 10.6 10.7 -#define BEVEL 1.0 10.8 +#define BEVEL 1.5 10.9 #define VIS_THRES 0.005 10.10 10.11 using namespace goatkit; 10.12 @@ -28,6 +28,10 @@ 10.13 TEXT_COLOR, 10.14 TOP_COLOR, 10.15 BOTTOM_COLOR, 10.16 + TOP_ON_COLOR, 10.17 + BOTTOM_ON_COLOR, 10.18 + TOP_OFF_COLOR, 10.19 + BOTTOM_OFF_COLOR, 10.20 BEVEL_LIT_COLOR, 10.21 BEVEL_SHAD_COLOR, 10.22 CURSOR_COLOR, 10.23 @@ -39,8 +43,12 @@ 10.24 Color(0.0, 0.0, 0.0, 1.0), /* text color */ 10.25 Color(0.75, 0.75, 0.75, 1.0), /* top color */ 10.26 Color(0.56, 0.56, 0.56, 1.0), /* bot color */ 10.27 + Color(0.4, 0.5, 0.8, 1.0), /* top on color */ 10.28 + Color(0.15, 0.2, 0.4, 1.0), /* bottom on color */ 10.29 + Color(0.8, 0.5, 0.4, 1.0), /* top off color */ 10.30 + Color(0.4, 0.2, 0.15, 1.0), /* bottom off color */ 10.31 Color(0.8, 0.8, 0.8, 1.0), /* lit bevel */ 10.32 - Color(0.35, 0.35, 0.35, 1.0), /* shadowed bevel */ 10.33 + Color(0.35, 0.35, 0.35, 1.0), /* shadowed bevel */ 10.34 Color(0.8, 0.25, 0.18, 1.0), /* cursor color */ 10.35 Color(0.68, 0.85, 1.3, 1.0), /* selection color */ 10.36 Color(0.75, 0.1, 0.095, 1.0) /* check color */ 10.37 @@ -60,10 +68,15 @@ 10.38 10.39 static void draw_label(const Widget *w); 10.40 static void draw_button(const Widget *w); 10.41 -static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &color); 10.42 -static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &ctop, const Color &cbot); 10.43 -static void draw_text(float justify, float x, float y, const char *text); 10.44 -static void draw_frame(const Vec2 &pos, const Vec2 &sz, float inset); 10.45 +static void draw_checkbox(const Widget *w); 10.46 +static void draw_slider(const Widget *w); 10.47 +static void draw_rect(const Widget *w, const Vec2 &pos, const Vec2 &sz, const Color &color); 10.48 +static void draw_rect(const Widget *w, const Vec2 &pos, const Vec2 &sz, const Color &ctop, const Color &cbot); 10.49 +static void draw_shadow_text(const Widget *w, float justify, float x, float y, const Color &col, const char *text, float press = 0.0); 10.50 +static void draw_shadow_text(const Widget *w, float justify, float x, float y, const char *text, float press = 0.0); 10.51 +static void draw_text(const Widget *w, float justify, float x, float y, const char *text); 10.52 +static void draw_frame(const Widget *w, const Vec2 &pos, const Vec2 &sz, float inset); 10.53 +static float lerp(float a, float b, float t); 10.54 static Color lerp(const Color &a, const Color &b, float t); 10.55 10.56 static struct { 10.57 @@ -72,6 +85,8 @@ 10.58 } widget_funcs[] = { 10.59 { "label", draw_label }, 10.60 { "button", draw_button }, 10.61 + { "checkbox", draw_checkbox }, 10.62 + { "slider", draw_slider }, 10.63 {0, 0} 10.64 }; 10.65 10.66 @@ -117,54 +132,126 @@ 10.67 static void draw_label(const Widget *w) 10.68 { 10.69 Vec2 pos = w->get_position(); 10.70 + Vec2 sz = w->get_size(); 10.71 float vis = w->get_visibility(); 10.72 if(vis < VIS_THRES) return; 10.73 10.74 begin_drawing(w); 10.75 - draw_text(JLEFT, pos.x, pos.y, w->get_text()); 10.76 + draw_shadow_text(w, JLEFT, pos.x, pos.y + sz.y / 2.0, w->get_text()); 10.77 end_drawing(w); 10.78 } 10.79 10.80 static void draw_button(const Widget *w) 10.81 { 10.82 + float vis = w->get_visibility(); 10.83 + if(vis < VIS_THRES) return; 10.84 + 10.85 Vec2 pos = w->get_position(); 10.86 Vec2 sz = w->get_size(); 10.87 - float vis = w->get_visibility(); 10.88 float press = w->get_pressed(); 10.89 - if(vis < VIS_THRES) return; 10.90 10.91 Color tcol = lerp(colors[TOP_COLOR], colors[BOTTOM_COLOR], press); 10.92 Color bcol = lerp(colors[BOTTOM_COLOR], colors[TOP_COLOR], press); 10.93 10.94 begin_drawing(w); 10.95 10.96 - draw_frame(pos, sz, press); 10.97 - draw_rect(pos, sz, tcol, bcol); 10.98 - //draw_rect(Vec2(pos.x + sz.x / 2.0 - 2.0, pos.y), Vec2(4.0, sz.y), 10.99 + draw_frame(w, pos, sz, press); 10.100 + draw_rect(w, pos, sz, tcol, bcol); 10.101 + //draw_rect(w, Vec2(pos.x + sz.x / 2.0 - 2.0, pos.y), Vec2(4.0, sz.y), 10.102 // Color(0.4, 0.5, 1.0)); 10.103 - draw_text(JCENTER, pos.x + sz.x / 2.0, pos.y, w->get_text()); 10.104 + draw_shadow_text(w, JCENTER, pos.x + sz.x / 2.0, pos.y + sz.y / 2.0, w->get_text(), press); 10.105 10.106 end_drawing(w); 10.107 } 10.108 10.109 -static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &color) 10.110 +static void draw_checkbox(const Widget *w) 10.111 { 10.112 - draw_rect(pos, sz, color, color); 10.113 + float vis = w->get_visibility(); 10.114 + if(vis < VIS_THRES) return; 10.115 + 10.116 + Vec2 pos = w->get_position(); 10.117 + Vec2 sz = w->get_size(); 10.118 + Vec2 boxsz = Vec2(sz.y * 3.0, sz.y); 10.119 + Vec2 boxpos = Vec2(pos.x + sz.x - boxsz.x, pos.y); 10.120 + 10.121 + float checked = ((CheckBox*)w)->get_checked(); 10.122 + 10.123 + float vcenter = boxpos.y + boxsz.y / 2.0; 10.124 + 10.125 + begin_drawing(w); 10.126 + 10.127 + draw_frame(w, boxpos, boxsz, 1.0); 10.128 + Color tcol = lerp(colors[TOP_OFF_COLOR], colors[TOP_ON_COLOR], checked); 10.129 + Color bcol = lerp(colors[BOTTOM_OFF_COLOR], colors[BOTTOM_ON_COLOR], checked); 10.130 + draw_rect(w, boxpos, boxsz, bcol, tcol); 10.131 + 10.132 + draw_shadow_text(w, JLEFT, boxpos.x + 2, vcenter, "ON", 0.0); 10.133 + draw_shadow_text(w, JRIGHT, boxpos.x + boxsz.x - 3, vcenter, "OFF", 0.0); 10.134 + 10.135 + Vec2 knobpos = Vec2(0, boxpos.y + 1.0); 10.136 + Vec2 knobsz = Vec2(boxsz.x / 2.0, boxsz.y - 2.0); 10.137 + 10.138 + knobpos.x = lerp(boxpos.x + 1.0, boxpos.x + boxsz.x / 2.0, checked); 10.139 + 10.140 + draw_frame(w, knobpos, knobsz, 0.0); 10.141 + draw_rect(w, knobpos, knobsz, colors[TOP_COLOR], colors[BOTTOM_COLOR]); 10.142 + 10.143 + draw_shadow_text(w, JRIGHT, boxpos.x - 2.0, vcenter, w->get_text(), 0.0); 10.144 + 10.145 + end_drawing(w); 10.146 } 10.147 10.148 -static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &ctop, const Color &cbot) 10.149 +static void draw_slider(const Widget *w) 10.150 { 10.151 + float vis = w->get_visibility(); 10.152 + if(vis < VIS_THRES) return; 10.153 + 10.154 + float nval = ((Slider*)w)->get_value_norm(); 10.155 + 10.156 + Vec2 pos = w->get_position(); 10.157 + Vec2 sz = w->get_size(); 10.158 + Vec2 tsz = Vec2(sz.y * 0.5, sz.y); 10.159 + Vec2 tpos = Vec2(pos.x + sz.x * nval - tsz.x / 2.0, pos.y); 10.160 + 10.161 + // modify original pos/size to correspond to the trough geometry 10.162 + sz.y /= 5.0; 10.163 + pos.y += sz.y * 2.0; 10.164 + 10.165 + begin_drawing(w); 10.166 + 10.167 + // draw trough 10.168 + draw_frame(w, pos, sz, 1.0); 10.169 + draw_rect(w, pos, sz, colors[BOTTOM_COLOR], colors[TOP_COLOR]); 10.170 + 10.171 + // draw thumb 10.172 + draw_frame(w, tpos, tsz, 0.0); 10.173 + draw_rect(w, tpos, tsz, colors[TOP_COLOR], colors[BOTTOM_COLOR]); 10.174 + 10.175 + end_drawing(w); 10.176 +} 10.177 + 10.178 +static void draw_rect(const Widget *w, const Vec2 &pos, const Vec2 &sz, const Color &color) 10.179 +{ 10.180 + draw_rect(w, pos, sz, color, color); 10.181 +} 10.182 + 10.183 +static void draw_rect(const Widget *w, const Vec2 &pos, const Vec2 &sz, const Color &ctop, const Color &cbot) 10.184 +{ 10.185 + float vis = w ? w->get_visibility() : 1.0; 10.186 + float act = w ? w->get_active() : 1.0; 10.187 float aspect = sz.x / sz.y; 10.188 10.189 + float alpha = vis * (act * 0.5 + 0.5); 10.190 + 10.191 bind_program(prog_color); 10.192 10.193 gl_begin(GL_QUADS); 10.194 - gl_color4f(cbot.r, cbot.g, cbot.b, cbot.a); 10.195 + gl_color4f(cbot.r, cbot.g, cbot.b, cbot.a * alpha); 10.196 gl_texcoord2f(0, 1); 10.197 gl_vertex3f(pos.x, pos.y, 0); 10.198 gl_texcoord2f(aspect, 1); 10.199 gl_vertex3f(pos.x + sz.x, pos.y, 0); 10.200 - gl_color4f(ctop.r, ctop.g, ctop.b, ctop.a); 10.201 + gl_color4f(ctop.r, ctop.g, ctop.b, ctop.a * alpha); 10.202 gl_texcoord2f(aspect, 0); 10.203 gl_vertex3f(pos.x + sz.x, pos.y + sz.y, 0); 10.204 gl_texcoord2f(0, 0); 10.205 @@ -172,21 +259,47 @@ 10.206 gl_end(); 10.207 } 10.208 10.209 -static void draw_text(float justify, float x, float y, const char *text) 10.210 +static void draw_shadow_text(const Widget *w, float justify, float x, float y, const Color &col, const char *text, float press) 10.211 +{ 10.212 + static const Color cshad = Color(0.1, 0.1, 0.1, 1.0); 10.213 + 10.214 + float xoffs = 1.0 - press; 10.215 + float yoffs = 1.0 - press; 10.216 + 10.217 + Color orig = colors[TEXT_COLOR]; 10.218 + colors[TEXT_COLOR] = cshad; 10.219 + colors[TEXT_COLOR].a = (1.0 - press); 10.220 + draw_text(w, justify, x + xoffs, y - yoffs, text); 10.221 + colors[TEXT_COLOR] = col; 10.222 + draw_text(w, justify, x, y, text); 10.223 + colors[TEXT_COLOR] = orig; 10.224 +} 10.225 + 10.226 +static void draw_shadow_text(const Widget *w, float justify, float x, float y, const char *text, float press) 10.227 +{ 10.228 + draw_shadow_text(w, justify, x, y, Color(1.0, 1.0, 1.0, 1.0), text, press); 10.229 +} 10.230 + 10.231 +static void draw_text(const Widget *w, float justify, float x, float y, const char *text) 10.232 { 10.233 struct dtx_glyphmap *gmap = dtx_get_font_glyphmap_idx(font, 0); 10.234 dtx_use_font(font, dtx_get_glyphmap_ptsize(gmap)); 10.235 10.236 + float vis = w ? w->get_visibility() : 1.0; 10.237 + float act = w ? w->get_active() : 1.0; 10.238 + 10.239 float twidth = dtx_string_width(text); 10.240 float thalf = twidth / 2.0; 10.241 + float theight = dtx_line_height(); 10.242 10.243 gl_matrix_mode(GL_MODELVIEW); 10.244 gl_push_matrix(); 10.245 gl_load_identity(); 10.246 - gl_translatef(x - thalf - justify * thalf, y + 8, 0); 10.247 + gl_translatef(x - thalf - justify * thalf, y - theight * 0.25, 0); 10.248 10.249 bind_program(prog_font); 10.250 - set_uniform_float4(prog_font, "ucolor", 1.0, 1.0, 1.0, 1.0); 10.251 + const Color &tcol = colors[TEXT_COLOR]; 10.252 + set_uniform_float4(prog_font, "ucolor", tcol.r, tcol.g, tcol.b, tcol.a * vis * (act * 0.5 + 0.5)); 10.253 gl_apply_xform(prog_font); 10.254 10.255 dtx_string(text); 10.256 @@ -195,8 +308,14 @@ 10.257 gl_pop_matrix(); 10.258 } 10.259 10.260 -static void draw_frame(const Vec2 &pos, const Vec2 &sz, float inset) 10.261 +static void draw_frame(const Widget *widget, const Vec2 &pos, const Vec2 &sz, float inset) 10.262 { 10.263 + float vis = widget ? widget->get_visibility() : 1.0; 10.264 + float act = widget ? widget->get_active() : 1.0; 10.265 + float offs = 300.0 * (1.0 - vis); 10.266 + 10.267 + float alpha = vis * (act * 0.5 + 0.5); 10.268 + 10.269 float x = pos.x - BEVEL; 10.270 float y = pos.y - BEVEL; 10.271 float w = sz.x + BEVEL * 2.0; 10.272 @@ -209,30 +328,35 @@ 10.273 bind_program(prog_color); 10.274 10.275 gl_begin(GL_QUADS); 10.276 - gl_color4f(tcol.r, tcol.g, tcol.b, tcol.a); 10.277 - gl_vertex2f(x + b, y + h - b); 10.278 - gl_vertex2f(x + w - b, y + h - b); 10.279 - gl_vertex2f(x + w, y + h); 10.280 - gl_vertex2f(x, y + h); 10.281 + gl_color4f(tcol.r, tcol.g, tcol.b, tcol.a * alpha); 10.282 + gl_vertex2f(x + b + offs, y + h - b); 10.283 + gl_vertex2f(x + w - b + offs, y + h - b); 10.284 + gl_vertex2f(x + w + offs, y + h); 10.285 + gl_vertex2f(x + offs, y + h); 10.286 10.287 - gl_vertex2f(x + b, y + b); 10.288 - gl_vertex2f(x, y); 10.289 - gl_vertex2f(x, y + h); 10.290 - gl_vertex2f(x + b, y + h - b); 10.291 + gl_vertex2f(x + b, y + b + offs); 10.292 + gl_vertex2f(x, y + offs); 10.293 + gl_vertex2f(x, y + h + offs); 10.294 + gl_vertex2f(x + b, y + h - b + offs); 10.295 10.296 - gl_color4f(bcol.r, bcol.g, bcol.b, bcol.a); 10.297 - gl_vertex2f(x, y); 10.298 - gl_vertex2f(x + b, y + b); 10.299 - gl_vertex2f(x + w - b, y + b); 10.300 - gl_vertex2f(x + w, y); 10.301 + gl_color4f(bcol.r, bcol.g, bcol.b, bcol.a * alpha); 10.302 + gl_vertex2f(x - offs, y); 10.303 + gl_vertex2f(x + b - offs, y + b); 10.304 + gl_vertex2f(x + w - b - offs, y + b); 10.305 + gl_vertex2f(x + w - offs, y); 10.306 10.307 - gl_vertex2f(x + w - b, y + b); 10.308 - gl_vertex2f(x + w, y); 10.309 - gl_vertex2f(x + w, y + h); 10.310 - gl_vertex2f(x + w - b, y + h - b); 10.311 + gl_vertex2f(x + w - b, y + b - offs); 10.312 + gl_vertex2f(x + w, y - offs); 10.313 + gl_vertex2f(x + w, y + h - offs); 10.314 + gl_vertex2f(x + w - b, y + h - b - offs); 10.315 gl_end(); 10.316 } 10.317 10.318 +static float lerp(float a, float b, float t) 10.319 +{ 10.320 + return a + (b - a) * t; 10.321 +} 10.322 + 10.323 static Color lerp(const Color &a, const Color &b, float t) 10.324 { 10.325 Color res;