Clone in a terminal:
Commit 231575c
Johan Mattsson - 2013-09-02T09:25:58+00:00
231575cd7dde8b74db4918e7b2ab4818f2e8d802johan.mattsson.m@gmail.com

scroll tool box

Changed files (5)

Diff

diff --git a/libbirdfont/DrawingTools.vala b/libbirdfont/DrawingTools.valaindex 38b5ba7..d3f7bf0 100644--- a/libbirdfont/DrawingTools.vala+++ b/libbirdfont/DrawingTools.vala@@ -671,8 +671,9 @@ public class DrawingTools : ToolCollection  { 		add_expander (style_tools); 		 		// Fixa: add_expander (trace);-		-		add_expander (test_tools);+		if (BirdFont.has_argument ("--test")) {+			add_expander (test_tools);+		} 		 		draw_tools.set_persistent (true); 		draw_tools.set_unique (true);diff --git a/libbirdfont/Expander.vala b/libbirdfont/Expander.valaindex e1cc8e2..e18ed4a 100644--- a/libbirdfont/Expander.vala+++ b/libbirdfont/Expander.vala@@ -21,13 +21,13 @@ public class Expander : GLib.Object { 	 	public double x = 7; 	public double y = 5;+	public double scroll = 0;  	public double w = 6; 	public double h = 5; 	 	public double margin = 0; 	-	protected double rotation = 0; 	protected double opacity = 0.5; 	 	protected bool active = false;@@ -38,9 +38,15 @@ public class Expander : GLib.Object { 	bool persist = false; 	bool unique = false; 	+	double content_height = 0;+	 	public Expander () { 	} +	public double get_content_height () {+		return content_height;+	}+ 	/** Returns true if tools can be used with the current canvas after 	 * they have been selectes and false if they are a commands to be executed. 	 */@@ -65,21 +71,32 @@ public class Expander : GLib.Object { 	 	private void update_tool_position () { 		double xt = x - 15;-		double yt = y - 30;-		+		double yt = y + scroll - 30;++		if (tool.length () > 0) {+			content_height = tool.first ().data.h + 2;+		} else {+			content_height = 0;+		}+ 		foreach (Tool t in tool) { 			t.x = xt; 			t.y = yt; 			 			xt += t.w + 4;-			+ 			if (xt + t.w > 160 - 20) { 				xt = x - 15; 				yt += t.h + 2;+				content_height += t.h + 2;  			} 		} 	} 	+	public void set_scroll (double scroll) {+		this.scroll = scroll;+	}+	 	public void set_offset (double ty) { 		y = ty; 		@@ -125,8 +142,9 @@ public class Expander : GLib.Object { 			}); 	} 	-	public bool is_over (double xp, double yp) {	-		return (x - 7/2.0 <= xp <= x + w  + 7/2.0 && y - 7/2.0<= yp <= y + w + 7/2.0);  +	public bool is_over (double xp, double yp) {+		double yt = y + scroll + 2;+		return yt - 7 <= yp <= yt + 7 && xp < 17; 	} 	 	public bool set_active (bool a) {@@ -142,17 +160,14 @@ public class Expander : GLib.Object { 	 	public virtual bool set_open (bool o) { 		bool r = (open != o);-		rotation = (o) ? Math.PI_2 : 0; 		 		if (o) { 			margin = 35 * (int)((tool.length () / 4.0) + 1) ;-			rotation = Math.PI_2;			 			if (tool.length () % 4 == 0) { 				margin -= 35; 			} 		} else { 			margin = 0;-			rotation = 0;  		} 		 		open = o;@@ -160,50 +175,44 @@ public class Expander : GLib.Object { 	} 	 	public void draw (int wd, int hd, Context cr) {-		double lx, ly;+		double yt = y + scroll + 2; 		double ih2 = 5.4 / 2; 		double iw2 = 5.4 / 2;-		+				+		cr.save ();+		cr.set_line_width (0.5);+		cr.set_source_rgba (0, 0, 0, 0.25);+		cr.move_to (x + w + 7, yt);+		cr.line_to (wd - w - x + 4, yt);	+		cr.stroke ();+		cr.restore ();+ 		// box 		cr.save (); 		cr.set_line_join (LineJoin.ROUND);-		cr.set_line_width(7);-		cr.set_source_rgba (176/255.0, 211/255.0, 230/255.0, opacity);-		cr.rectangle (x, y, w, h);+		cr.set_line_width (7);+		cr.set_source_rgba (0.75, 0.75, 0.75, opacity);+		cr.rectangle (x, yt - 3, w, h); 		cr.stroke (); 		cr.restore (); 		 		// arrow 		cr.save ();-		-		cr.translate (x + w/2, y + h/2);-		cr.rotate (rotation);-+		cr.new_path (); 		cr.set_line_width (1); 		cr.set_source_rgba (0, 0, 0, opacity);--		cr.new_path ();-		cr.move_to (-iw2, -ih2);-		cr.line_to (iw2, 0);	-		cr.line_to (-iw2, +ih2);-+		if (!open) {+			cr.move_to (x - iw2 + 3, yt - ih2 - 0.7);+			cr.line_to (x + iw2 + 3, yt);	+			cr.line_to (x - iw2 + 3, ih2 + yt - 0.7);+		} else {+			cr.move_to (x - iw2 + 3, yt - ih2 - 0.7);+			cr.line_to (x + iw2 + 3, yt - ih2 - 0.7);+			cr.line_to (x + iw2, yt + 2);	+		} 		cr.close_path(); 		cr.stroke (); 		cr.restore ();-		-		// separator-		cr.save ();-		lx = x + w + 7;-		ly = y + ih2;-		if (lx < wd) {-			cr.set_line_width(1);-			cr.set_source_rgba (0, 0, 0, 0.2);-			cr.move_to (lx, ly);-			cr.line_to (wd - w - x + 4, ly);	-			cr.stroke ();-		}-		cr.restore ();- 	} 	 	public void draw_content (int w, int h, Context cr) {diff --git a/libbirdfont/FileTab.vala b/libbirdfont/FileTab.valaindex 996dbb0..a10ca8b 100644--- a/libbirdfont/FileTab.vala+++ b/libbirdfont/FileTab.vala@@ -114,6 +114,11 @@ public class FileTab : FontDisplay { 		int r = (int) rint ((ey - 17) / row_height) + scroll; 		int i = 2; // heading +		if (is_null (recent_fonts)) {+			warning ("No recent fonts");+			return;+		}+ 		foreach (Font font in recent_fonts) { 			if (i == r) { 				return_if_fail (font.font_file != null);@@ -121,7 +126,12 @@ public class FileTab : FontDisplay { 			} 			i++; 		}-		++		if (is_null (backups)) {+			warning ("No backups");+			return;+		}+				 		i += 2;  		foreach (string backup in backups) { 			if (i == r) {diff --git a/libbirdfont/ToolCollection.vala b/libbirdfont/ToolCollection.valaindex 59a1495..dcbc89e 100644--- a/libbirdfont/ToolCollection.vala+++ b/libbirdfont/ToolCollection.vala@@ -18,6 +18,8 @@ using Math; namespace BirdFont {  public abstract class ToolCollection : GLib.Object  {+	public double scroll = 0;+	public double content_height = 0; 	public abstract unowned List<Expander> get_expanders (); } diff --git a/libbirdfont/Toolbox.vala b/libbirdfont/Toolbox.valaindex 1c7ec8f..5be7f54 100644--- a/libbirdfont/Toolbox.vala+++ b/libbirdfont/Toolbox.vala@@ -84,7 +84,7 @@ public class Toolbox : GLib.Object  { 			if (exp.is_over (x, y)) { 				exp.set_open (! exp.is_open ());					 				update_expanders ();			-				redraw ((int) exp.x - 10, (int) exp.y - 10, allocation_width, (int) (allocation_height - exp.y + 10));+				redraw_tool_box (); 			} 			 			if (exp.is_open ()) {@@ -104,6 +104,14 @@ public class Toolbox : GLib.Object  { 	}  	public void scroll_up (double x, double y) {+		current_set.scroll += 35;+		+		if (current_set.scroll > 0) {+			current_set.scroll = 0;+		}+		+		update_expanders ();+		 		foreach (Expander exp in current_set.get_expanders ()) { 			foreach (Tool t in exp.tool) { 				if (t.is_over (x, y)) {@@ -112,9 +120,21 @@ public class Toolbox : GLib.Object  { 				} 			} 		}+		+		redraw_tool_box (); 	}  	public void scroll_down (double x, double y) {+		current_set.scroll -= 35;+		+		if (current_set.content_height < allocation_height) {+			current_set.scroll = 0;+		} else if (current_set.content_height + current_set.scroll < allocation_height) {+			current_set.scroll = allocation_height - current_set.content_height;+		}+				+		update_expanders ();+		 		foreach (Expander exp in current_set.get_expanders ()) { 			foreach (Tool t in exp.tool) { 				if (t.is_over (x, y)) {@@ -123,6 +143,8 @@ public class Toolbox : GLib.Object  { 				} 			} 		}+		+		redraw_tool_box (); 	} 	 	public void move (double x, double y) {@@ -242,14 +264,25 @@ public class Toolbox : GLib.Object  { 	public void update_expanders () { 		Expander? p = null;  		Expander pp;++		foreach (Expander e in current_set.get_expanders ()) {+			e.set_scroll (current_set.scroll);+		}+		+		current_set.content_height = 0; 		foreach (Expander e in current_set.get_expanders ()) { 			if (p != null) { 				pp = (!) p; 				e.set_offset (pp.y + pp.margin + 9);+				current_set.content_height += e.get_content_height () + 9;+			} else {+				e.set_offset (9); 			} 			 			p = e; 		}+		+		current_set.content_height += 40; 	} 	 	private void draw_expanders (int w, int h, Context cr) {

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112