Commit b5da797
Store active layer in font settings and cache tools
Changed files (8)
modifiedlibbirdfont/DrawingTools.valamodifiedlibbirdfont/Expander.valamodifiedlibbirdfont/FontSettings.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/Layer.valamodifiedlibbirdfont/LayerLabel.valamodifiedlibbirdfont/ToolCollection.valamodifiedlibbirdfont/Toolbox.vala
Diff
@@ -768,7 +768,7 @@ public class DrawingTools : ToolCollection { add_layer.select_action.connect ((self) => { layer_tools.visible = true; MainWindow.get_current_glyph ().add_new_layer ();- update_layers ();+ update_layers (); // FIXME: speed optimization show_layers.selected = true; add_layer.selected = false; });@@ -1619,6 +1619,7 @@ public class DrawingTools : ToolCollection { } MainWindow.get_toolbox ().update_expanders ();+ layer_tools.clear_cache (); layer_tools.redraw (); Toolbox.redraw_tool_box (); }@@ -269,6 +269,14 @@ public class Expander : GLib.Object { return r; } + public void cache () {+ if (cached == null) {+ Surface workbench = Screen.create_background_surface (1, 1);+ Context context = new Context (workbench);+ draw (context);+ }+ }+ public void draw (Context cr) { Surface cache; @@ -65,7 +65,7 @@ public class FontSettings : GLib.Object { foreach (var k in settings.keys) { sb.append ("\t<setting key=\"");- sb.append (k);+ sb.append (XmlParser.encode (k)); sb.append ("\" "); sb.append ("value=\""); sb.append (XmlParser.encode (settings.get (k)));@@ -114,7 +114,7 @@ public class FontSettings : GLib.Object { string v = ""; foreach (Attribute a in tag.get_attributes ()) { if (a.get_name () == "key") {- key = a.get_content ();+ key = XmlParser.decode (a.get_content ()); } if (a.get_name () == "value") {@@ -197,6 +197,10 @@ public class Glyph : FontDisplay { current_layer = layers.subgroups.size - 1; } + public int get_layer_index (Layer layer) {+ return layers.index_of (layer);+ }+ public GlyfData get_ttf_data () { if (ttf_data == null) { @@ -471,6 +475,18 @@ public class Glyph : FontDisplay { } update_zoom_bar ();+ + Font font = BirdFont.get_current_font ();+ string index = font.settings.get_setting (@"Active Layer $(get_name ())");+ + if (index != "") {+ int i = int.parse (index);+ + if (0 <= i < layers.subgroups.size) {+ current_layer = i;+ }+ }+ DrawingTools.update_layers (); MainWindow.get_toolbox ().update_expanders (); }@@ -29,6 +29,10 @@ public class Layer : GLib.Object { subgroups = new Gee.ArrayList<Layer> (); } + public int index_of (Layer sublayer) {+ return subgroups.index_of (sublayer);+ }+ public PathList get_all_paths () { PathList p = new PathList (); @@ -158,11 +158,16 @@ public class LayerLabel : Tool { } public void select_layer () {- MainWindow.get_current_glyph ().set_current_layer (layer);+ Glyph glyph = MainWindow.get_current_glyph ();+ glyph.set_current_layer (layer); DrawingTools.deselect_layers (); selected_layer = true; MainWindow.get_current_glyph ().clear_active_paths (); GlyphCanvas.redraw ();+ + Font font = BirdFont.get_current_font ();+ int index = glyph.get_layer_index (layer);+ font.settings.set_setting (@"Active Layer $(glyph.get_name ())", @"$(index)"); } public void remove_layer () {@@ -1,5 +1,5 @@ /*- Copyright (C) 2013 Johan Mattsson+ Copyright (C) 2013 2015 Johan Mattsson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -36,6 +36,12 @@ public abstract class ToolCollection : GLib.Object { return current_tool; } + public void cache () {+ foreach (Expander e in get_expanders ()) {+ e.cache ();+ }+ }+ public void redraw () { foreach (Expander e in get_expanders ()) { e.redraw ();@@ -103,6 +103,14 @@ public class Toolbox : GLib.Object { tc.redraw (); } }+ + public static void cache_all_tools () {+ Toolbox t = MainWindow.get_toolbox ();+ + foreach (ToolCollection tc in t.tool_sets) {+ tc.cache ();+ }+ } public static void set_toolbox_from_tab (string tab_name, Tab? t = null) { if (tab_name == "Spacing") {