Clone in a terminal:
Commit c2e2d29
Johan Mattsson - 2016-06-27T12:07:00+00:00
c2e2d294391f0e56686e641f048d69333f14b5b7johan.mattsson.m@gmail.com

Fix rotation

Changed files (4)

Diff

diff --git a/libbirdfont/DrawingTools.vala b/libbirdfont/DrawingTools.valaindex 153b59c..e528e11 100644--- a/libbirdfont/DrawingTools.vala+++ b/libbirdfont/DrawingTools.vala@@ -390,12 +390,42 @@ public class DrawingTools : ToolCollection  { 			 			if (glyph.active_paths.size > 0) { 				last_path = glyph.active_paths.get (glyph.active_paths.size - 1);-				resize_tool.rotate_selected_paths (angle - last_path.transforms.rotation, x, y);		+				+				double last_angle;+				+				if (last_path is PathObject) {+					last_angle = ((PathObject) last_path).get_path ().rotation;+				} else {+					last_angle = last_path.transforms.total_rotation;+				}+				+				double r = angle - last_angle;+				resize_tool.rotate_selected_paths (r, x, y); 			} 			 			GlyphCanvas.redraw (); 		}); 		+		move_tool.selection_changed.connect (() => {+			Glyph glyph = MainWindow.get_current_glyph ();+			SvgBird.Object path;+			+			if (glyph.active_paths.size > 0) {+				path = glyph.active_paths.get (glyph.active_paths.size - 1);++				double angle;+				+				if (path is PathObject) {+					angle = ((PathObject) path).get_path ().rotation;+				} else {+					angle = path.transforms.total_rotation;+				}+				+				angle *= 180 / PI;+				rotation.set_value_round (angle, true, false);+			}+		});+		 		resize_tool.objects_rotated.connect ((angle) => { 			rotation.set_value_round (angle, true, false); 			PenTool.reset_stroke ();diff --git a/libbirdfont/MoveTool.vala b/libbirdfont/MoveTool.valaindex 2dd8be5..85cf1c0 100644--- a/libbirdfont/MoveTool.vala+++ b/libbirdfont/MoveTool.vala@@ -169,7 +169,6 @@ public class MoveTool : Tool { 		if (glyph.active_paths.size > 0) { 			selection_changed (); 			objects_moved ();-			DrawingTools.resize_tool.signal_objects_rotated (); 			 			foreach (SvgBird.Object o in glyph.active_paths) { 				if (o is PathObject) {diff --git a/libbirdfont/ResizeTool.vala b/libbirdfont/ResizeTool.valaindex e31fd3b..cc14186 100644--- a/libbirdfont/ResizeTool.vala+++ b/libbirdfont/ResizeTool.vala@@ -43,7 +43,7 @@ public class ResizeTool : Tool { 	static bool rotate_path = false; 	static double last_rotate_y; 	static double rotation = 0;-	static double last_rotate = 0;+	public static double last_rotate = 0; 	 	public double last_skew = 0; 	@@ -64,6 +64,24 @@ public class ResizeTool : Tool { 		horizontal_handle.load_font ("icons.bf"); 		Theme.text_color (horizontal_handle, "Highlighted 1"); 	+		DrawingTools.move_tool.selection_changed.connect (() => {+			Glyph glyph = MainWindow.get_current_glyph ();+			SvgBird.Object path;+			+			if (glyph.active_paths.size > 0) {+				path = glyph.active_paths.get (glyph.active_paths.size - 1);+				+				if (path is PathObject) {+					last_rotate = ((PathObject) path).get_path ().rotation;+				} else {+					last_rotate = path.transforms.total_rotation;+				}+			}+			+			rotation = last_rotate;+			update_resized_boundaries ();+		});+	 		select_action.connect((self) => { 		}); @@ -235,13 +253,8 @@ public class ResizeTool : Tool { 		return d; 	} -	public void signal_objects_rotated () {-		objects_rotated (rotation * (180 / PI));-	}- 	public void rotate_selected_paths (double angle, double cx, double cy) { 		Glyph glyph = MainWindow.get_current_glyph ();  -		SvgBird.Object last_path; 		double x, y; 		 		glyph.layers.update_boundaries_for_object ();@@ -252,20 +265,21 @@ public class ResizeTool : Tool { 				x = selection_box_left - svg.x + selection_box_width / 2; 				y = selection_box_top + svg.y + selection_box_height / 2; 				p.transforms.rotate (angle, x, y);+				rotation = p.transforms.total_rotation; 			} else if (p is PathObject) { 				Path path = ((PathObject) p).get_path (); 				SvgTransforms transform = new SvgTransforms (); 				transform.rotate (-angle, selection_box_center_x, selection_box_center_y); 				Matrix matrix = transform.get_matrix (); 				path.transform (matrix);+				path.rotation += angle;+				rotation = path.rotation; 			} 		}  		last_rotate = rotation;  		if (glyph.active_paths.size > 0) {-			last_path = glyph.active_paths.get (glyph.active_paths.size - 1);-			 			if (rotation > PI) { 				rotation -= 2 * PI; 			}@@ -274,7 +288,7 @@ public class ResizeTool : Tool { 				last_rotate -= 2 * PI; 			} 			-			signal_objects_rotated ();+			objects_rotated (rotation * (180 / PI)); 		} 	} 	diff --git a/libsvgbird/SvgTransforms.vala b/libsvgbird/SvgTransforms.valaindex 354d154..43c65f8 100644--- a/libsvgbird/SvgTransforms.vala+++ b/libsvgbird/SvgTransforms.vala@@ -22,6 +22,7 @@ public class SvgTransforms : GLib.Object { 	public Gee.ArrayList<SvgTransform> transforms; 	 	public double rotation = 0;+	public double total_rotation = 0; 	public double scale_x = 1; 	public double scale_y = 1; 	@@ -64,6 +65,7 @@ public class SvgTransforms : GLib.Object {  	public void rotate (double theta, double x, double y) { 		rotation += theta;+		total_rotation += theta; 		 		while (rotation > 2 * Math.PI) { 			rotation -= 2 * Math.PI;@@ -73,6 +75,14 @@ public class SvgTransforms : GLib.Object { 			rotation += 2 * Math.PI; 		} +		while (total_rotation > 2 * Math.PI) {+			total_rotation -= 2 * Math.PI;+		}++		while (total_rotation < -2 * Math.PI) {+			total_rotation += 2 * Math.PI;+		}+ 		rotation_matrix = Matrix.identity (); 		rotation_matrix.translate (x, y); 		rotation_matrix.rotate (rotation);

Contact

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