Clone in a terminal:
Commit be9fedb
Johan Mattsson - 2014-08-13T19:46:54+00:00
be9fedb974f70860bce8f5d1ed10e714e15ca466johan.mattsson.m@gmail.com

Rotation setting

Changed files (7)

Diff

diff --git a/graphics/tools_and_buttons.svg b/graphics/tools_and_buttons.svgindex 004d718..c364bf3 100644--- a/graphics/tools_and_buttons.svg+++ b/graphics/tools_and_buttons.svg@@ -905,17 +905,17 @@      borderopacity="1.0"      inkscape:pageopacity="0.0"      inkscape:pageshadow="2"-     inkscape:zoom="5.6568542"-     inkscape:cx="42.799888"-     inkscape:cy="630.94131"+     inkscape:zoom="4"+     inkscape:cx="102.84323"+     inkscape:cy="622.80931"      inkscape:current-layer="layer1"      inkscape:document-units="px"      showgrid="false"-     inkscape:window-width="707"-     inkscape:window-height="399"-     inkscape:window-x="344"-     inkscape:window-y="96"-     inkscape:window-maximized="0"+     inkscape:window-width="1215"+     inkscape:window-height="776"+     inkscape:window-x="65"+     inkscape:window-y="24"+     inkscape:window-maximized="1"      showguides="true"      inkscape:guide-bbox="true"      inkscape:object-paths="true" />@@ -2820,5 +2820,33 @@            d="m 55.480122,118.24792 c -0.304691,0.78125 -0.601566,1.29102 -0.890625,1.5293 -0.289066,0.23828 -0.675784,0.35742 -1.160157,0.35742 l -0.861328,0 0,-0.90234 0.632813,0 c 0.296873,0 0.527341,-0.0703 0.691406,-0.21094 0.16406,-0.14062 0.3457,-0.47265 0.544922,-0.99609 l 0.193359,-0.49219 -2.654297,-6.45703 1.142578,0 2.050782,5.13281 2.050781,-5.13281 1.142578,0 -2.882812,7.17187" />       </g>     </g>+    <g+       id="g4192"+       inkscape:export-filename="/home/johan/birdfont/icons/rotation.png"+       inkscape:export-xdpi="319"+       inkscape:export-ydpi="319">+      <path+         sodipodi:nodetypes="ccc"+         inkscape:connector-curvature="0"+         id="path3401"+         d="m 89.290787,110.036 9.854719,7.23734 -11.261263,0"+         style="fill:none;stroke:#929292;stroke-width:1.03757298" />+      <path+         transform="matrix(0.65036638,0,0,0.63938053,48.565454,38.30076)"+         d="m 81.140504,110.56747 a 3.005204,3.005204 0 1 1 -6.010408,0 3.005204,3.005204 0 1 1 6.010408,0 z"+         sodipodi:ry="3.005204"+         sodipodi:rx="3.005204"+         sodipodi:cy="110.56747"+         sodipodi:cx="78.1353"+         id="path3407"+         style="color:#000000;fill:none;stroke:#929292;stroke-width:1.55074811;stroke-miterlimit:4;stroke-dasharray:none;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"+         sodipodi:type="arc" />+      <path+         sodipodi:nodetypes="cc"+         inkscape:connector-curvature="0"+         id="path4182"+         d="m 93.495716,117.27334 c -0.157363,-1.32965 0.176971,-2.44858 1.185615,-3.27851"+         style="fill-opacity:1;stroke:#929292" />+    </g>   </g> </svg>diff --git a/icons/rotation.png b/icons/rotation.pngnew file mode 100644index 0000000..219a138Binary files /dev/null and b/icons/rotation.png differdiff --git a/libbirdfont/DrawingTools.vala b/libbirdfont/DrawingTools.valaindex 5eb98a8..1f4e32c 100644--- a/libbirdfont/DrawingTools.vala+++ b/libbirdfont/DrawingTools.vala@@ -37,8 +37,8 @@ public class DrawingTools : ToolCollection  {  	PointTool point_tool; 	ZoomTool zoom_tool;-	Tool resize_tool;-	Tool stroke_tool;+	public static ResizeTool resize_tool;+	StrokeTool stroke_tool; 	TrackTool track_tool; 	 	Tool quadratic_points;@@ -199,11 +199,11 @@ public class DrawingTools : ToolCollection  { 		SpinButton x_coordinate = new SpinButton ("x_coordinate", t_("X coordinate")); 		x_coordinate.set_big_number (true); 		x_coordinate.set_int_value ("0.000");-		x_coordinate.set_int_step (0.001);-		x_coordinate.set_wait_for_submit (true);+		x_coordinate.set_int_step (0.1); 		x_coordinate.set_min (-999.99); 		x_coordinate.set_max (999.99); 		x_coordinate.show_icon (true);+		x_coordinate.set_persistent (false); 		x_coordinate.new_value_action.connect((self) => { 			Glyph glyph = MainWindow.get_current_glyph (); 			double x, y, w, h;@@ -217,7 +217,7 @@ public class DrawingTools : ToolCollection  { 			} 			 			GlyphCanvas.redraw ();-		});+		});	 		draw_tool_modifiers.add_tool (x_coordinate);  		move_tool.objects_moved.connect (() => {@@ -234,15 +234,19 @@ public class DrawingTools : ToolCollection  { 				- glyph.left_limit, true, false); 		}); +		move_tool.objects_deselected.connect (() => {+			x_coordinate.set_value_round (0, true, false);+			x_coordinate.hide_value ();+		}); 		// y coordinate 		SpinButton y_coordinate = new SpinButton ("y_coordinate", t_("Y coordinate")); 		y_coordinate.set_big_number (true); 		y_coordinate.set_int_value ("0.000");-		y_coordinate.set_int_step (0.001);-		y_coordinate.set_wait_for_submit (true);+		y_coordinate.set_int_step (0.1); 		y_coordinate.set_min (-999.99); 		y_coordinate.set_max (999.99); 		y_coordinate.show_icon (true);+		y_coordinate.set_persistent (false); 		y_coordinate.new_value_action.connect((self) => { 			double x, y, w, h; 			Glyph glyph = MainWindow.get_current_glyph ();@@ -271,7 +275,50 @@ public class DrawingTools : ToolCollection  { 				- (MoveTool.selection_box_height / 2) 				+ font.base_line, true, false); 		});-	++		move_tool.objects_deselected.connect (() => {+			y_coordinate.set_value_round (0, true, false);+			y_coordinate.hide_value ();+		});++		// rotation+		SpinButton rotation = new SpinButton ("rotation", t_("Rotation"));+		rotation.set_big_number (true);+		rotation.set_int_value ("0.000");+		rotation.set_int_step (0.1);+		rotation.set_min (-360);+		rotation.set_max (360);+		rotation.show_icon (true);+		rotation.set_persistent (false);+		rotation.new_value_action.connect ((self) => {+			double x, y, w, h;+			Glyph glyph = MainWindow.get_current_glyph ();+			double angle = (self.get_value () / 360) * 2 * PI;+			Path last_path;+			glyph.selection_boundaries (out x, out y, out w, out h);+			+			x += w / 2;+			y -= h / 2;+			+			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.rotation, x, y);		+			}+			+			GlyphCanvas.redraw ();+		});+		+		resize_tool.objects_rotated.connect ((angle) => {+			rotation.set_value_round (angle, true, false);+		});+		+		move_tool.objects_deselected.connect (() => {+			rotation.set_value_round (0, true, false);+			rotation.hide_value ();+		});+		+		draw_tool_modifiers.add_tool (rotation);+			 		// edit stroke width 		object_stroke = new SpinButton ("object_stroke", t_("Stroke width")); 		object_stroke.set_int_value ("2.000");diff --git a/libbirdfont/MoveTool.vala b/libbirdfont/MoveTool.valaindex fbcacb1..4336565 100644--- a/libbirdfont/MoveTool.vala+++ b/libbirdfont/MoveTool.vala@@ -35,6 +35,7 @@ public class MoveTool : Tool { 	 	public signal void selection_changed (); 	public signal void objects_moved ();+	public signal void objects_deselected (); 	 	public MoveTool (string n) { 		base (n, t_("Move paths"), 'm', CTRL);@@ -112,7 +113,7 @@ public class MoveTool : Tool { 		 		update_selection_boundaries (); 		-		if (moved) {+		if (glyph.active_paths.size > 0) { 			objects_moved (); 		} 		@@ -143,6 +144,9 @@ public class MoveTool : Tool { 		 		if (glyph.active_paths.size > 0) { 			objects_moved ();+			DrawingTools.resize_tool.signal_objects_rotated ();+		} else {+			objects_deselected (); 		} 	} 		diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex 7fe3f1e..01c4930 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -88,6 +88,8 @@ public class Path { 	public static bool show_all_line_handles = true; 	public static bool fill_open_path = false; 	+	public double rotation = 0;+	 	public Path () {	 		string width; 		points = new Gee.ArrayList<EditPoint> ();@@ -1790,7 +1792,10 @@ public class Path { 				ep.get_left_handle ().angle += 2 * PI; 			} 		}-+	+		rotation += theta;+		rotation %= 2 * PI;+		 		update_region_boundaries (); 	} 	diff --git a/libbirdfont/ResizeTool.vala b/libbirdfont/ResizeTool.valaindex cf9dadb..0a78c08 100644--- a/libbirdfont/ResizeTool.vala+++ b/libbirdfont/ResizeTool.vala@@ -17,7 +17,7 @@ using Cairo;  namespace BirdFont { -class ResizeTool : Tool {+public class ResizeTool : Tool { 	 	bool resize_path = false; 	Path? resized_path = null;@@ -34,7 +34,9 @@ class ResizeTool : Tool { 	static double last_rotate_y; 	static double rotation = 0; 	static double last_rotate = 0;-		+	+	public signal void objects_rotated (double angle);+	 	public ResizeTool (string n) { 		base (n, t_("Resize and rotate paths")); 		@@ -47,8 +49,10 @@ class ResizeTool : Tool { 		}); 				 		press_action.connect((self, b, x, y) => {-			Glyph glyph = MainWindow.get_current_glyph ();-						+			Path last_path;+			Glyph glyph;+			+			glyph = MainWindow.get_current_glyph (); 			glyph.store_undo_state (); 			 			foreach (Path p in glyph.active_paths) {@@ -74,9 +78,13 @@ class ResizeTool : Tool { 					return; 				} 			}-			-			last_rotate = 0;-			rotation = 0;++			if (glyph.active_paths.size > 0) {+				last_path = glyph.active_paths.get (glyph.active_paths.size - 1);+				last_rotate = last_path.rotation ;+			}+					+			rotation = last_rotate; 			last_rotate_y = y;  @@ -131,11 +139,47 @@ class ResizeTool : Tool { 		 	} -	/** Move rotate handle to pixel x,y. */-	static void rotate (double x, double y) {-		double cx, cy, xc, yc, xc2, yc2, a, b, w, h;		+	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 ();  -		double dx, dy;+		double dx, dy, xc2, yc2, w, h;+		Path last_path;+		foreach (Path p in glyph.active_paths) {+			p.rotate (angle, cx, cy);+		}++		MoveTool.get_selection_box_boundaries (out xc2, out yc2, out w, out h); ++		dx = -(xc2 - cx);+		dy = -(yc2 - cy);+		+		foreach (Path p in glyph.active_paths) {+			p.move (dx, dy);+		}+		+		last_rotate = rotation;+		+		MoveTool.update_selection_boundaries ();+		+		if (glyph.active_paths.size > 0) {+			last_path = glyph.active_paths.get (glyph.active_paths.size - 1);+			rotation = last_path.rotation;+			+			if (rotation > PI) {+				rotation -= 2 * PI;+			}+			+			last_rotate = rotation;+			signal_objects_rotated ();+		}+	}+	+	/** Move rotate handle to pixel x,y. */+	void rotate (double x, double y) {+		double cx, cy, xc, yc, a, b;		 		 		cx = Glyph.reverse_path_coordinate_x (selection_box_center_x); 		cy = Glyph.reverse_path_coordinate_y (selection_box_center_y);@@ -151,22 +195,7 @@ class ResizeTool : Tool { 			rotation += PI; 		} 		-		foreach (Path p in glyph.active_paths) {-			p.rotate (rotation - last_rotate, selection_box_center_x, selection_box_center_y);-		}--		MoveTool.get_selection_box_boundaries (out xc2, out yc2, out w, out h); --		dx = -(xc2 - xc);-		dy = -(yc2 - yc);-		-		foreach (Path p in glyph.active_paths) {-			p.move (dx, dy);-		}-		-		last_rotate = rotation;-		-		MoveTool.update_selection_boundaries ();+		rotate_selected_paths (rotation - last_rotate, selection_box_center_x, selection_box_center_y); 	}  	static bool is_over_rotate_handle (Path p, double x, double y) {diff --git a/libbirdfont/SpinButton.vala b/libbirdfont/SpinButton.valaindex 28fc79f..9da5b50 100644--- a/libbirdfont/SpinButton.vala+++ b/libbirdfont/SpinButton.vala@@ -35,10 +35,6 @@ public class SpinButton : Tool { 	int max = 99999; 	int min = 0; 	int step = 1;--	/** Wait until button is pressed when the user sets value from text. */-	bool wait_for_submit = false;-	string text_input = ""; 	 	bool big_number = false; 	@@ -149,6 +145,12 @@ public class SpinButton : Tool { 		} 	} 	+	public void hide_value () {+		set_icon (base.name);+		waiting_for_icon_switch = false;+		redraw ();+	}+	 	void show_adjustmet_icon () { 		TimeoutSource timer; 		@@ -191,29 +193,14 @@ public class SpinButton : Tool { 		return sb.get_value (); 	} 	-	public void set_wait_for_submit (bool w) {-		wait_for_submit = w;-	}-	 	public void set_from_text () { 		TextListener listener = new TextListener (t_("Set"), get_display_value (), t_("Close")); 		-		if (!wait_for_submit) {-			listener.signal_text_input.connect ((text) => {-				set_value (text);-				redraw ();-			});-		} else {-			listener.signal_text_input.connect ((text) => {-				text_input = text;-			});-			-			listener.signal_submit.connect ((text) => {-				set_value (text_input);-				redraw ();-			});-		}-		+		listener.signal_text_input.connect ((text) => {+			set_value (text);+			redraw ();+		});+ 		listener.signal_submit.connect (() => { 			MainWindow.native_window.hide_text_input (); 			redraw ();@@ -329,6 +316,11 @@ public class SpinButton : Tool { 		} 		 		if (big_number) {+			+			while (v.has_prefix ("0") && !v.has_prefix ("0.")) {+				v = v.substring (v.index_of_nth_char (1));+			}+			 			fv = int.parse (v); 			fv = (fv < 0) ? -fv : fv; 			if (fv < 10) {

Contact

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