Clone in a terminal:
Commit 9bbfcc8
Johan Mattsson - 2013-08-08T12:17:36+00:00
9bbfcc8660b36f3ff1be71537eb65f8ba75eb803johan.mattsson.m@gmail.com

remove cut tool and draw outside of grid

Changed files (6)

Diff

diff --git a/icons/cut.png b/icons/cut.pngdeleted file mode 100644index 1e84f87..0000000Binary files a/icons/cut.png and /dev/null differdiff --git a/libbirdfont/CutTool.vala b/libbirdfont/CutTool.valadeleted file mode 100644index bb22255..0000000--- a/libbirdfont/CutTool.vala+++ /dev/null@@ -1,66 +0,0 @@-/*-    Copyright (C) 2012 Johan Mattsson--    This library is free software; you can redistribute it and/or modify -    it under the terms of the GNU Lesser General Public License as -    published by the Free Software Foundation; either version 3 of the -    License, or (at your option) any later version.--    This library is distributed in the hope that it will be useful, but -    WITHOUT ANY WARRANTY; without even the implied warranty of -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -    Lesser General Public License for more details.-*/--namespace BirdFont {--class CutTool : Tool {--	PenTool pen;-	-	public CutTool (string n) {-		base (n, "Create counter path", 'u', CTRL);-		-		select_action.connect((self) => {-			pen = (PenTool) MainWindow.get_tool ("pen_tool");-		});-		-		press_action.connect((self, b, x, y) => {-			pen.press_action (pen, b, x, y);-		});--		release_action.connect((self, b, x, y) => {-			pen.release_action (pen, b, x, y);-		});-		-		move_action.connect ((self, x, y)	 => {-			pen.move_action (pen, x, y);-		});-		-		key_press_action.connect ((self, keyval) => {-			pen.key_press_action (pen, keyval);-		});--		key_release_action.connect ((self, keyval) => {-			pen.key_release_action (pen, keyval);-		});-	}--	public static void force_direction () {-		Glyph g = MainWindow.get_current_glyph ();-		Tool current_tool = MainWindow.get_toolbox ().get_current_tool ();-		-		foreach (Path p in g.active_paths) {-			if (p.is_open () && !p.has_direction ()) {-				if (current_tool is PenTool) {-					p.force_direction (Direction.CLOCKWISE);-				} else if (current_tool is CutTool) {-					p.force_direction (Direction.COUNTER_CLOCKWISE);-				}				-			}-		}-	}-	-}--}diff --git a/libbirdfont/GridTool.vala b/libbirdfont/GridTool.valaindex c620081..bd229e2 100644--- a/libbirdfont/GridTool.vala+++ b/libbirdfont/GridTool.vala@@ -19,15 +19,15 @@ namespace BirdFont {  class GridTool : Tool { 	-	static List <Line> horizontal;-	static List <Line> vertical;+	static List<Line> horizontal;+	static List<Line> vertical; 	 	static bool visible = false; 	 	public static double size_x; 	public static double size_y; 	-	public static List <SpinButton> sizes;+	public static List<SpinButton> sizes; 	 	public GridTool (string n) { 		base (n, _("Show grid"), 'g', NONE);@@ -83,7 +83,7 @@ class GridTool : Tool { 		Glyph g = MainWindow.get_current_glyph (); 		double step = size_y; 		double i;-		int max_lines = 400;+		int max_lines = 600; 		int n; 		Line t, l, u; @@ -107,7 +107,7 @@ class GridTool : Tool { 			l = new Line ("grid", i, Line.VERTICAL); 			l.set_moveable (false); 			l.set_color (0.2, 0.6, 0.2, 0.2);-			horizontal.append (l);+			vertical.append (l); 			 			if (++n >= max_lines) { 				break;@@ -119,7 +119,7 @@ class GridTool : Tool { 			t = new Line ("grid", i, Line.HORIZONTAL); 			t.set_moveable (false); 			t.set_color (0.2, 0.6, 0.2, 0.2);-			vertical.append (t);	+			horizontal.prepend (t);	  			if (++n >= max_lines) { 				break;@@ -131,7 +131,7 @@ class GridTool : Tool { 			u = new Line ("grid", i, Line.HORIZONTAL); 			u.set_moveable (false); 			u.set_color (0.2, 0.6, 0.2, 0.2);-			vertical.append (u);	+			horizontal.append (u);	  			if (++n >= max_lines) { 				break;@@ -148,59 +148,104 @@ class GridTool : Tool { 	public static void tie_coordinate (ref double x, ref double y) { 		tie_point (ref x, ref y, true); 	}-		-	private static void tie_point (ref double x, ref double y, bool coordinate)-		requires (horizontal.length () > 0 && vertical.length () > 0)++	public static void tie_point (ref double x, ref double y, bool coordinate) {+		x = tie_point_x (x, coordinate);+		y = tie_point_y (y, coordinate);+	}++	public static double tie_point_x (double x, bool coordinate)+		requires (vertical.length () >= 2) 	{ 		double d, m;-		-		Line xmin = horizontal.first ().data;-		Line ymin = vertical.first ().data;-+		Line xmin = vertical.first ().data; 		Line xpos;-		Line ypos;-		+		Line startx = vertical.first ().data;+		Line stopx = vertical.last ().data;++		// outside of the grid+		if (!coordinate) {+			if (!(startx.pos < Glyph.path_coordinate_x (x) < stopx.pos)) {+				return x;+			}+		} else {+			if (!(startx.pos < x < stopx.pos)) {+				return x;+			}+		}+			 		if (!coordinate) { 			xpos = new Line ("", 0, Line.VERTICAL);-			ypos = new Line ("", 0, Line.HORIZONTAL);- 			xpos.pos = Glyph.path_coordinate_x (x);-			ypos.pos = Glyph.path_coordinate_y (y); 		} else { 			xpos = new Line ("", x, Line.VERTICAL);-			ypos = new Line ("", -y, Line.HORIZONTAL); 		}  		m = double.MAX;- 		foreach (Line line in vertical) {-			d = Math.fabs (line.get_pos () - ypos.get_pos ());+			d = Math.fabs (line.get_pos () - xpos.get_pos ()); 			 			if (d <= m) { 				m = d;-				ymin = line;+				xmin = line; 			} 			 		}+		+		if (!coordinate) {+			x = Glyph.reverse_path_coordinate_x (xmin.get_pos ());+		} else {+			x = xmin.get_pos ();+		}+		+		return x;+	}++	public static double tie_point_y (double y, bool coordinate)+		requires (horizontal.length () >= 2)+	{+		double d, m;+		Line ymin = horizontal.first ().data;+		Line ypos;+		Line starty = horizontal.first ().data;+		Line stopy = horizontal.last ().data;+		+		// outside of the grid+		if (!coordinate) {+			if (!(starty.pos < Glyph.path_coordinate_y (y) < stopy.pos)) {+				return y;+			}+		} else {+			if (!(starty.pos < -y < stopy.pos)) {+				return y;+			}+		}+		+		if (!coordinate) {+			ypos = new Line ("", 0, Line.HORIZONTAL);+			ypos.pos = Glyph.path_coordinate_y (y);+		} else {+			ypos = new Line ("", -y, Line.HORIZONTAL);+		}  		m = double.MAX; 		foreach (Line line in horizontal) {-			d = Math.fabs (line.get_pos () - xpos.get_pos ());+			d = Math.fabs (line.get_pos () - ypos.get_pos ()); 			 			if (d <= m) { 				m = d;-				xmin = line;+				ymin = line; 			} 			 		} 		 		if (!coordinate) {-			x = Glyph.reverse_path_coordinate_x (xmin.get_pos ()); 			y = Glyph.reverse_path_coordinate_y (ymin.get_pos ()); 		} else {-			x = xmin.get_pos (); 			y = -ymin.get_pos (); 		}+		+		return y; 	} 	 	public static bool is_visible () {diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex 6556082..1cedc9a 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -432,7 +432,7 @@ public class Path { 	/** Switch direction from clockwise path to counter clockwise path or vise versa. */ 	public void reverse () { 		bool direction = is_clockwise ();-		+		print ("reverse\n"); 		if (no_derived_direction) { 			clockwise_direction = !clockwise_direction; 		}@@ -1892,7 +1892,7 @@ public class Path { 		return true; 	} 	-	private static bool is_clasped (PathList pl, Path p) {+	public static bool is_clasped (PathList pl, Path p) { 		foreach (Path o in pl.paths) { 			if (o == p) { 				continue;@@ -1909,7 +1909,7 @@ public class Path { 	private static bool is_clasped_path (Path outside, Path inside) { 		bool i = true; 		foreach (EditPoint e in inside.points) {-			if (!outside.is_over_coordinate_var (e.x, e.y, 0.5)) { // high tolerance since point may be off curve in both paths+			if (!outside.is_over_coordinate_var (e.x, e.y, 0.5)) { // point may be off curve in both paths 				i = false; 				break; 			}@@ -2036,9 +2036,6 @@ public class Path { 	}  	public void append_path (Path path) {-		EditPointHandle handle;-		EditPoint first;- 		if (points.length () == 0) { 			warning ("No points"); 			return;diff --git a/libbirdfont/PenTool.vala b/libbirdfont/PenTool.valaindex 7c7170d..78c7b66 100644--- a/libbirdfont/PenTool.vala+++ b/libbirdfont/PenTool.vala@@ -49,8 +49,8 @@ public class PenTool : Tool { 	/** Move curve handle instead of control point. */ 	private bool last_selected_is_handle = false; -	List<Path> clockwise = new List<Path> ();-	List<Path> counter_clockwise = new List<Path> ();+	static List<Path> clockwise = new List<Path> ();+	static List<Path> counter_clockwise = new List<Path> (); 			 	public PenTool (string name) { 		string click_to_add_points;@@ -71,7 +71,7 @@ public class PenTool : Tool { 		deselect_action.connect ((self) => { 			Glyph glyph = MainWindow.get_current_glyph (); 			-			CutTool.force_direction ();+			force_direction (); 			glyph.close_path (); 			 			move_point_on_path = false;@@ -115,10 +115,9 @@ public class PenTool : Tool { 		});  		release_action.connect ((self, b, ix, iy) => {-			Glyph glyph = MainWindow.get_current_glyph (); 			double x = ix; 			double y = iy;-+			 			join_paths (x, y);  			active_handle = new EditPointHandle.empty ();@@ -129,13 +128,13 @@ public class PenTool : Tool { 			 			// update path direction if it has changed 			foreach (Path p in clockwise) {-				if (!p.is_clockwise ()) {+				if (!p.is_open () && !p.is_clockwise ()) { 					p.reverse (); 				} 			}  			foreach (Path p in counter_clockwise) {-				if (p.is_clockwise ()) {+				if (!p.is_open () &&  p.is_clockwise ()) { 					p.reverse (); 				} 			}@@ -292,7 +291,7 @@ public class PenTool : Tool {  		if (button == 2) { 			if (glyph.is_open ()) {-				CutTool.force_direction ();+				force_direction (); 				glyph.close_path (); 			} else { 				glyph.open_path ();@@ -337,6 +336,43 @@ public class PenTool : Tool { 		glyph.store_undo_state (); 	} 	+	/** Set fill property to transparend for paths that is contained within +	 * another path.+	 */ +	public static void force_direction () {+		Glyph g = MainWindow.get_current_glyph ();+		+		// don't retain direction+		while (clockwise.length () > 0) {+			clockwise.remove_link (clockwise.first ());+		}+		+		while (counter_clockwise.length () > 0) {+			counter_clockwise.remove_link (counter_clockwise.first ());+		}++		foreach (Path p in g.active_paths) {+			if (p.is_open () && !p.has_direction ()) {+				if (is_counter_path (p)) {+					p.force_direction (Direction.COUNTER_CLOCKWISE);+				} else {+					p.force_direction (Direction.CLOCKWISE);+				}				+			}+		}+	}++	public static bool is_counter_path (Path path) {+		Glyph g = MainWindow.get_current_glyph ();+		PathList pl = new PathList ();+		+		foreach (Path p in g.path_list) {+			pl.paths.append (p);+		}+		+		return Path.is_clasped (pl, path);+	}+		 	bool is_new_point_from_path_selected () { 		return false; 	}@@ -355,7 +391,8 @@ public class PenTool : Tool { 	public void select_active_point (double x, double y) { 		Glyph? g = MainWindow.get_current_glyph (); 		Glyph glyph = (!) g;-+		bool reverse;+		 		control_point_event (x, y); 		 		if (active_edit_point == null) {@@ -392,9 +429,21 @@ public class PenTool : Tool { 		} 		 		// continue adding points from the selected one+		reverse = false; 		foreach (Path p in glyph.active_paths) { 			if (p.is_open () && p.points.length () > 0 && active_edit_point == p.points.first ().data) { 				p.reverse ();+				reverse = true;+			}+		}+		+		if (reverse) {+			while (clockwise.length () > 0) {+				clockwise.remove_link (clockwise.first ());+			}++			while (counter_clockwise.length () > 0) {+				counter_clockwise.remove_link (counter_clockwise.first ()); 			} 		} 	}@@ -431,10 +480,7 @@ public class PenTool : Tool { 		Glyph glyph = MainWindow.get_current_glyph (); 		Path? p; 		Path path;-		EditPointHandle hf, hn;-		double a, l;-		PointType t;-		EditPoint corner;+		bool direction_changed = false;  		if (glyph.path_list.length () < 1) { 			return;@@ -448,6 +494,7 @@ public class PenTool : Tool { 				 		if (active_edit_point == path.points.first ().data) { 			path.reverse ();+			direction_changed = !direction_changed; 		} 		 		// join path with it self@@ -472,6 +519,12 @@ public class PenTool : Tool { 			path.points.remove_link (path.points.last ()); 			 			path.close ();+			+			force_direction ();++			if (direction_changed) {+				path.reverse ();+			} 			return; 		} 		@@ -488,6 +541,7 @@ public class PenTool : Tool { 			 			if (is_close_to_point (merge.points.last ().data, x, y)) { 				merge.reverse ();+				direction_changed = !direction_changed; 			}  			return_if_fail (merge.points.length () > 0);@@ -507,10 +561,19 @@ public class PenTool : Tool {  				path.append_path (merge); 				path.reopen ();-	+				+				force_direction ();+				+				if (direction_changed) {+					path.reverse ();+				} 				return; 			} 		}++		if (direction_changed) {+			path.reverse ();+		} 	} 	 	/** Merge paths if ends are close. */diff --git a/libbirdfont/Toolbox.vala b/libbirdfont/Toolbox.valaindex 89dc4a5..76f4dfe 100644--- a/libbirdfont/Toolbox.vala+++ b/libbirdfont/Toolbox.vala@@ -77,9 +77,6 @@ public class Toolbox : GLib.Object  { 		ZoomTool zoom_tool = new ZoomTool ("zoom_tool"); 		draw_tools.add_tool (zoom_tool); -		CutTool cut_tool = new CutTool ("cut");-		draw_tools.add_tool (cut_tool);	- 		Tool move_tool = new MoveTool ("move"); 		draw_tools.add_tool (move_tool); 

Contact

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