Clone in a terminal:
Commit 68508b7
Johan Mattsson - 2012-10-26T18:03:53+00:00
68508b740f889d8f694acdeb8d2690a54ba7d0aajohan.mattsson.m@gmail.com

resize path

Changed files (5)

Diff

diff --git a/icons/resize.png b/icons/resize.pngdeleted file mode 100644index 2cfa6a8..0000000Binary files a/icons/resize.png and /dev/null differdiff --git a/icons/resize_handle.png b/icons/resize_handle.pngnew file mode 100644index 0000000..c3e19b7Binary files /dev/null and b/icons/resize_handle.png differdiff --git a/src/Glyph.vala b/src/Glyph.valaindex 83c67a2..5faeb4b 100644--- a/src/Glyph.vala+++ b/src/Glyph.vala@@ -1369,11 +1369,6 @@ public class Glyph : FontDisplay { 			draw_help_lines (cmp); 			cmp.restore (); 		}-				-		cmp.save (); -		tool = MainWindow.get_toolbox ().get_current_tool ();-		tool.draw_action (tool, cmp, this);-		cmp.restore ();  		if (zoom_area_is_visible) { 			cmp.save ();@@ -1388,7 +1383,12 @@ public class Glyph : FontDisplay { 			draw_path (cmp); 			cmp.restore (); 		}-		++		cmp.save (); +		tool = MainWindow.get_toolbox ().get_current_tool ();+		tool.draw_action (tool, cmp, this);+		cmp.restore ();+				 		cr.save (); 		cr.set_source_surface (ps, 0, 0); 		cr.paint ();diff --git a/src/MoveTool.vala b/src/MoveTool.valaindex 2e70822..5cebd7a 100644--- a/src/MoveTool.vala+++ b/src/MoveTool.vala@@ -15,17 +15,27 @@     along with this program.  If not, see <http://www.gnu.org/licenses/>. */ +using Math;+using Cairo;+ namespace Supplement {  class MoveTool : Tool {  	bool move_path = false;- 	double last_x = 0; 	double last_y = 0;++	bool resize_path = false;+	Path? resized_path = null;+	double last_resize_y;+	+	ImageSurface? resize_handle; 	 	public MoveTool (string n) { 		base (n, "Move paths", 'm', CTRL);+		+		resize_handle = Icons.get_icon ("resize_handle.png"); 	 		select_action.connect((self) => { 		});@@ -36,10 +46,19 @@ class MoveTool : Tool { 		}); 				 		press_action.connect((self, b, x, y) => {+			double handle_x, handle_y; 			Glyph glyph = MainWindow.get_current_glyph ();-			+						 			glyph.store_undo_state (); 			+			foreach (Path p in glyph.active_paths) {+				is_over_resize_handle (p, x, y);+			}+			+			if (resized_path != null) {+				is_over_resize_handle ((!) resized_path, x, y);+			}+			 			if (!glyph.is_over_selected_path (x, y)) { 				if (!glyph.select_path (x, y)) { 					glyph.clear_active_paths ();@@ -54,7 +73,9 @@ class MoveTool : Tool {  		release_action.connect((self, b, x, y) => { 			Glyph glyph = MainWindow.get_current_glyph ();+			 			move_path = false;+			resize_path = false; 				 			if (GridTool.is_visible ()) { 				foreach (Path p in glyph.active_paths) {@@ -64,21 +85,35 @@ class MoveTool : Tool { 		}); 		 		move_action.connect ((self, x, y)	 => {+			Glyph glyph = MainWindow.get_current_glyph ();+			double dx = last_x - x;+			double dy = last_y - y; +			double p = PenTool.precision;+			Path rp;+			double h, ratio;+			 			if (move_path) {-				Glyph glyph = MainWindow.get_current_glyph ();-				double dx = last_x - x;-				double dy = last_y - y; -				double p = PenTool.precision;- 				foreach (Path path in glyph.active_paths) { 					path.move (glyph.ivz () * -dx * p, glyph.ivz () * dy * p); 				}+			}+			+			if (resize_path) {+				return_if_fail (!is_null (resized_path));+				rp = (!) resized_path;+				h = rp.xmax - rp.xmin; 				-				MainWindow.get_glyph_canvas ().redraw ();+				ratio = 1;+				ratio -= p * (Glyph.path_coordinate_y (last_resize_y) - Glyph.path_coordinate_y (y)) / h; 				-				last_x = x;-				last_y = y;+				rp.resize (ratio);+				last_resize_y = y; 			}++			last_x = x;+			last_y = y;++			MainWindow.get_glyph_canvas ().redraw (); 		}); 		 		key_press_action.connect ((self, keyval) => {@@ -91,6 +126,32 @@ class MoveTool : Tool { 				} 			} 		});+		+		draw_action.connect ((self, cr, glyph) => {+			Glyph g = MainWindow.get_current_glyph ();+			ImageSurface img = (!) resize_handle;+		+			foreach (Path p in g.active_paths) {+				cr.set_source_surface (img, Glyph.reverse_path_coordinate_x (p.xmax) - 10, Glyph.reverse_path_coordinate_y (p.ymax) - 10);+				cr.paint ();	+			}+			+			if (resized_path != null) {+				cr.set_source_surface (img, Glyph.reverse_path_coordinate_x (((!) resized_path).xmax) - 10, Glyph.reverse_path_coordinate_y (((!)resized_path).ymax) - 10);+				cr.paint ();+			}+		});+	}++	void is_over_resize_handle (Path p, double x, double y) {+		double handle_x = Math.fabs (Glyph.reverse_path_coordinate_x (p.xmax)); +		double handle_y = Math.fabs (Glyph.reverse_path_coordinate_y (p.ymax));+	+		if (fabs (handle_x - x + 10) < 20 && fabs (handle_y - y + 10) < 20) {+			resize_path = true;+			resized_path = p;+			last_resize_y = y;+		}		 	}  	void tie_path_to_grid (Path p, double x, double y) {diff --git a/src/Path.vala b/src/Path.valaindex fbd6dff..6c27d01 100644--- a/src/Path.vala+++ b/src/Path.vala@@ -591,48 +591,32 @@ public class Path { 	} 	 	public void resize (double ratio) {-		double w, h, cx, cy;-		-		update_region_boundries ();+		double h = ymax - ymin;+		double px, py, nx, ny;++		px = xmin;+		py = ymin; 		-		w = Math.fabs(xmax - xmin);-		h = Math.fabs(ymax - ymin);-		cx = w / 2 + xmin; -		cy = h / 2 + ymin;+		if (ratio < 1 && h < 2) {+			return;+		} 		-		if (ratio == 1) return;+		foreach (var p in points) {+			p.x *= ratio;+			p.y *= ratio;+			p.right_handle.length *= ratio;+			p.left_handle.length *= ratio;+		} 		-		if (ratio < 1) {-			ratio = 1 - ratio;-			-			foreach (var p in points) {-				if (p.x < cx)-					p.x += (cx - p.x) * ratio;-				else-					p.x -= (p.x - cx) * ratio;+		xmin *= ratio;	+		xmax *= ratio;+		ymin *= ratio;+		ymax *= ratio; -				if (p.y > cy)-					p.y += (cy - p.y) * ratio;-				else-					p.y -= (p.y - cy) * ratio;				-			}-				-		} else {-			ratio = ratio - 1;-			-			foreach (var p in points) {-				if (p.x < cx)-					p.x -= (cx - p.x) * ratio;-				else-					p.x += (p.x - cx) * ratio;--				if (p.y > cy)-					p.y -= (cy - p.y) * ratio;-				else-					p.y += (p.y - cy) * ratio;				-			}-			-		}+		nx = xmin;+		ny = ymin;+		+		move (px - nx, py - ny); 	} 	 	public Path copy () {

Contact

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