Clone in a terminal:
Commit 59d6244
Johan Mattsson - 2015-05-04T10:39:29+00:00
59d6244a90f7cafe8521037784ca10ead3e834b5johan.mattsson.m@gmail.com

Give press event method a name

Changed files (3)

Diff

diff --git a/libbirdfont/ForesightTool.vala b/libbirdfont/ForesightTool.valaindex 311ca67..ab298b5 100644--- a/libbirdfont/ForesightTool.vala+++ b/libbirdfont/ForesightTool.vala@@ -37,6 +37,9 @@ public class ForesightTool : Tool {  	public bool skip_deselect = false; +	static int press_counter = 0;+	bool button_pressed = false;+	 	public ForesightTool (string name) { 		base (name, t_ ("Create Beziér curves")); @@ -50,6 +53,8 @@ public class ForesightTool : Tool { 			MainWindow.get_current_glyph ().clear_active_paths (); 			MainWindow.set_cursor (NativeWindow.VISIBLE); 			state = NONE;+			+			print (@"select press_action\n"); 		});  		deselect_action.connect ((self) => {@@ -61,101 +66,24 @@ public class ForesightTool : Tool { 			 			MainWindow.set_cursor (NativeWindow.VISIBLE); 			state = NONE;+			+			print (@"deselect press_action\n"); 		}); 		 		press_action.connect ((self, b, x, y) => {-			PenTool p = (PenTool) PointTool.pen ();-			PointSelection ps;-			EditPoint first_point;-			bool clockwise;-			Path? path = null;-			bool one_point = false;-			-			MainWindow.set_cursor (NativeWindow.HIDDEN);-				-			if (b == 2) {-				stop_drawing ();-				return;-			} --			BirdFont.get_current_font ().touch ();-			MainWindow.get_current_glyph ().store_undo_state ();--			last_move_x = x;-			last_move_y = y;--			if (previous_point > 0) {-				previous_point = 0;-				state = MOVE_POINT;-			} else {-				if (state == MOVE_POINT) {			-					state = MOVE_HANDLES;-					-					path = PenTool.find_path_to_join ();-					-					if (path != null) {-						one_point = (((!) path).points.size == 1);-					}-					-					if (p.has_join_icon ()) {-						// FIXME: last activa path in list-						ps = new PointSelection (PenTool.active_path.points.get (PenTool.active_path.points.size - 1), PenTool.active_path);-						ps.point.set_tie_handle (false);-						-						ps = new PointSelection (PenTool.active_path.points.get (0), PenTool.active_path);-						ps.point.set_tie_handle (false);-						-						first_point = PenTool.active_path.points.get (0);-						clockwise = PenTool.active_path.is_clockwise ();-		-						PenTool.move_selected = false;-						p.release_action (p, 2, x, y);-						-						PenTool.move_selected = false;-						p.press_action (p, 2, x, y);-						-						if (ps.path.has_point (first_point)) {-							ps.path.reverse ();-						}-						-						if (clockwise && PenTool.active_path.is_clockwise ()) {-							ps = new PointSelection (PenTool.active_path.points.get (0), PenTool.active_path);-						} else {-							ps = new PointSelection (PenTool.active_path.points.get (PenTool.active_path.points.size - 1), PenTool.active_path);-						}-						-						PenTool.selected_points.clear ();-						PenTool.selected_points.add (ps);-						PenTool.selected_point = ps.point; -						-						state = MOVE_LAST_HANDLE;-						-						if (one_point) {-							p.press_action (p, 2, x, y);-							state = NONE;-						}-					}-				} -			}-			-			if (state == NONE) {-				state = MOVE_POINT;-				PenTool.active_path = get_active_path ();-				-				add_new_point (x, y);-				-				PenTool.last_point_x = Glyph.path_coordinate_x (x);-				PenTool.last_point_y = Glyph.path_coordinate_y (y);-				-				move_action (this, x, y);-				state = MOVE_FIRST_HANDLE;-				release_action(this, b, x, y);-			}+			press (b, x, y); 		});  		release_action.connect ((self, b, x, y) => { 			PenTool p = (PenTool) PointTool.pen (); 			PointSelection last;++			if (!button_pressed) {+				warning ("!button_pressed");+				return;+			}+			+			print (@"bezier release_action\n"); 			 			if (state == MOVE_HANDLES || state == MOVE_FIRST_HANDLE) { 				if (state != MOVE_FIRST_HANDLE) {@@ -191,6 +119,7 @@ public class ForesightTool : Tool { 			} 			 			current_path.hide_end_handle = true;+			button_pressed = false; 		});  		move_action.connect ((self, x, y) => {@@ -330,6 +259,104 @@ public class ForesightTool : Tool { 		}); 	} 	+	public void press (int b, int x, int y) {+		PenTool p = (PenTool) PointTool.pen ();+		PointSelection ps;+		EditPoint first_point;+		bool clockwise;+		Path? path = null;+		bool one_point = false;+		+		if (button_pressed) {+			warning ("no release event");+			return;+		}+		button_pressed = true;+		+		MainWindow.set_cursor (NativeWindow.HIDDEN);+		+		print (@"$(press_counter++) bezier press_action\n");+		+		if (b == 2) {+			stop_drawing ();+			return;+		} ++		BirdFont.get_current_font ().touch ();+		MainWindow.get_current_glyph ().store_undo_state ();++		last_move_x = x;+		last_move_y = y;++		if (previous_point > 0) {+			previous_point = 0;+			state = MOVE_POINT;+		} else {+			if (state == MOVE_POINT) {			+				state = MOVE_HANDLES;+				+				path = PenTool.find_path_to_join ();+				+				if (path != null) {+					one_point = (((!) path).points.size == 1);+				}+				+				if (p.has_join_icon ()) {+					// FIXME: last activa path in list+					ps = new PointSelection (PenTool.active_path.points.get (PenTool.active_path.points.size - 1), PenTool.active_path);+					ps.point.set_tie_handle (false);+					+					ps = new PointSelection (PenTool.active_path.points.get (0), PenTool.active_path);+					ps.point.set_tie_handle (false);+					+					first_point = PenTool.active_path.points.get (0);+					clockwise = PenTool.active_path.is_clockwise ();++					PenTool.move_selected = false;+					p.release_action (p, 2, x, y);+					+					PenTool.move_selected = false;+					p.press_action (p, 2, x, y);+					+					if (ps.path.has_point (first_point)) {+						ps.path.reverse ();+					}+					+					if (clockwise && PenTool.active_path.is_clockwise ()) {+						ps = new PointSelection (PenTool.active_path.points.get (0), PenTool.active_path);+					} else {+						ps = new PointSelection (PenTool.active_path.points.get (PenTool.active_path.points.size - 1), PenTool.active_path);+					}+					+					PenTool.selected_points.clear ();+					PenTool.selected_points.add (ps);+					PenTool.selected_point = ps.point; +					+					state = MOVE_LAST_HANDLE;+					+					if (one_point) {+						p.press_action (p, 2, x, y);+						state = NONE;+					}+				}+			} +		}+		+		if (state == NONE) {+			state = MOVE_POINT;+			PenTool.active_path = get_active_path ();+			+			add_new_point (x, y);+			+			PenTool.last_point_x = Glyph.path_coordinate_x (x);+			PenTool.last_point_y = Glyph.path_coordinate_y (y);+			+			move_action (this, x, y);+			state = MOVE_FIRST_HANDLE;+			release_action(this, b, x, y);+		}	+	}+	 	public void stop_drawing () { 		PenTool p = (PenTool) PointTool.pen (); 		Path a;@@ -338,8 +365,14 @@ public class ForesightTool : Tool { 		 		if (state != NONE) { 			a = get_active_path ();-			if (a.is_open () && state != NONE) {+			if (a.is_open ()) { 				a.delete_last_point ();++				a.get_first_point ().set_reflective_handles (false);+				a.get_first_point ().set_tie_handle (false);++				a.get_last_point ().set_reflective_handles (false);+				a.get_last_point ().set_tie_handle (false); 			} 		} 	@@ -356,7 +389,9 @@ public class ForesightTool : Tool { 	 	public Path get_active_path () { 		Glyph g = MainWindow.get_current_glyph ();-		return_val_if_fail (g.active_paths.size > 0, new Path ());+		if (g.active_paths.size == 0) {+			return new Path ();+		} 		return g.active_paths.get (g.active_paths.size -1); 	} 	@@ -380,6 +415,7 @@ public class ForesightTool : Tool { 		PointSelection last; 		double handle_x, handle_y; 		+		print (@"add_new_point: $(PenTool.active_path.points.size)\n"); 		PenTool p = (PenTool) PointTool.pen ();  		if (PenTool.active_path.points.size == 0) {diff --git a/libbirdfont/PenTool.vala b/libbirdfont/PenTool.valaindex 19b3eea..48a3ad8 100644--- a/libbirdfont/PenTool.vala+++ b/libbirdfont/PenTool.vala@@ -76,6 +76,9 @@ public class PenTool : Tool { 	public static double simplification_threshold = 0.5; 		 	public static bool retain_angle = false;+	bool button_pressed = false;+	+	static int press_counter = 0; 	 	public PenTool (string name) {	 		base (name, t_("Add new points"));@@ -101,7 +104,16 @@ public class PenTool : Tool { 			MainWindow.get_current_glyph ().clear_active_paths (); 		}); 				-		press_action.connect ((self, b, x, y) => {		+		press_action.connect ((self, b, x, y) => {+			if (button_pressed) {+				warning ("Unexpected event");+				return;+			}+			+			print (@"$(press_counter++) pen press_action\n");+			+			button_pressed = true;+			 			// retain path direction 			clockwise = new Gee.ArrayList<Path> (); 			counter_clockwise = new Gee.ArrayList<Path> ();@@ -144,7 +156,7 @@ public class PenTool : Tool { 			last_point_x = Glyph.path_coordinate_x (x); 			last_point_y = Glyph.path_coordinate_y (y); 			-			if (!move_selected_handle && !move_selected) {+			if (!move_selected_handle && !move_selected && !button_pressed) { 				press (b, x, y, true); 			} else { 				warning ("double click suppressed");@@ -203,6 +215,8 @@ public class PenTool : Tool { 					p.get_last_point ().set_reflective_handles (false); 				} 			}+			+			button_pressed = false; 		});  		move_action.connect ((self, x, y) => {@@ -869,6 +883,11 @@ public class PenTool : Tool { 		Glyph glyph = (!) g; 		PointSelection ps; 		+		if (move_selected_handle)  {+			warning ("moving handle");+			return;+		}+		 		return_if_fail (g != null); 		 		remove_all_selected_points ();@@ -978,9 +997,6 @@ public class PenTool : Tool { 			if (p.is_open () && p.points.size >= 1  				&& (active_edit_point == p.points.get (0)  				|| active_edit_point == p.points.get (p.points.size - 1))) {-				active_path = p;-				glyph.set_active_path (p);-				 				update_selection (); 				reverse = true; 				control_point_event (x, y);@@ -1539,6 +1555,9 @@ public class PenTool : Tool {  		if (distance < contact_surface) { 			set_active_edit_point (e.point, e.path);+			+			active_path = e.path;+			g.add_active_path (active_path); 		} 	} 	@@ -1564,6 +1583,8 @@ public class PenTool : Tool { 		glyph.clear_active_paths (); 		glyph.add_active_path (new_point.path); 		+		print (@"PointSelection new_point_action; $(glyph.active_paths.size)\n");+		 		move_selected = true; 		 		return new_point;diff --git a/libbirdfont/StrokeTool.vala b/libbirdfont/StrokeTool.valaindex ebbf7bc..a8ebe46 100644--- a/libbirdfont/StrokeTool.vala+++ b/libbirdfont/StrokeTool.vala@@ -1664,7 +1664,10 @@ public class StrokeTool : Tool {  		Path path = original_path.copy (); -		path.add_hidden_double_points (); // FIXME:+		if (path.points.size > 1) {+			path.add_hidden_double_points (); // FIXME:+		}+		 		foreach (EditPoint ep in path.points) { 			if (ep.type == PointType.DOUBLE_CURVE || ep.type == PointType.LINE_DOUBLE_CURVE) { 				PenTool.convert_point_type (ep, PointType.QUADRATIC);@@ -1708,8 +1711,8 @@ public class StrokeTool : Tool { 			p2 = path.points.get ((i + 1) % path.points.size); 			p3 = path.points.get ((i + 2) % path.points.size); -			tolerance = 0.13 / sqrt (stroke_width);-			// tolerance = 2 / sqrt (stroke_width);+			//tolerance = 0.13 / sqrt (stroke_width);+			tolerance = 1.6 / sqrt (stroke_width); 			step_increment = 1.05; 			step_size = 0.039 / stroke_width; 

Contact

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