Clone in a terminal:
Commit 63c30a9
Johan Mattsson - 2015-06-04T10:46:06+00:00
63c30a989eaf3ace4cf16b9a9d872ef38b638d09johan.mattsson.m@gmail.com

Undo and redo layer operations

Changed files (5)

Diff

diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex 8ba7385..0410e3c 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -107,14 +107,13 @@ public class Glyph : FontDisplay { 	public static double orientation_arrow_opacity = 1; 	 	public Layer layers = new Layer ();-	public Layer current_layer = new Layer ();+	public int current_layer = 0; 	public Gee.ArrayList<Path> active_paths = new Gee.ArrayList<Path> (); 	 	public Glyph (string name, unichar unichar_code = 0) { 		this.name = name; 		this.unichar_code = unichar_code; -		current_layer.add_path (new Path ()); 		add_help_lines (); 		 		left_limit = -28;@@ -124,8 +123,24 @@ public class Glyph : FontDisplay { 	public Glyph.no_lines (string name, unichar unichar_code = 0) { 		this.name = name; 		this.unichar_code = unichar_code;+	}++	public Layer get_current_layer () {+		return_val_if_fail (0 <= current_layer < layers.subgroups.size, new Layer ());+		return layers.subgroups.get (current_layer);+	} -		current_layer.add_path (new Path ());+	public void set_current_layer (Layer layer) {+		int i = 0;+		foreach (Layer l in layers.subgroups) {+			if (likely (l == layer)) {+				current_layer = i;+				return;+			}+			i++;+		}+		+		warning ("Layer is not added to glyph."); 	}  	public PathList get_visible_path_list () {@@ -136,8 +151,8 @@ public class Glyph : FontDisplay { 		return layers.get_visible_paths ().paths; 	} -	public Gee.ArrayList<Path> get_current_layer () {-		return current_layer.paths.paths;+	public Gee.ArrayList<Path> get_paths_in_current_layer () {+		return get_current_layer ().paths.paths; 	} 	 	public Gee.ArrayList<Path> get_all_paths () {@@ -381,10 +396,10 @@ public class Glyph : FontDisplay { 	 	public void add_path (Path p) { 		if (layers.subgroups.size == 0) {-			layers.add_layer (current_layer);+			layers.add_layer (new Layer ()); 		} 		-		current_layer.add_path (p);+		get_current_layer ().add_path (p); 	} 	 	public override void selected_canvas () {@@ -1076,7 +1091,7 @@ public class Glyph : FontDisplay { 		Path? p = null; 		bool found = false; 		-		foreach (Path pt in get_current_layer ()) {+		foreach (Path pt in get_paths_in_current_layer ()) { 			if (pt.is_over (x, y)) { 				p = pt; 				found = true;@@ -1791,6 +1806,8 @@ public class Glyph : FontDisplay { 	public Glyph copy () { 		Glyph g = new Glyph.no_lines (name, unichar_code); 		+		g.current_layer = current_layer;+		 		g.left_limit = left_limit; 		g.right_limit = right_limit; 		@@ -1841,7 +1858,8 @@ public class Glyph : FontDisplay { 		set_glyph_data (g); 		 		undo_list.remove_at (undo_list.size - 1);-+		+		DrawingTools.update_layers (); 		PenTool.update_selected_points (); 		 		clear_active_paths ();@@ -1863,20 +1881,15 @@ public class Glyph : FontDisplay { 		 		redo_list.remove_at (redo_list.size - 1); +		DrawingTools.update_layers (); 		PenTool.update_selected_points (); 		 		clear_active_paths (); 	} 	 	void set_glyph_data (Glyph g) {-		// FIXME: get a pointer to current layer not a copy-		// current_layer +		current_layer = g.current_layer; 		layers = g.layers.copy ();-		-		foreach (Path p in get_all_paths ()) {-			add_path (p);-			p.update_region_boundaries ();-		}  		remove_lines (); 		foreach (Line line in g.get_all_help_lines ()) {diff --git a/libbirdfont/LayerLabel.vala b/libbirdfont/LayerLabel.valaindex 4c158c0..dd67ab5 100644--- a/libbirdfont/LayerLabel.vala+++ b/libbirdfont/LayerLabel.vala@@ -59,7 +59,7 @@ public class LayerLabel : Tool { 	} 	 	public void select_layer () {-		MainWindow.get_current_glyph ().current_layer = layer;+		MainWindow.get_current_glyph ().set_current_layer (layer); 		DrawingTools.deselect_layers (); 		selected_layer = true; 		MainWindow.get_current_glyph ().clear_active_paths ();diff --git a/libbirdfont/MoveTool.vala b/libbirdfont/MoveTool.valaindex 30b7487..3b61cb7 100644--- a/libbirdfont/MoveTool.vala+++ b/libbirdfont/MoveTool.vala@@ -202,7 +202,7 @@ public class MoveTool : Tool { 		 		glyph.clear_active_paths (); 		-		foreach (Path p in glyph.get_current_layer ()) {+		foreach (Path p in glyph.get_paths_in_current_layer ()) { 			if (p.xmin > x1 && p.xmax < x2 && p.ymin < y1 && p.ymax > y2) { 				if (p.points.size > 0) { 					glyph.add_active_path (p);@@ -442,7 +442,7 @@ public class MoveTool : Tool { 		 		g.clear_active_paths (); 		-		foreach (Path p in g.get_current_layer ()) {+		foreach (Path p in g.get_paths_in_current_layer ()) { 			if (p.points.size > 0) { 				g.add_active_path (p); 			}diff --git a/libbirdfont/OverView.vala b/libbirdfont/OverView.valaindex fc2c895..ce5a207 100644--- a/libbirdfont/OverView.vala+++ b/libbirdfont/OverView.vala@@ -123,6 +123,7 @@ public class OverView : FontDisplay { 			glyph_collection = add_character_to_font (character); 			 			glyph = glyph_collection.get_current ();+			glyph.layers.add_layer (new Layer ()); 			tabs.add_tab (glyph, true, glyph_collection); 			 			selected_items.add (glyph_collection);diff --git a/libbirdfont/PathList.vala b/libbirdfont/PathList.valaindex 7b7198d..63283c6 100644--- a/libbirdfont/PathList.vala+++ b/libbirdfont/PathList.vala@@ -68,7 +68,7 @@ public class PathList : GLib.Object { 		PathList pl = new PathList (); 		 		foreach (Path p in paths) {-			pl.add (p);+			pl.add (p.copy ()); 		} 		 		return pl;

Contact

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