Clone in a terminal:
Commit e147293
Johan Mattsson - 2015-06-15T09:00:46+00:00
e147293b45c01d5d5eceba16347a46ac68a80b71johan.mattsson.m@gmail.com

Fix tool selection

Changed files (9)

Diff

diff --git a/libbirdfont/BirdFont.vala b/libbirdfont/BirdFont.valaindex 8595f87..f02c2bb 100644--- a/libbirdfont/BirdFont.vala+++ b/libbirdfont/BirdFont.vala@@ -653,12 +653,12 @@ public class BirdFont { 		home = File.new_for_path (home_path); #endif -		if (settings_directory != null) {+		if (settings_subdirectory != null) { 			settings = get_child(home, (!) settings_subdirectory); 		} else { 			settings = get_child(home, "birdfont"); 		}-				+			 		if (!settings.query_exists ()) { 			DirUtils.create ((!) settings.get_path (), 0755); 		}diff --git a/libbirdfont/ColorPicker.vala b/libbirdfont/ColorPicker.valaindex 060e53f..43e30e9 100644--- a/libbirdfont/ColorPicker.vala+++ b/libbirdfont/ColorPicker.vala@@ -25,6 +25,7 @@ public class ColorPicker : Tool {  	public signal void fill_color_updated (); 	public signal void stroke_color_updated ();+	public signal void gradient_color_updated (); 	 	bool update_color = false; 	public double bar_height;@@ -37,11 +38,17 @@ public class ColorPicker : Tool { 	public Color stroke_color = new Color (0, 0, 0, 1); 	public Color fill_color = new Color (0, 0, 0, 1); 	+	public Gradient gradient = new Gradient ();+	bool update_gradient = false; +	int bars;+	Stop current_stop = new Stop ();+	 	public ColorPicker (string tooltip = "") { 		base (null, tooltip); 		 		bar_height = 22 * Toolbox.get_scale ();-		h = 5 * bar_height;+		bars = 5;+		h = bars * bar_height; 		 		stroke_color_updated.connect (() => { 			redraw ();@@ -49,7 +56,7 @@ public class ColorPicker : Tool { 		});  		panel_press_action.connect ((selected, button, tx, ty) => {	-			if (y <= ty <= y + 5 * bar_height) {+			if (y <= ty <= y + bars * bar_height) { 				update_color = true; 				selected_bar = (int) ((ty - y) / bar_height); 				set_color_from_pointer (tx);@@ -69,6 +76,14 @@ public class ColorPicker : Tool { 		}); 	} 	+	public void set_gradient (Gradient g, bool update_gradient) {+		gradient = g;+		this.update_gradient = update_gradient;+		return_if_fail (g.stops.size > 0);+		current_stop = g.stops.get (0);+		redraw ();+	}+	 	public void set_color (Color c) { 		c.to_hsva (out hue, out s, out b, out a); 	}@@ -90,7 +105,7 @@ public class ColorPicker : Tool { 			b = (double) tx / Toolbox.allocation_width; 		} else if (selected_bar == 3) { 			a = (double) tx / Toolbox.allocation_width;-		} else if (selected_bar == 4) {+		} else if (!update_gradient && selected_bar == 4) { 			if (has_stroke_color) { 				stroke_selected = tx > Toolbox.allocation_width / 2.0; 				@@ -100,14 +115,25 @@ public class ColorPicker : Tool { 					set_color (fill_color); 				} 			}+		} else if (update_gradient && selected_bar == 4) {+			if (gradient.stops.size > 0) {+				int g = (int) ((double) Toolbox.allocation_width / gradient.stops.size);+				return_if_fail (0 <= g < gradient.stops.size);+				current_stop = gradient.stops.get (g);+			} 		} 		-		if (has_stroke_color && stroke_selected) {-			stroke_color = new Color.hsba (hue, s, b, a);-			stroke_color_updated ();+		if (update_gradient) {+			current_stop.color = new Color.hsba (hue, s, b, a);+			gradient_color_updated (); 		} else {-			fill_color = new Color.hsba (hue, s, b, a);-			fill_color_updated ();+			if (has_stroke_color && stroke_selected) {+				stroke_color = new Color.hsba (hue, s, b, a);+				stroke_color_updated ();+			} else {+				fill_color = new Color.hsba (hue, s, b, a);+				fill_color_updated ();+			} 		} 	} 	@@ -161,8 +187,11 @@ public class ColorPicker : Tool { 			cr.rectangle (p * Toolbox.allocation_width, y + 3 * bar_height, scale, bar_height); 			cr.fill (); 			cr.restore ();-						+		}++		if (!update_gradient) { 			if (!has_stroke_color) {+				c = fill_color; 				cr.save (); 				cr.set_source_rgba (c.r, c.g, c.b, c.a); 				cr.rectangle (0, y + 4 * bar_height, Toolbox.allocation_width, bar_height);@@ -201,7 +230,28 @@ public class ColorPicker : Tool { 					} 				} 			}+		} else { // update gradient+			int stop_size = (int) ((double) Toolbox.allocation_width / gradient.stops.size);+			for (int i = 0; i < gradient.stops.size; i++) {+				Stop s = gradient.stops.get (i);+				c = s.color;+				cr.save ();+				cr.set_source_rgba (c.r, c.g, c.b, c.a);+				cr.rectangle (i * stop_size, y + 4 * bar_height, stop_size, bar_height);+				cr.fill ();+				cr.restore ();+				+				if (s == current_stop) {+					cr.save ();+					Theme.color (cr, "Tool Foreground");+					cr.set_line_width (1);+					cr.rectangle (i * stop_size, y + 4 * bar_height, stop_size, bar_height);+					cr.stroke ();+					cr.restore ();+				}+			} 		}+			 	} 	 	void draw_dial (Context cr, double px, double py, int bar_index, double val) {diff --git a/libbirdfont/DrawingTools.vala b/libbirdfont/DrawingTools.valaindex f8b7f4d..f9ea514 100644--- a/libbirdfont/DrawingTools.vala+++ b/libbirdfont/DrawingTools.vala@@ -1385,7 +1385,10 @@ public class DrawingTools : ToolCollection  {  			hide_all_modifiers (); -			move_background.set_selected (false);+			foreach (Tool t in draw_tools.tool) {+				t.set_selected (false);+			}+			 			cut_background.set_selected (false); 			 			bezier_tool.set_selected (false);@@ -1412,6 +1415,7 @@ public class DrawingTools : ToolCollection  { 			flip_horizontal.set_selected (false); 			 			current_tool.set_selected (true);+			current_tool.select_action (current_tool); 		 			if (resize_tool.is_selected () || move_tool.is_selected ()) { 				show_object_tool_modifiers ();diff --git a/libbirdfont/Expander.vala b/libbirdfont/Expander.valaindex 3ee4720..76c4349 100644--- a/libbirdfont/Expander.vala+++ b/libbirdfont/Expander.vala@@ -249,6 +249,8 @@ public class Expander : GLib.Object { 				} 			} 			+			// FIXME: delete+			/* 			if (!is_persistent () && !selected.persistent) { 				var time = new TimeoutSource(200); 				time.set_callback(() => {@@ -257,7 +259,7 @@ public class Expander : GLib.Object { 					return false; 				}); 				time.attach(null);-			}+			}*/  			selected.new_selection = false; 		});diff --git a/libbirdfont/Gradient.vala b/libbirdfont/Gradient.valaindex e6ed885..d74b871 100644--- a/libbirdfont/Gradient.vala+++ b/libbirdfont/Gradient.vala@@ -23,7 +23,7 @@ public class Gradient : GLib.Object { 	public double x2 = 0; 	public double y2 = 0; 	-	Gee.ArrayList<Stop> stops = new Gee.ArrayList<Stop> ();+	public Gee.ArrayList<Stop> stops = new Gee.ArrayList<Stop> (); 	 	public Gradient () { 	}diff --git a/libbirdfont/MoveTool.vala b/libbirdfont/MoveTool.valaindex cb188e1..36e996b 100644--- a/libbirdfont/MoveTool.vala+++ b/libbirdfont/MoveTool.vala@@ -51,8 +51,6 @@ public class MoveTool : Tool { 		}); 		 		select_action.connect((self) => {-			Glyph glyph = MainWindow.get_current_glyph ();-			glyph.close_path (); 		});  		deselect_action.connect((self) => {@@ -473,7 +471,6 @@ public class MoveTool : Tool { 		Glyph g = MainWindow.get_current_glyph (); 		 		g.clear_active_paths ();-		 		foreach (Path p in g.get_paths_in_current_layer ()) { 			if (p.points.size > 0) { 				g.add_active_path (p);diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex c0f2e74..ed61fe4 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -83,6 +83,8 @@ public class Path : GLib.Object { 	public Color? color = null; 	public Color? stroke_color = null; +	public Gradient? gradient = null;+ 	public Path () {	 		string width; 		@@ -1013,6 +1015,14 @@ public class Path : GLib.Object { 			ep.y += delta_y; 		} 		+		if (gradient != null) {+			Gradient g = (!) gradient;+			g.x1 += delta_x;+			g.x2 += delta_x;+			g.y1 += delta_y;+			g.y2 += delta_y;+		}+		 		update_region_boundaries (); 	} 	diff --git a/libbirdfont/Stop.vala b/libbirdfont/Stop.valaindex cad54ec..933590e 100644--- a/libbirdfont/Stop.vala+++ b/libbirdfont/Stop.vala@@ -19,7 +19,7 @@ namespace BirdFont {  public class Stop : GLib.Object { 	public Color color = Color.black ();-	double offset = 0;+	public double offset = 0; 	 	public Stop () { 	}diff --git a/libbirdfont/Toolbox.vala b/libbirdfont/Toolbox.valaindex 0fc0021..b24c708 100644--- a/libbirdfont/Toolbox.vala+++ b/libbirdfont/Toolbox.vala@@ -88,6 +88,10 @@ public class Toolbox : GLib.Object  { 		update_expanders (); 	} +	public static DrawingTools get_drawing_tools () {+		return drawing_tools;+	}+ 	public static void set_toolbox_from_tab (string tab_name, Tab? t = null) {		 		if (tab_name == "Spacing") { 			current_set = (ToolCollection) spacing_tools;

Contact

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