Commit 4e2f9ac
Drag and drop layers
Changed files (5)
modifiedlibbirdfont/Expander.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/LabelTool.valamodifiedlibbirdfont/LayerLabel.valamodifiedlibbirdfont/Menu.vala
Diff
@@ -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;@@ -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 (); } } @@ -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) {@@ -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 () {@@ -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);