istereo2

changeset 14:018f997dc646

button done
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 29 Sep 2015 01:11:54 +0300
parents ea928c313344
children 7bd4264bf74a
files Makefile libs/goatkit/boolanm.cc libs/goatkit/boolanm.h libs/goatkit/widget.cc libs/goatkit/widget.h src/ui.cc src/uitheme.cc
diffstat 7 files changed, 210 insertions(+), 41 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Mon Sep 28 19:04:50 2015 +0300
     1.2 +++ b/Makefile	Tue Sep 29 01:11:54 2015 +0300
     1.3 @@ -22,7 +22,8 @@
     1.4  endif
     1.5  
     1.6  $(bin): $(obj)
     1.7 -	$(CXX) -o $@ $(obj) $(LDFLAGS)
     1.8 +	@echo "Linking $(bin) ..."
     1.9 +	@$(CXX) -o $@ $(obj) $(LDFLAGS)
    1.10  
    1.11  -include $(dep)
    1.12  
     2.1 --- a/libs/goatkit/boolanm.cc	Mon Sep 28 19:04:50 2015 +0300
     2.2 +++ b/libs/goatkit/boolanm.cc	Tue Sep 29 01:11:54 2015 +0300
     2.3 @@ -54,6 +54,11 @@
     2.4  	trans_dur = dur;
     2.5  }
     2.6  
     2.7 +long BoolAnim::get_transition_duration() const
     2.8 +{
     2.9 +	return trans_dur;
    2.10 +}
    2.11 +
    2.12  void BoolAnim::set_time_callback(long (*time_func)())
    2.13  {
    2.14  	get_msec = time_func;
     3.1 --- a/libs/goatkit/boolanm.h	Mon Sep 28 19:04:50 2015 +0300
     3.2 +++ b/libs/goatkit/boolanm.h	Tue Sep 29 01:11:54 2015 +0300
     3.3 @@ -33,6 +33,8 @@
     3.4  	BoolAnim(bool st = false);
     3.5  
     3.6  	void set_transition_duration(long dur);
     3.7 +	long get_transition_duration() const;
     3.8 +
     3.9  	void set_time_callback(long (*time_func)());
    3.10  
    3.11  	void set(bool st);
     4.1 --- a/libs/goatkit/widget.cc	Mon Sep 28 19:04:50 2015 +0300
     4.2 +++ b/libs/goatkit/widget.cc	Tue Sep 29 01:11:54 2015 +0300
     4.3 @@ -124,6 +124,16 @@
     4.4  	return widget->visible.get_state();
     4.5  }
     4.6  
     4.7 +void Widget::set_visibility_transition(long msec)
     4.8 +{
     4.9 +	widget->visible.set_transition_duration(msec);
    4.10 +}
    4.11 +
    4.12 +long Widget::get_visibility_transition() const
    4.13 +{
    4.14 +	return widget->visible.get_transition_duration();
    4.15 +}
    4.16 +
    4.17  void Widget::activate()
    4.18  {
    4.19  	widget->active.change(true);
    4.20 @@ -144,6 +154,16 @@
    4.21  	return widget->active.get_state();
    4.22  }
    4.23  
    4.24 +void Widget::set_active_transition(long msec)
    4.25 +{
    4.26 +	widget->active.set_transition_duration(msec);
    4.27 +}
    4.28 +
    4.29 +long Widget::get_active_transition() const
    4.30 +{
    4.31 +	widget->active.get_transition_duration();
    4.32 +}
    4.33 +
    4.34  void Widget::press()
    4.35  {
    4.36  	widget->press.change(true);
    4.37 @@ -164,6 +184,16 @@
    4.38  	return widget->press.get_state();
    4.39  }
    4.40  
    4.41 +void Widget::set_press_transition(long msec)
    4.42 +{
    4.43 +	widget->press.set_transition_duration(msec);
    4.44 +}
    4.45 +
    4.46 +long Widget::get_press_transition() const
    4.47 +{
    4.48 +	return widget->press.get_transition_duration();
    4.49 +}
    4.50 +
    4.51  void Widget::mousein()
    4.52  {
    4.53  	widget->hover.change(true);
    4.54 @@ -187,6 +217,16 @@
    4.55  	return widget->hover.get_state();
    4.56  }
    4.57  
    4.58 +void Widget::set_hover_transition(long msec)
    4.59 +{
    4.60 +	widget->hover.set_transition_duration(msec);
    4.61 +}
    4.62 +
    4.63 +long Widget::get_hover_transition() const
    4.64 +{
    4.65 +	return widget->hover.get_transition_duration();
    4.66 +}
    4.67 +
    4.68  bool Widget::can_focus() const
    4.69  {
    4.70  	return false;
    4.71 @@ -212,6 +252,16 @@
    4.72  	return widget->focus.get_state();
    4.73  }
    4.74  
    4.75 +void Widget::set_focus_transition(long msec)
    4.76 +{
    4.77 +	widget->focus.set_transition_duration(msec);
    4.78 +}
    4.79 +
    4.80 +long Widget::get_focus_transition() const
    4.81 +{
    4.82 +	return widget->focus.get_transition_duration();
    4.83 +}
    4.84 +
    4.85  void Widget::set_position(float x, float y)
    4.86  {
    4.87  	set_position(Vec2(x, y));
     5.1 --- a/libs/goatkit/widget.h	Mon Sep 28 19:04:50 2015 +0300
     5.2 +++ b/libs/goatkit/widget.h	Tue Sep 29 01:11:54 2015 +0300
     5.3 @@ -56,21 +56,29 @@
     5.4  	virtual void hide();
     5.5  	virtual float get_visibility() const;
     5.6  	virtual bool is_visible() const;
     5.7 +	virtual void set_visibility_transition(long msec);
     5.8 +	virtual long get_visibility_transition() const;
     5.9  
    5.10  	virtual void activate();
    5.11  	virtual void deactivate();
    5.12  	virtual float get_active() const;
    5.13  	virtual bool is_active() const;
    5.14 +	virtual void set_active_transition(long msec);
    5.15 +	virtual long get_active_transition() const;
    5.16  
    5.17  	virtual void press();
    5.18  	virtual void release();
    5.19  	virtual float get_pressed() const;
    5.20  	virtual bool is_pressed() const;
    5.21 +	virtual void set_press_transition(long msec);
    5.22 +	virtual long get_press_transition() const;
    5.23  
    5.24  	virtual void mousein();
    5.25  	virtual void mouseout();
    5.26  	virtual float get_under_mouse() const;
    5.27  	virtual bool is_under_mouse() const;
    5.28 +	virtual void set_hover_transition(long msec);
    5.29 +	virtual long get_hover_transition() const;
    5.30  
    5.31  	// input focus, managed by the screen
    5.32  	virtual bool can_focus() const;
    5.33 @@ -78,6 +86,8 @@
    5.34  	virtual void focusout();
    5.35  	virtual float get_focus() const;
    5.36  	virtual bool is_focused() const;
    5.37 +	virtual void set_focus_transition(long msec);
    5.38 +	virtual long get_focus_transition() const;
    5.39  
    5.40  	virtual void set_position(float x, float y);
    5.41  	virtual void set_position(const Vec2 &pos);
     6.1 --- a/src/ui.cc	Mon Sep 28 19:04:50 2015 +0300
     6.2 +++ b/src/ui.cc	Tue Sep 29 01:11:54 2015 +0300
     6.3 @@ -15,24 +15,25 @@
     6.4  static goatkit::Screen scr;
     6.5  static float aspect;
     6.6  static int width, height;
     6.7 +static int virt_width, virt_height;
     6.8  
     6.9  extern unsigned int prog_color, prog_ui;
    6.10  
    6.11  int ui_init(void)
    6.12  {
    6.13 -	float xpos = 0.25;
    6.14 -	float ypos = 0.8;
    6.15 -	float vsep = 0.1;
    6.16 +	float xpos = 100;
    6.17 +	float ypos = 50;
    6.18 +	float vsep = 50;
    6.19  
    6.20  	/*goatkit::Label *label = new goatkit::Label;
    6.21  	label->set_position(xpos, ypos);
    6.22 -	label->set_size(0.1, 0.1);
    6.23 +	label->set_size(20, 20);
    6.24  	label->set_text("Stereoscopic rendering");
    6.25  	scr.add_widget(label);*/
    6.26  
    6.27  	goatkit::Button *button = new goatkit::Button;
    6.28  	button->set_position(xpos, ypos);
    6.29 -	button->set_size(0.2, 0.1);
    6.30 +	button->set_size(80, 30);
    6.31  	button->set_text("Done");
    6.32  	button->set_callback(goatkit::EV_CLICK, done_bn_handler);
    6.33  	scr.add_widget(button);
    6.34 @@ -91,6 +92,9 @@
    6.35  	width = x;
    6.36  	height = y;
    6.37  	aspect = (float)width / (float)height;
    6.38 +
    6.39 +	virt_width = 500.0 * aspect;
    6.40 +	virt_height = 500.0;
    6.41  }
    6.42  
    6.43  void ui_draw(void)
    6.44 @@ -100,8 +104,7 @@
    6.45  	gl_matrix_mode(GL_PROJECTION);
    6.46  	gl_push_matrix();
    6.47  	gl_load_identity();
    6.48 -	gl_scalef(2.0 / aspect, 2.0, 1);
    6.49 -	gl_translatef(-1, -1, 0);
    6.50 +	gl_ortho(0, virt_width, 0, virt_height, -1, 1);
    6.51  	gl_matrix_mode(GL_MODELVIEW);
    6.52  	gl_push_matrix();
    6.53  	gl_load_identity();
    6.54 @@ -116,9 +119,9 @@
    6.55  	gl_begin(GL_QUADS);
    6.56  	//gl_color4f(0, 0, 0, 0.5);
    6.57  	gl_vertex3f(0, 0, 0);
    6.58 -	gl_vertex3f(0, 1.0, 0);
    6.59 -	gl_vertex3f(1.0 * aspect, 1.0, 0);
    6.60 -	gl_vertex3f(1.0 * aspect, 0, 0);
    6.61 +	gl_vertex3f(0, virt_height, 0);
    6.62 +	gl_vertex3f(virt_width, virt_height, 0);
    6.63 +	gl_vertex3f(virt_width, 0, 0);
    6.64  	gl_end();
    6.65  
    6.66  	scr.draw();
    6.67 @@ -136,16 +139,16 @@
    6.68  
    6.69  void ui_button(int bn, int press, int x, int y)
    6.70  {
    6.71 -	float normx = aspect * (float)x / (float)width;
    6.72 -	float normy = 1.0 - (float)y / (float)height;
    6.73 +	float normx = virt_width * (float)x / (float)width;
    6.74 +	float normy = virt_height - virt_height * (float)y / (float)height;
    6.75  
    6.76  	scr.sysev_mouse_button(bn, press != 0, normx, normy);
    6.77  }
    6.78  
    6.79  void ui_motion(int x, int y)
    6.80  {
    6.81 -	float normx = aspect * (float)x / (float)width;
    6.82 -	float normy = 1.0 - (float)y / (float)height;
    6.83 +	float normx = virt_width * (float)x / (float)width;
    6.84 +	float normy = virt_height - virt_height * (float)y / (float)height;
    6.85  
    6.86  	scr.sysev_mouse_motion(normx, normy);
    6.87  }
     7.1 --- a/src/uitheme.cc	Mon Sep 28 19:04:50 2015 +0300
     7.2 +++ b/src/uitheme.cc	Tue Sep 29 01:11:54 2015 +0300
     7.3 @@ -6,10 +6,53 @@
     7.4  #include "drawtext.h"
     7.5  #include "sdr.h"
     7.6  
     7.7 +#define BEVEL		1.0
     7.8  #define VIS_THRES	0.005
     7.9  
    7.10  using namespace goatkit;
    7.11  
    7.12 +struct Color {
    7.13 +	float r, g, b, a;
    7.14 +
    7.15 +	Color() : r(1), g(1), b(1), a(1) {}
    7.16 +	Color(float r, float g, float b, float a = 1.0f)
    7.17 +	{
    7.18 +		this->r = r;
    7.19 +		this->g = g;
    7.20 +		this->b = b;
    7.21 +		this->a = a;
    7.22 +	}
    7.23 +};
    7.24 +
    7.25 +enum {
    7.26 +	TEXT_COLOR,
    7.27 +	TOP_COLOR,
    7.28 +	BOTTOM_COLOR,
    7.29 +	BEVEL_LIT_COLOR,
    7.30 +	BEVEL_SHAD_COLOR,
    7.31 +	CURSOR_COLOR,
    7.32 +	SELECTION_COLOR,
    7.33 +	CHECK_COLOR
    7.34 +};
    7.35 +
    7.36 +static Color colors[] = {
    7.37 +	Color(0.0, 0.0, 0.0, 1.0),		/* text color */
    7.38 +	Color(0.75, 0.75, 0.75, 1.0),	/* top color */
    7.39 +	Color(0.56, 0.56, 0.56, 1.0),	/* bot color */
    7.40 +	Color(0.8, 0.8, 0.8, 1.0),		/* lit bevel */
    7.41 +	Color(0.35, 0.35, 0.35, 1.0),		/* shadowed bevel */
    7.42 +	Color(0.8, 0.25, 0.18, 1.0),	/* cursor color */
    7.43 +	Color(0.68, 0.85, 1.3, 1.0),	/* selection color */
    7.44 +	Color(0.75, 0.1, 0.095, 1.0)	/* check color */
    7.45 +};
    7.46 +
    7.47 +
    7.48 +#define JLEFT	-1.0f
    7.49 +#define JCENTER	0.0f
    7.50 +#define JRIGHT	1.0f
    7.51 +
    7.52 +enum { FRAME_INSET, FRAME_OUTSET };
    7.53 +
    7.54  extern int view_xsz, view_ysz;
    7.55  extern float view_aspect;
    7.56  extern unsigned int prog_ui, prog_font, prog_color;
    7.57 @@ -17,8 +60,11 @@
    7.58  
    7.59  static void draw_label(const Widget *w);
    7.60  static void draw_button(const Widget *w);
    7.61 -static void draw_rect(const Vec2 &pos, const Vec2 &sz, float r, float g, float b, float a = 1.0f);
    7.62 -static void draw_text(float x, float y, const char *text);
    7.63 +static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &color);
    7.64 +static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &ctop, const Color &cbot);
    7.65 +static void draw_text(float justify, float x, float y, const char *text);
    7.66 +static void draw_frame(const Vec2 &pos, const Vec2 &sz, float inset);
    7.67 +static Color lerp(const Color &a, const Color &b, float t);
    7.68  
    7.69  static struct {
    7.70  	const char *name;
    7.71 @@ -51,7 +97,7 @@
    7.72  
    7.73  static void begin_drawing(const Widget *w)
    7.74  {
    7.75 -	Vec2 pos = w->get_position();
    7.76 +	//Vec2 pos = w->get_position();
    7.77  
    7.78  	glEnable(GL_BLEND);
    7.79  	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    7.80 @@ -59,7 +105,7 @@
    7.81  	gl_matrix_mode(GL_MODELVIEW);
    7.82  	gl_push_matrix();
    7.83  	gl_load_identity();
    7.84 -	gl_translatef(pos.x, pos.y, 0);
    7.85 +	//gl_translatef(pos.x, pos.y, 0);
    7.86  }
    7.87  
    7.88  static void end_drawing(const Widget *w)
    7.89 @@ -75,7 +121,7 @@
    7.90  	if(vis < VIS_THRES) return;
    7.91  
    7.92  	begin_drawing(w);
    7.93 -	draw_text(pos.x, pos.y, w->get_text());
    7.94 +	draw_text(JLEFT, pos.x, pos.y, w->get_text());
    7.95  	end_drawing(w);
    7.96  }
    7.97  
    7.98 @@ -84,62 +130,114 @@
    7.99  	Vec2 pos = w->get_position();
   7.100  	Vec2 sz = w->get_size();
   7.101  	float vis = w->get_visibility();
   7.102 +	float press = w->get_pressed();
   7.103  	if(vis < VIS_THRES) return;
   7.104  
   7.105 +	Color tcol = lerp(colors[TOP_COLOR], colors[BOTTOM_COLOR], press);
   7.106 +	Color bcol = lerp(colors[BOTTOM_COLOR], colors[TOP_COLOR], press);
   7.107 +
   7.108  	begin_drawing(w);
   7.109  
   7.110 -	draw_rect(pos, sz, 1.0, 0.3, 0.2);
   7.111 -	draw_text(pos.x, pos.y, w->get_text());
   7.112 +	draw_frame(pos, sz, press);
   7.113 +	draw_rect(pos, sz, tcol, bcol);
   7.114 +	//draw_rect(Vec2(pos.x + sz.x / 2.0 - 2.0, pos.y), Vec2(4.0, sz.y),
   7.115 +	//		Color(0.4, 0.5, 1.0));
   7.116 +	draw_text(JCENTER, pos.x + sz.x / 2.0, pos.y, w->get_text());
   7.117  
   7.118  	end_drawing(w);
   7.119  }
   7.120  
   7.121 -static void draw_rect(const Vec2 &pos, const Vec2 &sz, float r, float g, float b, float a)
   7.122 +static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &color)
   7.123 +{
   7.124 +	draw_rect(pos, sz, color, color);
   7.125 +}
   7.126 +
   7.127 +static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &ctop, const Color &cbot)
   7.128  {
   7.129  	float aspect = sz.x / sz.y;
   7.130  
   7.131  	bind_program(prog_color);
   7.132 -	gl_apply_xform(prog_color);
   7.133  
   7.134  	gl_begin(GL_QUADS);
   7.135 -	gl_color4f(r, g, b, a);
   7.136 +	gl_color4f(cbot.r, cbot.g, cbot.b, cbot.a);
   7.137  	gl_texcoord2f(0, 1);
   7.138 -	gl_vertex2f(pos.x, pos.y);
   7.139 +	gl_vertex3f(pos.x, pos.y, 0);
   7.140  	gl_texcoord2f(aspect, 1);
   7.141 -	gl_vertex2f(pos.x + sz.x, pos.y);
   7.142 +	gl_vertex3f(pos.x + sz.x, pos.y, 0);
   7.143 +	gl_color4f(ctop.r, ctop.g, ctop.b, ctop.a);
   7.144  	gl_texcoord2f(aspect, 0);
   7.145 -	gl_vertex2f(pos.x + sz.x, pos.y + sz.y);
   7.146 +	gl_vertex3f(pos.x + sz.x, pos.y + sz.y, 0);
   7.147  	gl_texcoord2f(0, 0);
   7.148 -	gl_vertex2f(pos.x, pos.y + sz.y);
   7.149 +	gl_vertex3f(pos.x, pos.y + sz.y, 0);
   7.150  	gl_end();
   7.151  }
   7.152  
   7.153 -static void draw_text(float x, float y, const char *text)
   7.154 +static void draw_text(float justify, float x, float y, const char *text)
   7.155  {
   7.156  	struct dtx_glyphmap *gmap = dtx_get_font_glyphmap_idx(font, 0);
   7.157  	dtx_use_font(font, dtx_get_glyphmap_ptsize(gmap));
   7.158  
   7.159 -	float virt_xsz = 420.0 * view_aspect;
   7.160 -	float virt_ysz = 420.0;
   7.161 -
   7.162 -	gl_matrix_mode(GL_PROJECTION);
   7.163 -	gl_push_matrix();
   7.164 -	gl_load_identity();
   7.165 -	gl_ortho(0, virt_xsz, 0, virt_ysz, -1, 1);
   7.166 +	float twidth = dtx_string_width(text);
   7.167 +	float thalf = twidth / 2.0;
   7.168  
   7.169  	gl_matrix_mode(GL_MODELVIEW);
   7.170  	gl_push_matrix();
   7.171  	gl_load_identity();
   7.172 -	gl_translatef(x * virt_xsz, y * virt_ysz, 0);
   7.173 +	gl_translatef(x - thalf - justify * thalf, y + 8, 0);
   7.174  
   7.175  	bind_program(prog_font);
   7.176  	set_uniform_float4(prog_font, "ucolor", 1.0, 1.0, 1.0, 1.0);
   7.177 -	gl_apply_xform(prog_ui);
   7.178 +	gl_apply_xform(prog_font);
   7.179  
   7.180  	dtx_string(text);
   7.181  
   7.182 -	gl_matrix_mode(GL_PROJECTION);
   7.183 -	gl_pop_matrix();
   7.184  	gl_matrix_mode(GL_MODELVIEW);
   7.185  	gl_pop_matrix();
   7.186  }
   7.187 +
   7.188 +static void draw_frame(const Vec2 &pos, const Vec2 &sz, float inset)
   7.189 +{
   7.190 +	float x = pos.x - BEVEL;
   7.191 +	float y = pos.y - BEVEL;
   7.192 +	float w = sz.x + BEVEL * 2.0;
   7.193 +	float h = sz.y + BEVEL * 2.0;
   7.194 +	float b = BEVEL;
   7.195 +
   7.196 +	Color tcol = lerp(colors[BEVEL_LIT_COLOR], colors[BEVEL_SHAD_COLOR], inset);
   7.197 +	Color bcol = lerp(colors[BEVEL_SHAD_COLOR], colors[BEVEL_LIT_COLOR], inset);
   7.198 +
   7.199 +	bind_program(prog_color);
   7.200 +
   7.201 +	gl_begin(GL_QUADS);
   7.202 +	gl_color4f(tcol.r, tcol.g, tcol.b, tcol.a);
   7.203 +	gl_vertex2f(x + b, y + h - b);
   7.204 +	gl_vertex2f(x + w - b, y + h - b);
   7.205 +	gl_vertex2f(x + w, y + h);
   7.206 +	gl_vertex2f(x, y + h);
   7.207 +
   7.208 +	gl_vertex2f(x + b, y + b);
   7.209 +	gl_vertex2f(x, y);
   7.210 +	gl_vertex2f(x, y + h);
   7.211 +	gl_vertex2f(x + b, y + h - b);
   7.212 +
   7.213 +	gl_color4f(bcol.r, bcol.g, bcol.b, bcol.a);
   7.214 +	gl_vertex2f(x, y);
   7.215 +	gl_vertex2f(x + b, y + b);
   7.216 +	gl_vertex2f(x + w - b, y + b);
   7.217 +	gl_vertex2f(x + w, y);
   7.218 +
   7.219 +	gl_vertex2f(x + w - b, y + b);
   7.220 +	gl_vertex2f(x + w, y);
   7.221 +	gl_vertex2f(x + w, y + h);
   7.222 +	gl_vertex2f(x + w - b, y + h - b);
   7.223 +	gl_end();
   7.224 +}
   7.225 +
   7.226 +static Color lerp(const Color &a, const Color &b, float t)
   7.227 +{
   7.228 +	Color res;
   7.229 +	res.r = a.r + (b.r - a.r) * t;
   7.230 +	res.g = a.g + (b.g - a.g) * t;
   7.231 +	res.b = a.b + (b.b - a.b) * t;
   7.232 +	return res;
   7.233 +}