Clone in a terminal:
Commit 80f5f2d
Johan Mattsson - 2013-08-09T09:45:14+00:00
80f5f2deeee4c7eceee7f2db8a57cdcfa9e0e7f7johan.mattsson.m@gmail.com

rectangles

Changed files (5)

Diff

diff --git a/icons/rectangle.png b/icons/rectangle.pngnew file mode 100644index 0000000..3f8d716Binary files /dev/null and b/icons/rectangle.png differdiff --git a/libbirdfont/CircleTool.vala b/libbirdfont/CircleTool.valaindex 1db20a2..d6592c1 100644--- a/libbirdfont/CircleTool.vala+++ b/libbirdfont/CircleTool.vala@@ -34,13 +34,6 @@ public class CircleTool : Tool { 	 	public CircleTool (string n) { 		base (n, _("Circle"));-		-		select_action.connect((self) => {-		});--		deselect_action.connect((self) => {-			Glyph glyph = MainWindow.get_current_glyph ();-		}); 				 		press_action.connect((self, b, x, y) => { 			press (b, x, y);@@ -101,7 +94,6 @@ public class CircleTool : Tool { 		double radius = 2; 		double px, py, steps; 		Path path = new Path ();-		PointType type; 		 		press_x = x; 		press_y = y;@@ -123,28 +115,7 @@ public class CircleTool : Tool { 			path.add (px, py); 		} 		-		switch (Toolbox.point_type) {-			case PointType.QUADRATIC:-				type = PointType.LINE_QUADRATIC;-				break;-			case PointType.DOUBLE_CURVE:-				type = PointType.LINE_DOUBLE_CURVE;-				break;-			case PointType.CUBIC:-				type = PointType.LINE_CUBIC;-				break;-			default:-				warning ("No type is set");-				type = PointType.LINE_CUBIC;-				break;-		}-				-		foreach (EditPoint ep in path.points) {-			ep.type = type;-			ep.get_right_handle ().type = type;-			ep.get_left_handle ().type = type;-		}-		+		path.init_point_type (); 		path.close (); 		path.recalculate_linear_handles (); diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex 48f1e17..5683d83 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -2143,6 +2143,32 @@ public class Path { 		 		update_region_boundries (); 	}++	public void init_point_type () {+		PointType type;+		+		switch (Toolbox.point_type) {+			case PointType.QUADRATIC:+				type = PointType.LINE_QUADRATIC;+				break;+			case PointType.DOUBLE_CURVE:+				type = PointType.LINE_DOUBLE_CURVE;+				break;+			case PointType.CUBIC:+				type = PointType.LINE_CUBIC;+				break;+			default:+				warning ("No type is set");+				type = PointType.LINE_CUBIC;+				break;+		}+				+		foreach (EditPoint ep in points) {+			ep.type = type;+			ep.get_right_handle ().type = type;+			ep.get_left_handle ().type = type;+		}		+	} }  }diff --git a/libbirdfont/RectangleTool.vala b/libbirdfont/RectangleTool.valanew file mode 100644index 0000000..4c63b13--- /dev/null+++ b/libbirdfont/RectangleTool.vala@@ -0,0 +1,95 @@+/*+    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.+*/++using Math;+using Cairo;++namespace BirdFont {++public class RectangleTool : Tool {++	Path rectangle = new Path ();++	double press_x = -1;+	double press_y = -1;+	+	bool resize = false;+	+	public RectangleTool (string n) {+		base (n, _("Rectangle"));++		press_action.connect((self, b, x, y) => {+			press (b, x, y);+		});++		release_action.connect((self, b, x, y) => {+			press_x = -1;+			press_y = -1;+			rectangle = new Path ();+			resize = false;+		});+		+		move_action.connect ((self, x, y)	 => {+			move (x, y);+		});+	}+	+	void move (double x, double y) {+		Glyph g;+		double x1, y1, x2, y2;++		if (resize) {+			g = MainWindow.get_current_glyph ();+			g.delete_path (rectangle);+			+			rectangle = new Path ();+			+			x1 = Glyph.path_coordinate_x (press_x); +			y1 = Glyph.path_coordinate_y (press_y);+			x2 = Glyph.path_coordinate_x (x); +			y2 = Glyph.path_coordinate_y (y);++			if (GridTool.is_visible ()) {+				GridTool.tie_coordinate (ref x1, ref y1);+				GridTool.tie_coordinate (ref x2, ref y2);+			}+					+			rectangle.add (x1, y1);+			rectangle.add (x2, y1);+			rectangle.add (x2, y2);+			rectangle.add (x1, y2);++			rectangle.init_point_type ();++			g.add_path (rectangle);+			+			foreach (EditPoint e in rectangle.points) {+				e.recalculate_linear_handles ();+			}+			+			MainWindow.get_glyph_canvas ().redraw ();+		}+	}+	+	void press (int button, double x, double y) {+		Glyph glyph = MainWindow.get_current_glyph ();+		press_x = x;+		press_y = y;+		resize = true;+		+		MainWindow.get_glyph_canvas ().redraw ();+	}+}++}diff --git a/libbirdfont/Toolbox.vala b/libbirdfont/Toolbox.valaindex ba0fcb8..06b8d69 100644--- a/libbirdfont/Toolbox.vala+++ b/libbirdfont/Toolbox.vala@@ -439,6 +439,9 @@ public class Toolbox : GLib.Object  { 		Tool circle = new CircleTool ("circle"); 		shape_tools.add_tool (circle); 		+		Tool rectangle = new RectangleTool ("rectangle");+		shape_tools.add_tool (rectangle);+				 		// background tools 		background_scale = new SpinButton ("scale_background", _("Set size for background image")); 		background_scale.set_int_value ("1.000");

Contact

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