Clone in a terminal:
Commit 4e2f9ac
Johan Mattsson - 2015-06-05T03:53:26+00:00
4e2f9ac5f7fcc1ce30f994578db6895c379a1f03johan.mattsson.m@gmail.com

Drag and drop layers

Changed files (5)

Diff

diff --git a/libbirdfont/Expander.vala b/libbirdfont/Expander.valaindex 818ea86..b6372a3 100644--- a/libbirdfont/Expander.vala+++ b/libbirdfont/Expander.vala@@ -126,7 +126,7 @@ public class Expander : GLib.Object { 				t.h = 17 * scale; 			} else if (t is LayerLabel) { 				t.w = Toolbox.allocation_width * scale;-				t.h = 21 * scale;	+				t.h = 21 * scale; 			} else { 				t.w = 33 * scale; 				t.h = (33 / 1.11) * scale;@@ -164,13 +164,17 @@ public class Expander : GLib.Object { 					} 					 					if (new_row && !first_row) {-						content_height += previous.h + margin_small; +						content_height += previous.h;  						xt = x; 						yt += previous.h; 						 						if (!(t is LabelTool) && !(previous is LayerLabel)) { 							yt += 7 * scale; 						}+						+						if (!(previous is LayerLabel)) {+							content_height += margin_small;+						} 					} 				 					t.x = xt;diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex fbe1db4..c2ef0b9 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -2303,8 +2303,6 @@ public class Glyph : FontDisplay { 			 			set_current_layer (layer); 		} -		-		DrawingTools.update_layers (); 	} 		 	public void move_layer_down () {@@ -2319,8 +2317,6 @@ public class Glyph : FontDisplay { 			 			set_current_layer (layer); 		} -		-		DrawingTools.update_layers (); 	} } diff --git a/libbirdfont/LabelTool.vala b/libbirdfont/LabelTool.valaindex 284bd21..1080892 100644--- a/libbirdfont/LabelTool.vala+++ b/libbirdfont/LabelTool.vala@@ -51,10 +51,6 @@ public class LabelTool : Tool { 				delete_action (this); 			} 		});--		panel_move_action.connect ((selected, button, tx, ty) => {-			return false;-		}); 	} 	 	public override void draw_tool (Context cr, double px, double py) {diff --git a/libbirdfont/LayerLabel.vala b/libbirdfont/LayerLabel.valaindex d793c15..0aced6f 100644--- a/libbirdfont/LayerLabel.vala+++ b/libbirdfont/LayerLabel.vala@@ -24,6 +24,9 @@ public class LayerLabel : Tool { 	public Layer layer; 	Text label_text; +	/** Add margin when layer is moves. */+	bool active_layer = false;+	 	public LayerLabel (Layer layer) { 		base (); @@ -45,6 +48,7 @@ public class LayerLabel : Tool { 					BirdFont.get_current_font ().touch (); 					MainWindow.get_current_glyph ().clear_active_paths (); 				} else {+					active_layer = true; 					select_layer (); 				} 			} else {@@ -59,6 +63,70 @@ public class LayerLabel : Tool { 				} 			} 		});++		panel_move_action.connect ((selected, button, tx, ty) => {+			if (active_layer) {+				if (ty > y) {+					move_layer_down ();+				} else if (ty < y - h) {+					move_layer_up ();+				}+				+				MainWindow.get_toolbox ().update_expanders ();+				redraw ();+			}+			+			return false;+		});++		panel_release_action.connect ((selected, button, tx, ty) => {+			active_layer = false;+		});+	}+	+	void move_layer_up () {+		int i;+		Glyph g = MainWindow.get_current_glyph ();++		// g.layers is ordered from bottom to top+		i = DrawingTools.layer_tools.tool.size - g.current_layer - 1;+		g.move_layer_up ();+		+		DrawingTools.update_layers ();+		+		if (i < 0) {+			i = 0;+		}+		+		set_moving_label (i);+	}++	void move_layer_down () {+		int i;+		Glyph g = MainWindow.get_current_glyph ();++		i = DrawingTools.layer_tools.tool.size - g.current_layer + 1;+		g.move_layer_down ();+		+		DrawingTools.update_layers ();+		+		if (i >= DrawingTools.layer_tools.tool.size) {+			i = DrawingTools.layer_tools.tool.size - 1;+		}+		+		set_moving_label (i);+	}+		+	void set_moving_label (int i) {+		LayerLabel label;+		int j = 0;+		foreach (Tool layer in DrawingTools.layer_tools.tool) {+			label = (LayerLabel) layer;+			if (i == j) {+				label.active_layer = true;+			}+			j++;+		}		 	} 	 	void set_text () {diff --git a/libbirdfont/Menu.vala b/libbirdfont/Menu.valaindex 977656f..4d536df 100644--- a/libbirdfont/Menu.vala+++ b/libbirdfont/Menu.vala@@ -269,12 +269,14 @@ public class Menu : GLib.Object { 		MenuItem layer_up = add_menu_item (t_("Move Layer Up"), "move layer up", "Glyph"); 		layer_up.action.connect (() => { 			MainWindow.get_current_glyph ().move_layer_up ();+			DrawingTools.update_layers (); 		}); 		layers_menu.items.add (layer_up);  		MenuItem layer_down = add_menu_item (t_("Move Layer Down"), "move layer down", "Glyph"); 		layer_down.action.connect (() => { 			MainWindow.get_current_glyph ().move_layer_down ();+			DrawingTools.update_layers (); 		}); 		layers_menu.items.add (layer_down); 		

Contact

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