# HG changeset patch # User John Tsiombikas # Date 1443478314 -10800 # Node ID 018f997dc6461b3aa4a33022bcd1731398a917b3 # Parent ea928c313344a6fe781facff81905ee8cb157555 button done diff -r ea928c313344 -r 018f997dc646 Makefile --- a/Makefile Mon Sep 28 19:04:50 2015 +0300 +++ b/Makefile Tue Sep 29 01:11:54 2015 +0300 @@ -22,7 +22,8 @@ endif $(bin): $(obj) - $(CXX) -o $@ $(obj) $(LDFLAGS) + @echo "Linking $(bin) ..." + @$(CXX) -o $@ $(obj) $(LDFLAGS) -include $(dep) diff -r ea928c313344 -r 018f997dc646 libs/goatkit/boolanm.cc --- a/libs/goatkit/boolanm.cc Mon Sep 28 19:04:50 2015 +0300 +++ b/libs/goatkit/boolanm.cc Tue Sep 29 01:11:54 2015 +0300 @@ -54,6 +54,11 @@ trans_dur = dur; } +long BoolAnim::get_transition_duration() const +{ + return trans_dur; +} + void BoolAnim::set_time_callback(long (*time_func)()) { get_msec = time_func; diff -r ea928c313344 -r 018f997dc646 libs/goatkit/boolanm.h --- a/libs/goatkit/boolanm.h Mon Sep 28 19:04:50 2015 +0300 +++ b/libs/goatkit/boolanm.h Tue Sep 29 01:11:54 2015 +0300 @@ -33,6 +33,8 @@ BoolAnim(bool st = false); void set_transition_duration(long dur); + long get_transition_duration() const; + void set_time_callback(long (*time_func)()); void set(bool st); diff -r ea928c313344 -r 018f997dc646 libs/goatkit/widget.cc --- a/libs/goatkit/widget.cc Mon Sep 28 19:04:50 2015 +0300 +++ b/libs/goatkit/widget.cc Tue Sep 29 01:11:54 2015 +0300 @@ -124,6 +124,16 @@ return widget->visible.get_state(); } +void Widget::set_visibility_transition(long msec) +{ + widget->visible.set_transition_duration(msec); +} + +long Widget::get_visibility_transition() const +{ + return widget->visible.get_transition_duration(); +} + void Widget::activate() { widget->active.change(true); @@ -144,6 +154,16 @@ return widget->active.get_state(); } +void Widget::set_active_transition(long msec) +{ + widget->active.set_transition_duration(msec); +} + +long Widget::get_active_transition() const +{ + widget->active.get_transition_duration(); +} + void Widget::press() { widget->press.change(true); @@ -164,6 +184,16 @@ return widget->press.get_state(); } +void Widget::set_press_transition(long msec) +{ + widget->press.set_transition_duration(msec); +} + +long Widget::get_press_transition() const +{ + return widget->press.get_transition_duration(); +} + void Widget::mousein() { widget->hover.change(true); @@ -187,6 +217,16 @@ return widget->hover.get_state(); } +void Widget::set_hover_transition(long msec) +{ + widget->hover.set_transition_duration(msec); +} + +long Widget::get_hover_transition() const +{ + return widget->hover.get_transition_duration(); +} + bool Widget::can_focus() const { return false; @@ -212,6 +252,16 @@ return widget->focus.get_state(); } +void Widget::set_focus_transition(long msec) +{ + widget->focus.set_transition_duration(msec); +} + +long Widget::get_focus_transition() const +{ + return widget->focus.get_transition_duration(); +} + void Widget::set_position(float x, float y) { set_position(Vec2(x, y)); diff -r ea928c313344 -r 018f997dc646 libs/goatkit/widget.h --- a/libs/goatkit/widget.h Mon Sep 28 19:04:50 2015 +0300 +++ b/libs/goatkit/widget.h Tue Sep 29 01:11:54 2015 +0300 @@ -56,21 +56,29 @@ virtual void hide(); virtual float get_visibility() const; virtual bool is_visible() const; + virtual void set_visibility_transition(long msec); + virtual long get_visibility_transition() const; virtual void activate(); virtual void deactivate(); virtual float get_active() const; virtual bool is_active() const; + virtual void set_active_transition(long msec); + virtual long get_active_transition() const; virtual void press(); virtual void release(); virtual float get_pressed() const; virtual bool is_pressed() const; + virtual void set_press_transition(long msec); + virtual long get_press_transition() const; virtual void mousein(); virtual void mouseout(); virtual float get_under_mouse() const; virtual bool is_under_mouse() const; + virtual void set_hover_transition(long msec); + virtual long get_hover_transition() const; // input focus, managed by the screen virtual bool can_focus() const; @@ -78,6 +86,8 @@ virtual void focusout(); virtual float get_focus() const; virtual bool is_focused() const; + virtual void set_focus_transition(long msec); + virtual long get_focus_transition() const; virtual void set_position(float x, float y); virtual void set_position(const Vec2 &pos); diff -r ea928c313344 -r 018f997dc646 src/ui.cc --- a/src/ui.cc Mon Sep 28 19:04:50 2015 +0300 +++ b/src/ui.cc Tue Sep 29 01:11:54 2015 +0300 @@ -15,24 +15,25 @@ static goatkit::Screen scr; static float aspect; static int width, height; +static int virt_width, virt_height; extern unsigned int prog_color, prog_ui; int ui_init(void) { - float xpos = 0.25; - float ypos = 0.8; - float vsep = 0.1; + float xpos = 100; + float ypos = 50; + float vsep = 50; /*goatkit::Label *label = new goatkit::Label; label->set_position(xpos, ypos); - label->set_size(0.1, 0.1); + label->set_size(20, 20); label->set_text("Stereoscopic rendering"); scr.add_widget(label);*/ goatkit::Button *button = new goatkit::Button; button->set_position(xpos, ypos); - button->set_size(0.2, 0.1); + button->set_size(80, 30); button->set_text("Done"); button->set_callback(goatkit::EV_CLICK, done_bn_handler); scr.add_widget(button); @@ -91,6 +92,9 @@ width = x; height = y; aspect = (float)width / (float)height; + + virt_width = 500.0 * aspect; + virt_height = 500.0; } void ui_draw(void) @@ -100,8 +104,7 @@ gl_matrix_mode(GL_PROJECTION); gl_push_matrix(); gl_load_identity(); - gl_scalef(2.0 / aspect, 2.0, 1); - gl_translatef(-1, -1, 0); + gl_ortho(0, virt_width, 0, virt_height, -1, 1); gl_matrix_mode(GL_MODELVIEW); gl_push_matrix(); gl_load_identity(); @@ -116,9 +119,9 @@ gl_begin(GL_QUADS); //gl_color4f(0, 0, 0, 0.5); gl_vertex3f(0, 0, 0); - gl_vertex3f(0, 1.0, 0); - gl_vertex3f(1.0 * aspect, 1.0, 0); - gl_vertex3f(1.0 * aspect, 0, 0); + gl_vertex3f(0, virt_height, 0); + gl_vertex3f(virt_width, virt_height, 0); + gl_vertex3f(virt_width, 0, 0); gl_end(); scr.draw(); @@ -136,16 +139,16 @@ void ui_button(int bn, int press, int x, int y) { - float normx = aspect * (float)x / (float)width; - float normy = 1.0 - (float)y / (float)height; + float normx = virt_width * (float)x / (float)width; + float normy = virt_height - virt_height * (float)y / (float)height; scr.sysev_mouse_button(bn, press != 0, normx, normy); } void ui_motion(int x, int y) { - float normx = aspect * (float)x / (float)width; - float normy = 1.0 - (float)y / (float)height; + float normx = virt_width * (float)x / (float)width; + float normy = virt_height - virt_height * (float)y / (float)height; scr.sysev_mouse_motion(normx, normy); } diff -r ea928c313344 -r 018f997dc646 src/uitheme.cc --- a/src/uitheme.cc Mon Sep 28 19:04:50 2015 +0300 +++ b/src/uitheme.cc Tue Sep 29 01:11:54 2015 +0300 @@ -6,10 +6,53 @@ #include "drawtext.h" #include "sdr.h" +#define BEVEL 1.0 #define VIS_THRES 0.005 using namespace goatkit; +struct Color { + float r, g, b, a; + + Color() : r(1), g(1), b(1), a(1) {} + Color(float r, float g, float b, float a = 1.0f) + { + this->r = r; + this->g = g; + this->b = b; + this->a = a; + } +}; + +enum { + TEXT_COLOR, + TOP_COLOR, + BOTTOM_COLOR, + BEVEL_LIT_COLOR, + BEVEL_SHAD_COLOR, + CURSOR_COLOR, + SELECTION_COLOR, + CHECK_COLOR +}; + +static Color colors[] = { + 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.8, 0.8, 0.8, 1.0), /* lit 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 */ +}; + + +#define JLEFT -1.0f +#define JCENTER 0.0f +#define JRIGHT 1.0f + +enum { FRAME_INSET, FRAME_OUTSET }; + extern int view_xsz, view_ysz; extern float view_aspect; extern unsigned int prog_ui, prog_font, prog_color; @@ -17,8 +60,11 @@ static void draw_label(const Widget *w); static void draw_button(const Widget *w); -static void draw_rect(const Vec2 &pos, const Vec2 &sz, float r, float g, float b, float a = 1.0f); -static void draw_text(float x, float y, const char *text); +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 Color lerp(const Color &a, const Color &b, float t); static struct { const char *name; @@ -51,7 +97,7 @@ static void begin_drawing(const Widget *w) { - Vec2 pos = w->get_position(); + //Vec2 pos = w->get_position(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -59,7 +105,7 @@ gl_matrix_mode(GL_MODELVIEW); gl_push_matrix(); gl_load_identity(); - gl_translatef(pos.x, pos.y, 0); + //gl_translatef(pos.x, pos.y, 0); } static void end_drawing(const Widget *w) @@ -75,7 +121,7 @@ if(vis < VIS_THRES) return; begin_drawing(w); - draw_text(pos.x, pos.y, w->get_text()); + draw_text(JLEFT, pos.x, pos.y, w->get_text()); end_drawing(w); } @@ -84,62 +130,114 @@ 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_rect(pos, sz, 1.0, 0.3, 0.2); - draw_text(pos.x, pos.y, w->get_text()); + 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), + // Color(0.4, 0.5, 1.0)); + draw_text(JCENTER, pos.x + sz.x / 2.0, pos.y, w->get_text()); end_drawing(w); } -static void draw_rect(const Vec2 &pos, const Vec2 &sz, float r, float g, float b, float a) +static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &color) +{ + draw_rect(pos, sz, color, color); +} + +static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &ctop, const Color &cbot) { float aspect = sz.x / sz.y; bind_program(prog_color); - gl_apply_xform(prog_color); gl_begin(GL_QUADS); - gl_color4f(r, g, b, a); + gl_color4f(cbot.r, cbot.g, cbot.b, cbot.a); gl_texcoord2f(0, 1); - gl_vertex2f(pos.x, pos.y); + gl_vertex3f(pos.x, pos.y, 0); gl_texcoord2f(aspect, 1); - gl_vertex2f(pos.x + sz.x, pos.y); + gl_vertex3f(pos.x + sz.x, pos.y, 0); + gl_color4f(ctop.r, ctop.g, ctop.b, ctop.a); gl_texcoord2f(aspect, 0); - gl_vertex2f(pos.x + sz.x, pos.y + sz.y); + gl_vertex3f(pos.x + sz.x, pos.y + sz.y, 0); gl_texcoord2f(0, 0); - gl_vertex2f(pos.x, pos.y + sz.y); + gl_vertex3f(pos.x, pos.y + sz.y, 0); gl_end(); } -static void draw_text(float x, float y, const char *text) +static void draw_text(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 virt_xsz = 420.0 * view_aspect; - float virt_ysz = 420.0; - - gl_matrix_mode(GL_PROJECTION); - gl_push_matrix(); - gl_load_identity(); - gl_ortho(0, virt_xsz, 0, virt_ysz, -1, 1); + float twidth = dtx_string_width(text); + float thalf = twidth / 2.0; gl_matrix_mode(GL_MODELVIEW); gl_push_matrix(); gl_load_identity(); - gl_translatef(x * virt_xsz, y * virt_ysz, 0); + gl_translatef(x - thalf - justify * thalf, y + 8, 0); bind_program(prog_font); set_uniform_float4(prog_font, "ucolor", 1.0, 1.0, 1.0, 1.0); - gl_apply_xform(prog_ui); + gl_apply_xform(prog_font); dtx_string(text); - gl_matrix_mode(GL_PROJECTION); - gl_pop_matrix(); gl_matrix_mode(GL_MODELVIEW); gl_pop_matrix(); } + +static void draw_frame(const Vec2 &pos, const Vec2 &sz, float inset) +{ + float x = pos.x - BEVEL; + float y = pos.y - BEVEL; + float w = sz.x + BEVEL * 2.0; + float h = sz.y + BEVEL * 2.0; + float b = BEVEL; + + Color tcol = lerp(colors[BEVEL_LIT_COLOR], colors[BEVEL_SHAD_COLOR], inset); + Color bcol = lerp(colors[BEVEL_SHAD_COLOR], colors[BEVEL_LIT_COLOR], inset); + + 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_vertex2f(x + b, y + b); + gl_vertex2f(x, y); + gl_vertex2f(x, y + h); + gl_vertex2f(x + b, y + h - b); + + 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_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_end(); +} + +static Color lerp(const Color &a, const Color &b, float t) +{ + Color res; + res.r = a.r + (b.r - a.r) * t; + res.g = a.g + (b.g - a.g) * t; + res.b = a.b + (b.b - a.b) * t; + return res; +}