# HG changeset patch # User John Tsiombikas # Date 1443577281 -10800 # Node ID 7bd4264bf74a6c77af4b293f62b03cf09a290f85 # Parent 018f997dc6461b3aa4a33022bcd1731398a917b3 gui done? diff -r 018f997dc646 -r 7bd4264bf74a libs/drawtext/font.c --- a/libs/drawtext/font.c Tue Sep 29 01:11:54 2015 +0300 +++ b/libs/drawtext/font.c Wed Sep 30 04:41:21 2015 +0300 @@ -153,14 +153,14 @@ void dtx_prepare(struct dtx_font *fnt, int sz) { if(!dtx_get_font_glyphmap_range(fnt, sz, 0, 256)) { - fprintf(stderr, "%s: failed (sz: %d, range: 0-255 [ascii])\n", __FUNCTION__, sz); + fprintf(stderr, "%s: failed (sz: %d, range: 0-255 [ascii])\n", __func__, sz); } } void dtx_prepare_range(struct dtx_font *fnt, int sz, int cstart, int cend) { if(!dtx_get_font_glyphmap_range(fnt, sz, cstart, cend)) { - fprintf(stderr, "%s: failed (sz: %d, range: %d-%d)\n", __FUNCTION__, sz, cstart, cend); + fprintf(stderr, "%s: failed (sz: %d, range: %d-%d)\n", __func__, sz, cstart, cend); } } @@ -437,7 +437,7 @@ } } else { - fprintf(stderr, "%s: invalid glyph info line\n", __FUNCTION__); + fprintf(stderr, "%s: invalid glyph info line\n", __func__); goto err; } @@ -445,14 +445,14 @@ switch(hdr_lines) { case 0: if(0[line] != 'P' || 1[line] != '6') { - fprintf(stderr, "%s: invalid file format (magic)\n", __FUNCTION__); + fprintf(stderr, "%s: invalid file format (magic)\n", __func__); goto err; } break; case 1: if(sscanf(line, "%d %d", &gmap->xsz, &gmap->ysz) != 2) { - fprintf(stderr, "%s: invalid file format (dim)\n", __FUNCTION__); + fprintf(stderr, "%s: invalid file format (dim)\n", __func__); goto err; } break; @@ -462,7 +462,7 @@ char *endp; max_pixval = strtol(line, &endp, 10); if(endp == line) { - fprintf(stderr, "%s: invalid file format (maxval)\n", __FUNCTION__); + fprintf(stderr, "%s: invalid file format (maxval)\n", __func__); goto err; } } @@ -476,7 +476,7 @@ } if(gmap->ptsize == -1 || gmap->line_advance == FLT_MIN) { - fprintf(stderr, "%s: invalid glyphmap, insufficient information in ppm comments\n", __FUNCTION__); + fprintf(stderr, "%s: invalid glyphmap, insufficient information in ppm comments\n", __func__); goto err; } @@ -540,7 +540,7 @@ int res; if(!(fp = fopen(fname, "wb"))) { - fprintf(stderr, "%s: failed to open file: %s: %s\n", __FUNCTION__, fname, strerror(errno)); + fprintf(stderr, "%s: failed to open file: %s: %s\n", __func__, fname, strerror(errno)); return -1; } res = dtx_save_glyphmap_stream(fp, gmap); diff -r 018f997dc646 -r 7bd4264bf74a libs/goatkit/checkbox.cc --- a/libs/goatkit/checkbox.cc Tue Sep 29 01:11:54 2015 +0300 +++ b/libs/goatkit/checkbox.cc Wed Sep 30 04:41:21 2015 +0300 @@ -71,6 +71,16 @@ } } +void CheckBox::set_toggle_transition(long msec) +{ + cbox->checked.set_transition_duration(msec); +} + +long CheckBox::get_toggle_transition() const +{ + return cbox->checked.get_transition_duration(); +} + void CheckBox::on_click() { toggle(); diff -r 018f997dc646 -r 7bd4264bf74a libs/goatkit/checkbox.h --- a/libs/goatkit/checkbox.h Tue Sep 29 01:11:54 2015 +0300 +++ b/libs/goatkit/checkbox.h Wed Sep 30 04:41:21 2015 +0300 @@ -39,6 +39,8 @@ virtual float get_checked() const; virtual bool is_checked() const; virtual void toggle(); + virtual void set_toggle_transition(long msec); + virtual long get_toggle_transition() const; virtual void on_click(); }; diff -r 018f997dc646 -r 7bd4264bf74a libs/goatkit/screen.cc --- a/libs/goatkit/screen.cc Tue Sep 29 01:11:54 2015 +0300 +++ b/libs/goatkit/screen.cc Wed Sep 30 04:41:21 2015 +0300 @@ -21,13 +21,14 @@ #include #include "screen.h" #include "widget.h" +#include "boolanm.h" #define MAX_BUTTONS 16 namespace goatkit { struct ScreenImpl { - bool visible; + BoolAnim visible; std::vector widgets; BBox box; @@ -137,7 +138,7 @@ void Screen::show() { - scr->visible = true; + scr->visible.change(true); for(size_t i=0; iwidgets.size(); i++) { scr->widgets[i]->show(); @@ -146,7 +147,7 @@ void Screen::hide() { - scr->visible = false; + scr->visible.change(false); for(size_t i=0; iwidgets.size(); i++) { scr->widgets[i]->hide(); @@ -158,6 +159,24 @@ return scr->visible; } +float Screen::get_visibility() const +{ + return scr->visible.get_value(); +} + +void Screen::set_visibility_transition(long msec) +{ + scr->visible.set_transition_duration(msec); + for(size_t i=0; iwidgets.size(); i++) { + scr->widgets[i]->set_visibility_transition(msec); + } +} + +long Screen::get_visibility_transition() const +{ + return scr->visible.get_transition_duration(); +} + bool Screen::grab_mouse(Widget *w) { if(!scr->mgrab || !w) { diff -r 018f997dc646 -r 7bd4264bf74a libs/goatkit/screen.h --- a/libs/goatkit/screen.h Tue Sep 29 01:11:54 2015 +0300 +++ b/libs/goatkit/screen.h Wed Sep 30 04:41:21 2015 +0300 @@ -49,6 +49,9 @@ void show(); void hide(); bool is_visible() const; + float get_visibility() const; + void set_visibility_transition(long msec); + long get_visibility_transition() const; bool grab_mouse(Widget *w); diff -r 018f997dc646 -r 7bd4264bf74a libs/goatkit/widget.cc --- a/libs/goatkit/widget.cc Tue Sep 29 01:11:54 2015 +0300 +++ b/libs/goatkit/widget.cc Wed Sep 30 04:41:21 2015 +0300 @@ -161,7 +161,7 @@ long Widget::get_active_transition() const { - widget->active.get_transition_duration(); + return widget->active.get_transition_duration(); } void Widget::press() diff -r 018f997dc646 -r 7bd4264bf74a src/istereo.c --- a/src/istereo.c Tue Sep 29 01:11:54 2015 +0300 +++ b/src/istereo.c Wed Sep 30 04:41:21 2015 +0300 @@ -34,6 +34,8 @@ #include "drawtext.h" #include "timer.h" +#undef STEREO_GUI + static void render(float t); static void draw_tunnel(float t); static void tunnel_vertex(float u, float v, float du, float dv, int tang_loc, float t); @@ -100,12 +102,11 @@ return -1; } - if(!(font = dtx_open_font_glyphmap(find_resource("linux-libertine_s24.glyphmap", 0, 0)))) { + if(!(font = dtx_open_font_glyphmap(find_resource("droidsans_s24.glyphmap", 0, 0)))) { fprintf(stderr, "failed to load font\n"); return -1; } dtx_vertex_attribs(get_attrib_loc(prog_ui, "attr_vertex"), get_attrib_loc(prog_ui, "attr_texcoord")); - dtx_use_font(font, 24); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); @@ -113,6 +114,9 @@ if(ui_init() == -1) { return -1; } + if(show_opt) { + ui_show(); + } cam_fov(42.5); cam_clip(0.5, 250.0); @@ -199,19 +203,12 @@ render(tsec); } - /* TEST */ - /*bind_program(prog_ui); - - gl_matrix_mode(GL_PROJECTION); - gl_load_identity(); - gl_ortho(0, view_xsz, 0, view_ysz, -1, 1); - gl_matrix_mode(GL_MODELVIEW); - gl_load_identity(); - gl_apply_xform(prog_ui); - - glDisable(GL_DEPTH_TEST); - dtx_printf("hello world\n"); - glEnable(GL_DEPTH_TEST);*/ +#ifndef STEREO_GUI + if(ui_visible()) { + glViewport(0, 0, view_xsz, view_ysz); + ui_draw(); + } +#endif assert(glGetError() == GL_NO_ERROR); } @@ -233,9 +230,12 @@ glDepthMask(1); } - if(show_opt) { +#ifdef STEREO_GUI + if(ui_visible()) { + ui_reshape(stereo ? view_xsz / 2.0 : view_xsz, view_ysz); ui_draw(); } +#endif } static void draw_tunnel(float t) @@ -418,6 +418,11 @@ { if(show_opt) { ui_button(bn, press, x, y); + } else { + if(press) { + show_opt = 1; + ui_show(); + } } } diff -r 018f997dc646 -r 7bd4264bf74a src/ui.cc --- a/src/ui.cc Tue Sep 29 01:11:54 2015 +0300 +++ b/src/ui.cc Wed Sep 30 04:41:21 2015 +0300 @@ -7,76 +7,106 @@ using namespace goatkit; -static void done_bn_handler(Widget *w, const Event &ev, void *cls) -{ - printf("done\n"); -} +extern int stereo; +extern int show_opt; +extern int use_bump; +extern float split; -static goatkit::Screen scr; +static void done_bn_handler(Widget *w, const Event &ev, void *cls); +static void stereo_cbox_handler(Widget *w, const Event &ev, void *cls); +static void bump_cbox_handler(Widget *w, const Event &ev, void *cls); +static void split_slider_handler(Widget *w, const Event &ev, void *cls); + +static Screen scr; static float aspect; static int width, height; static int virt_width, virt_height; +static Slider *slider_split; +static Label *label_split; extern unsigned int prog_color, prog_ui; int ui_init(void) { - float xpos = 100; - float ypos = 50; - float vsep = 50; + float ypos = 300; + float vsep = 70; + float vsz = 35; - /*goatkit::Label *label = new goatkit::Label; - label->set_position(xpos, ypos); - label->set_size(20, 20); - label->set_text("Stereoscopic rendering"); - scr.add_widget(label);*/ + CheckBox *cbox = new CheckBox; + cbox->set_position(300, ypos); + cbox->set_size(300, vsz); + cbox->set_text("Stereoscopic rendering"); + cbox->set_callback(EV_CHANGE, stereo_cbox_handler); + //cbox->set_toggle_transition(80); + scr.add_widget(cbox); + ypos -= vsep; - goatkit::Button *button = new goatkit::Button; - button->set_position(xpos, ypos); - button->set_size(80, 30); + label_split = new Label; + label_split->set_position(170, ypos); + label_split->set_size(20, vsz); + label_split->set_text("Stereo split"); + if(!stereo) label_split->deactivate(); + scr.add_widget(label_split); + + slider_split = new Slider; + slider_split->set_position(300, ypos); + slider_split->set_size(300, vsz); + slider_split->set_callback(EV_CHANGE, split_slider_handler); + slider_split->set_continuous_change(true); + slider_split->set_range(0, 1.0); + slider_split->set_value(split); + if(!stereo) slider_split->deactivate(); + scr.add_widget(slider_split); + ypos -= vsep; + + cbox = new CheckBox; + cbox->set_position(300, ypos); + cbox->set_size(300, vsz); + cbox->set_text("Bump mapping"); + cbox->set_callback(EV_CHANGE, bump_cbox_handler); + scr.add_widget(cbox); + ypos -= vsep; + + ypos -= vsep * 0.5; + Button *button = new Button; + button->set_position(450, ypos); + button->set_size(150, vsz); button->set_text("Done"); - button->set_callback(goatkit::EV_CLICK, done_bn_handler); + button->set_callback(EV_CLICK, done_bn_handler); scr.add_widget(button); + ypos -= vsep; /* - goatkit::TextBox *text = new goatkit::TextBox; + TextBox *text = new TextBox; text->set_position(300, ypos += vsep); text->set_size(200, 30); text->set_text("foo"); - text->set_callback(goatkit::EV_CHANGE, callback); + text->set_callback(EV_CHANGE, callback); scr.add_widget(text); - goatkit::CheckBox *cbox = new goatkit::CheckBox; + CheckBox *cbox = new CheckBox; cbox->set_position(300, ypos += vsep); cbox->set_size(200, 20); cbox->set_text("a checkbox!"); - cbox->set_callback(goatkit::EV_CHANGE, callback); + cbox->set_callback(EV_CHANGE, callback); scr.add_widget(cbox); - goatkit::Slider *slider = new goatkit::Slider; - slider->set_position(300, ypos += vsep); - slider->set_size(200, 40); - slider->set_callback(goatkit::EV_CHANGE, callback); - slider->set_continuous_change(false); - slider->set_range(0, 100.0); - scr.add_widget(slider); - - goatkit::Slider *intslider = new goatkit::Slider; + Slider *intslider = new Slider; intslider->set_position(300, ypos += vsep); intslider->set_size(200, 40); - intslider->set_callback(goatkit::EV_CHANGE, callback); + intslider->set_callback(EV_CHANGE, callback); intslider->set_continuous_change(false); intslider->set_range(0, 100.0); intslider->set_step(10); scr.add_widget(intslider); */ - scr.show(); + scr.set_visibility_transition(400); // load the theme - //goatkit::add_theme_path("themes/simple"); + //add_theme_path("themes/simple"); - if(!(goatkit::theme = goatkit::get_theme("istereo"))) { + if(!(theme = get_theme("istereo"))) { return -1; } @@ -87,6 +117,21 @@ { } +void ui_show() +{ + scr.show(); +} + +void ui_hide() +{ + scr.hide(); +} + +int ui_visible() +{ + return scr.get_visibility() > 0.01; +} + void ui_reshape(int x, int y) { width = x; @@ -114,7 +159,7 @@ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - set_uniform_float4(prog_ui, "ucolor", 0, 0, 0, 0.5); + set_uniform_float4(prog_ui, "ucolor", 0, 0, 0, 0.5 * scr.get_visibility()); gl_begin(GL_QUADS); //gl_color4f(0, 0, 0, 0.5); @@ -152,3 +197,34 @@ scr.sysev_mouse_motion(normx, normy); } + + +static void done_bn_handler(Widget *w, const Event &ev, void *cls) +{ + show_opt = 0; + ui_hide(); +} + +static void stereo_cbox_handler(Widget *w, const Event &ev, void *cls) +{ + stereo = ((CheckBox*)w)->is_checked() ? 1 : 0; + + if(stereo) { + slider_split->activate(); + label_split->activate(); + } else { + slider_split->deactivate(); + label_split->deactivate(); + } +} + +static void bump_cbox_handler(Widget *w, const Event &ev, void *cls) +{ + use_bump = ((CheckBox*)w)->is_checked() ? 1 : 0; +} + +static void split_slider_handler(Widget *w, const Event &ev, void *cls) +{ + split = ((Slider*)w)->get_value(); +} + diff -r 018f997dc646 -r 7bd4264bf74a src/ui.h --- a/src/ui.h Tue Sep 29 01:11:54 2015 +0300 +++ b/src/ui.h Wed Sep 30 04:41:21 2015 +0300 @@ -8,6 +8,10 @@ int ui_init(void); void ui_shutdown(void); +void ui_show(); +void ui_hide(); +int ui_visible(); + void ui_reshape(int x, int y); void ui_draw(void); diff -r 018f997dc646 -r 7bd4264bf74a src/uitheme.cc --- a/src/uitheme.cc Tue Sep 29 01:11:54 2015 +0300 +++ b/src/uitheme.cc Wed Sep 30 04:41:21 2015 +0300 @@ -6,7 +6,7 @@ #include "drawtext.h" #include "sdr.h" -#define BEVEL 1.0 +#define BEVEL 1.5 #define VIS_THRES 0.005 using namespace goatkit; @@ -28,6 +28,10 @@ TEXT_COLOR, TOP_COLOR, BOTTOM_COLOR, + TOP_ON_COLOR, + BOTTOM_ON_COLOR, + TOP_OFF_COLOR, + BOTTOM_OFF_COLOR, BEVEL_LIT_COLOR, BEVEL_SHAD_COLOR, CURSOR_COLOR, @@ -39,8 +43,12 @@ Color(0.0, 0.0, 0.0, 1.0), /* text color */ Color(0.75, 0.75, 0.75, 1.0), /* top color */ Color(0.56, 0.56, 0.56, 1.0), /* bot color */ + Color(0.4, 0.5, 0.8, 1.0), /* top on color */ + Color(0.15, 0.2, 0.4, 1.0), /* bottom on color */ + Color(0.8, 0.5, 0.4, 1.0), /* top off color */ + Color(0.4, 0.2, 0.15, 1.0), /* bottom off color */ Color(0.8, 0.8, 0.8, 1.0), /* lit bevel */ - Color(0.35, 0.35, 0.35, 1.0), /* shadowed bevel */ + Color(0.35, 0.35, 0.35, 1.0), /* shadowed bevel */ Color(0.8, 0.25, 0.18, 1.0), /* cursor color */ Color(0.68, 0.85, 1.3, 1.0), /* selection color */ Color(0.75, 0.1, 0.095, 1.0) /* check color */ @@ -60,10 +68,15 @@ static void draw_label(const Widget *w); static void draw_button(const Widget *w); -static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &color); -static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &ctop, const Color &cbot); -static void draw_text(float justify, float x, float y, const char *text); -static void draw_frame(const Vec2 &pos, const Vec2 &sz, float inset); +static void draw_checkbox(const Widget *w); +static void draw_slider(const Widget *w); +static void draw_rect(const Widget *w, const Vec2 &pos, const Vec2 &sz, const Color &color); +static void draw_rect(const Widget *w, const Vec2 &pos, const Vec2 &sz, const Color &ctop, const Color &cbot); +static void draw_shadow_text(const Widget *w, float justify, float x, float y, const Color &col, const char *text, float press = 0.0); +static void draw_shadow_text(const Widget *w, float justify, float x, float y, const char *text, float press = 0.0); +static void draw_text(const Widget *w, float justify, float x, float y, const char *text); +static void draw_frame(const Widget *w, const Vec2 &pos, const Vec2 &sz, float inset); +static float lerp(float a, float b, float t); static Color lerp(const Color &a, const Color &b, float t); static struct { @@ -72,6 +85,8 @@ } widget_funcs[] = { { "label", draw_label }, { "button", draw_button }, + { "checkbox", draw_checkbox }, + { "slider", draw_slider }, {0, 0} }; @@ -117,54 +132,126 @@ static void draw_label(const Widget *w) { Vec2 pos = w->get_position(); + Vec2 sz = w->get_size(); float vis = w->get_visibility(); if(vis < VIS_THRES) return; begin_drawing(w); - draw_text(JLEFT, pos.x, pos.y, w->get_text()); + draw_shadow_text(w, JLEFT, pos.x, pos.y + sz.y / 2.0, w->get_text()); end_drawing(w); } static void draw_button(const Widget *w) { + float vis = w->get_visibility(); + if(vis < VIS_THRES) return; + Vec2 pos = w->get_position(); Vec2 sz = w->get_size(); - float vis = w->get_visibility(); float press = w->get_pressed(); - if(vis < VIS_THRES) return; Color tcol = lerp(colors[TOP_COLOR], colors[BOTTOM_COLOR], press); Color bcol = lerp(colors[BOTTOM_COLOR], colors[TOP_COLOR], press); begin_drawing(w); - draw_frame(pos, sz, press); - draw_rect(pos, sz, tcol, bcol); - //draw_rect(Vec2(pos.x + sz.x / 2.0 - 2.0, pos.y), Vec2(4.0, sz.y), + draw_frame(w, pos, sz, press); + draw_rect(w, pos, sz, tcol, bcol); + //draw_rect(w, Vec2(pos.x + sz.x / 2.0 - 2.0, pos.y), Vec2(4.0, sz.y), // Color(0.4, 0.5, 1.0)); - draw_text(JCENTER, pos.x + sz.x / 2.0, pos.y, w->get_text()); + draw_shadow_text(w, JCENTER, pos.x + sz.x / 2.0, pos.y + sz.y / 2.0, w->get_text(), press); end_drawing(w); } -static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &color) +static void draw_checkbox(const Widget *w) { - draw_rect(pos, sz, color, color); + float vis = w->get_visibility(); + if(vis < VIS_THRES) return; + + Vec2 pos = w->get_position(); + Vec2 sz = w->get_size(); + Vec2 boxsz = Vec2(sz.y * 3.0, sz.y); + Vec2 boxpos = Vec2(pos.x + sz.x - boxsz.x, pos.y); + + float checked = ((CheckBox*)w)->get_checked(); + + float vcenter = boxpos.y + boxsz.y / 2.0; + + begin_drawing(w); + + draw_frame(w, boxpos, boxsz, 1.0); + Color tcol = lerp(colors[TOP_OFF_COLOR], colors[TOP_ON_COLOR], checked); + Color bcol = lerp(colors[BOTTOM_OFF_COLOR], colors[BOTTOM_ON_COLOR], checked); + draw_rect(w, boxpos, boxsz, bcol, tcol); + + draw_shadow_text(w, JLEFT, boxpos.x + 2, vcenter, "ON", 0.0); + draw_shadow_text(w, JRIGHT, boxpos.x + boxsz.x - 3, vcenter, "OFF", 0.0); + + Vec2 knobpos = Vec2(0, boxpos.y + 1.0); + Vec2 knobsz = Vec2(boxsz.x / 2.0, boxsz.y - 2.0); + + knobpos.x = lerp(boxpos.x + 1.0, boxpos.x + boxsz.x / 2.0, checked); + + draw_frame(w, knobpos, knobsz, 0.0); + draw_rect(w, knobpos, knobsz, colors[TOP_COLOR], colors[BOTTOM_COLOR]); + + draw_shadow_text(w, JRIGHT, boxpos.x - 2.0, vcenter, w->get_text(), 0.0); + + end_drawing(w); } -static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &ctop, const Color &cbot) +static void draw_slider(const Widget *w) { + float vis = w->get_visibility(); + if(vis < VIS_THRES) return; + + float nval = ((Slider*)w)->get_value_norm(); + + Vec2 pos = w->get_position(); + Vec2 sz = w->get_size(); + Vec2 tsz = Vec2(sz.y * 0.5, sz.y); + Vec2 tpos = Vec2(pos.x + sz.x * nval - tsz.x / 2.0, pos.y); + + // modify original pos/size to correspond to the trough geometry + sz.y /= 5.0; + pos.y += sz.y * 2.0; + + begin_drawing(w); + + // draw trough + draw_frame(w, pos, sz, 1.0); + draw_rect(w, pos, sz, colors[BOTTOM_COLOR], colors[TOP_COLOR]); + + // draw thumb + draw_frame(w, tpos, tsz, 0.0); + draw_rect(w, tpos, tsz, colors[TOP_COLOR], colors[BOTTOM_COLOR]); + + end_drawing(w); +} + +static void draw_rect(const Widget *w, const Vec2 &pos, const Vec2 &sz, const Color &color) +{ + draw_rect(w, pos, sz, color, color); +} + +static void draw_rect(const Widget *w, const Vec2 &pos, const Vec2 &sz, const Color &ctop, const Color &cbot) +{ + float vis = w ? w->get_visibility() : 1.0; + float act = w ? w->get_active() : 1.0; float aspect = sz.x / sz.y; + float alpha = vis * (act * 0.5 + 0.5); + bind_program(prog_color); gl_begin(GL_QUADS); - gl_color4f(cbot.r, cbot.g, cbot.b, cbot.a); + gl_color4f(cbot.r, cbot.g, cbot.b, cbot.a * alpha); gl_texcoord2f(0, 1); gl_vertex3f(pos.x, pos.y, 0); gl_texcoord2f(aspect, 1); gl_vertex3f(pos.x + sz.x, pos.y, 0); - gl_color4f(ctop.r, ctop.g, ctop.b, ctop.a); + gl_color4f(ctop.r, ctop.g, ctop.b, ctop.a * alpha); gl_texcoord2f(aspect, 0); gl_vertex3f(pos.x + sz.x, pos.y + sz.y, 0); gl_texcoord2f(0, 0); @@ -172,21 +259,47 @@ gl_end(); } -static void draw_text(float justify, float x, float y, const char *text) +static void draw_shadow_text(const Widget *w, float justify, float x, float y, const Color &col, const char *text, float press) +{ + static const Color cshad = Color(0.1, 0.1, 0.1, 1.0); + + float xoffs = 1.0 - press; + float yoffs = 1.0 - press; + + Color orig = colors[TEXT_COLOR]; + colors[TEXT_COLOR] = cshad; + colors[TEXT_COLOR].a = (1.0 - press); + draw_text(w, justify, x + xoffs, y - yoffs, text); + colors[TEXT_COLOR] = col; + draw_text(w, justify, x, y, text); + colors[TEXT_COLOR] = orig; +} + +static void draw_shadow_text(const Widget *w, float justify, float x, float y, const char *text, float press) +{ + draw_shadow_text(w, justify, x, y, Color(1.0, 1.0, 1.0, 1.0), text, press); +} + +static void draw_text(const Widget *w, float justify, float x, float y, const char *text) { struct dtx_glyphmap *gmap = dtx_get_font_glyphmap_idx(font, 0); dtx_use_font(font, dtx_get_glyphmap_ptsize(gmap)); + float vis = w ? w->get_visibility() : 1.0; + float act = w ? w->get_active() : 1.0; + float twidth = dtx_string_width(text); float thalf = twidth / 2.0; + float theight = dtx_line_height(); gl_matrix_mode(GL_MODELVIEW); gl_push_matrix(); gl_load_identity(); - gl_translatef(x - thalf - justify * thalf, y + 8, 0); + gl_translatef(x - thalf - justify * thalf, y - theight * 0.25, 0); bind_program(prog_font); - set_uniform_float4(prog_font, "ucolor", 1.0, 1.0, 1.0, 1.0); + const Color &tcol = colors[TEXT_COLOR]; + set_uniform_float4(prog_font, "ucolor", tcol.r, tcol.g, tcol.b, tcol.a * vis * (act * 0.5 + 0.5)); gl_apply_xform(prog_font); dtx_string(text); @@ -195,8 +308,14 @@ gl_pop_matrix(); } -static void draw_frame(const Vec2 &pos, const Vec2 &sz, float inset) +static void draw_frame(const Widget *widget, const Vec2 &pos, const Vec2 &sz, float inset) { + float vis = widget ? widget->get_visibility() : 1.0; + float act = widget ? widget->get_active() : 1.0; + float offs = 300.0 * (1.0 - vis); + + float alpha = vis * (act * 0.5 + 0.5); + float x = pos.x - BEVEL; float y = pos.y - BEVEL; float w = sz.x + BEVEL * 2.0; @@ -209,30 +328,35 @@ bind_program(prog_color); gl_begin(GL_QUADS); - gl_color4f(tcol.r, tcol.g, tcol.b, tcol.a); - gl_vertex2f(x + b, y + h - b); - gl_vertex2f(x + w - b, y + h - b); - gl_vertex2f(x + w, y + h); - gl_vertex2f(x, y + h); + gl_color4f(tcol.r, tcol.g, tcol.b, tcol.a * alpha); + gl_vertex2f(x + b + offs, y + h - b); + gl_vertex2f(x + w - b + offs, y + h - b); + gl_vertex2f(x + w + offs, y + h); + gl_vertex2f(x + offs, y + h); - gl_vertex2f(x + b, y + b); - gl_vertex2f(x, y); - gl_vertex2f(x, y + h); - gl_vertex2f(x + b, y + h - b); + gl_vertex2f(x + b, y + b + offs); + gl_vertex2f(x, y + offs); + gl_vertex2f(x, y + h + offs); + gl_vertex2f(x + b, y + h - b + offs); - gl_color4f(bcol.r, bcol.g, bcol.b, bcol.a); - gl_vertex2f(x, y); - gl_vertex2f(x + b, y + b); - gl_vertex2f(x + w - b, y + b); - gl_vertex2f(x + w, y); + gl_color4f(bcol.r, bcol.g, bcol.b, bcol.a * alpha); + gl_vertex2f(x - offs, y); + gl_vertex2f(x + b - offs, y + b); + gl_vertex2f(x + w - b - offs, y + b); + gl_vertex2f(x + w - offs, y); - gl_vertex2f(x + w - b, y + b); - gl_vertex2f(x + w, y); - gl_vertex2f(x + w, y + h); - gl_vertex2f(x + w - b, y + h - b); + gl_vertex2f(x + w - b, y + b - offs); + gl_vertex2f(x + w, y - offs); + gl_vertex2f(x + w, y + h - offs); + gl_vertex2f(x + w - b, y + h - b - offs); gl_end(); } +static float lerp(float a, float b, float t) +{ + return a + (b - a) * t; +} + static Color lerp(const Color &a, const Color &b, float t) { Color res;