Commit f251491
Speed optimizations in toolbox
Changed files (16)
modifiedlibbirdfont/BackgroundTools.valamodifiedlibbirdfont/DrawingTools.valamodifiedlibbirdfont/Expander.valamodifiedlibbirdfont/FileTools.valamodifiedlibbirdfont/KerningRange.valamodifiedlibbirdfont/KerningTools.valamodifiedlibbirdfont/LabelTool.valamodifiedlibbirdfont/OverView.valamodifiedlibbirdfont/OverviewTools.valamodifiedlibbirdfont/Renderer/CachedFont.valamodifiedlibbirdfont/Renderer/FallbackFont.valamodifiedlibbirdfont/Renderer/Text.valamodifiedlibbirdfont/SpinButton.valamodifiedlibbirdfont/Tool.valamodifiedlibbirdfont/Toolbox.valamodifiedscripts/windows_build.py
Diff
@@ -54,7 +54,6 @@ public class BackgroundTools : ToolCollection { expanders.add (font_name); expanders.add (background_tools); expanders.add (DrawingTools.zoombar_tool);- expanders.add (DrawingTools.view_tools); expanders.add (DrawingTools.guideline_tools); expanders.add (background_selection); expanders.add (files);@@ -28,7 +28,6 @@ public class DrawingTools : ToolCollection { public static Expander draw_tool_modifiers; public static Expander stroke_expander; public static Expander zoombar_tool;- public static Expander view_tools; public static Expander guideline_tools; public static PointType point_type = PointType.DOUBLE_CURVE;@@ -111,7 +110,6 @@ public class DrawingTools : ToolCollection { stroke_expander = new Expander (t_("Stroke")); shape_tools = new Expander (t_("Geometrical Shapes")); zoombar_tool = new Expander (t_("Zoom"));- view_tools = new Expander (); guideline_tools = new Expander (t_("Guidelines & Grid")); Expander font_name = new Expander ();@@ -1053,7 +1051,7 @@ public class DrawingTools : ToolCollection { glyph_canvas.get_current_display ().reset_zoom (); glyph_canvas.redraw_area(0, 0, GlyphCanvas.allocation.width, GlyphCanvas.allocation.height); });- view_tools.add_tool (reset_zoom);+ zoombar_tool.add_tool (reset_zoom); reset_zoom.set_tool_visibility (false); Tool full_glyph = new Tool ("full_glyph", t_("Show full glyph"));@@ -1061,14 +1059,14 @@ public class DrawingTools : ToolCollection { zoom_tool.store_current_view (); zoom_tool.zoom_full_glyph (); });- view_tools.add_tool (full_glyph);+ zoombar_tool.add_tool (full_glyph); Tool zoom_boundaries = new Tool ("zoom_boundaries", t_("Fit in view")); zoom_boundaries.select_action.connect((self) => { zoom_tool.store_current_view (); glyph_canvas.get_current_display ().zoom_max (); });- view_tools.add_tool (zoom_boundaries);+ zoombar_tool.add_tool (zoom_boundaries); Tool zoom_bg = new Tool ("zoom_background_image", t_("Zoom in on background image")); zoom_bg.select_action.connect((self) => {@@ -1078,19 +1076,19 @@ public class DrawingTools : ToolCollection { glyph_canvas.redraw_area(0, 0, GlyphCanvas.allocation.width, GlyphCanvas.allocation.height); } });- view_tools.add_tool (zoom_bg);+ zoombar_tool.add_tool (zoom_bg); Tool zoom_prev = new Tool ("prev", t_("Previous view")); zoom_prev.select_action.connect((self) => { zoom_tool.previous_view (); });- view_tools.add_tool (zoom_prev);+ zoombar_tool.add_tool (zoom_prev); Tool zoom_next = new Tool ("next", t_("Next view")); zoom_next.select_action.connect((self) => { zoom_tool.next_view (); });- view_tools.add_tool (zoom_next);+ zoombar_tool.add_tool (zoom_next); // view_tools zoom_next.set_tool_visibility (false); // shape tools @@ -1120,7 +1118,6 @@ public class DrawingTools : ToolCollection { add_expander (guideline_tools); add_expander (grid); add_expander (zoombar_tool);- add_expander (view_tools); add_expander (shape_tools); // Fixa: add_expander (trace);@@ -1386,9 +1383,9 @@ public class DrawingTools : ToolCollection { || auto_trace.is_selected ()) { show_background_tool_modifiers (); }- - MainWindow.get_toolbox ().update_expanders ();- Toolbox.redraw_tool_box ();++ MainWindow.get_toolbox ().update_expanders (); + draw_tool_modifiers.redraw (); return false; });@@ -93,7 +93,7 @@ public class Expander : GLib.Object { double scale = Toolbox.get_scale (); double margin_small = 5 * scale; double xt = x;- double yt = y + scroll + margin_small;+ double yt = y + margin_small; // + scroll bool new_row = false; bool has_visible_tools = false; Tool previous;@@ -101,7 +101,7 @@ public class Expander : GLib.Object { foreach (Tool t in tool) { if (t.tool_is_visible ()) {- has_visible_tools = true;+ has_visible_tools = true; break; } }@@ -114,7 +114,7 @@ public class Expander : GLib.Object { foreach (Tool t in tool) { if (t is ZoomBar) { t.w = Toolbox.allocation_width * scale;- t.h = 7 * scale;+ t.h = 10 * scale; // 7 } else if (t is LabelTool) { t.w = Toolbox.allocation_width * scale; t.h = 22 * scale;@@ -148,13 +148,26 @@ public class Expander : GLib.Object { if (t.tool_is_visible ()) { new_row = xt + t.w > Toolbox.allocation_width - 7 * scale; + if (t is ZoomBar) {+ t.x = xt;+ t.y = yt;+ //content_height += t.h;+ yt += t.h + 7 * scale;+ previous = t;+ continue;+ }+ + if (previous is ZoomBar) {+ content_height += t.h;+ }+ if (new_row && !first_row) { content_height += previous.h + margin_small; xt = x; yt += previous.h; if (t is LabelTool) {- yt += 0 * scale;+ // yt += 0 * scale; } else { yt += 7 * scale; }@@ -164,7 +177,11 @@ public class Expander : GLib.Object { t.y = yt; xt += t.w + 7 * scale;- ++ if (previous is ZoomBar) {+ content_height += 7 * scale;+ }+ previous = t; first_row = false; }@@ -181,6 +198,11 @@ public class Expander : GLib.Object { update_tool_position (); } + public void redraw () {+ cached = null;+ Toolbox.redraw_tool_box ();+ }+ public void add_tool (Tool t, int position = -1) { if (position < 0) { tool.add (t);@@ -196,36 +218,36 @@ public class Expander : GLib.Object { update_tool_position (); t.select_action.connect ((selected) => {- MainWindow.get_toolbox ().redraw ((int) x, (int) y, (int) w + 300, (int) (h + margin));- - if (is_unique ()) {- foreach (var deselected in tool) {- if (selected.get_id () != deselected.get_id ()) {- deselected.set_selected (false);- }+ MainWindow.get_toolbox ().redraw ((int) x, (int) y, (int) w + 300, (int) (h + margin));+ + if (is_unique ()) {+ foreach (var deselected in tool) {+ if (selected.get_id () != deselected.get_id ()) {+ deselected.set_selected (false); } }+ } - if (!selected.new_selection && selected.persistent) {- if (is_persistent ()) {- selected.set_selected (true);- } else {- selected.set_selected (false);- }- }- - if (!is_persistent () && !selected.persistent) {- var time = new TimeoutSource(200);- time.set_callback(() => {- selected.set_selected (false);- MainWindow.get_toolbox ().redraw ((int) x, (int) y, (int) w + 300, (int) (h + margin));- return false;- });- time.attach(null);+ if (!selected.new_selection && selected.persistent) {+ if (is_persistent ()) {+ selected.set_selected (true);+ } else {+ selected.set_selected (false); }+ }+ + if (!is_persistent () && !selected.persistent) {+ var time = new TimeoutSource(200);+ time.set_callback(() => {+ selected.set_selected (false);+ MainWindow.get_toolbox ().redraw ((int) x, (int) y, (int) w + 300, (int) (h + margin));+ return false;+ });+ time.attach(null);+ } - selected.new_selection = false;- });+ selected.new_selection = false;+ }); } public bool is_over (double xp, double yp) {@@ -255,7 +277,7 @@ public class Expander : GLib.Object { if (tool.size > 0 && headline != null) { Theme.text_color (title, "Text Tool Box"); title.set_font_size (text_height);- title.draw_at_top (cc, 0, 0);+ title.draw_at_top (cc, x, 0); offset_y = text_height + HEADLINE_MARGIN; } @@ -267,7 +289,7 @@ public class Expander : GLib.Object { cache = (!) cached; cr.save (); cr.set_antialias (Cairo.Antialias.NONE);- cr.set_source_surface (cache, (int) x, (int) (y + scroll));+ cr.set_source_surface (cache, 0, (int) (y + scroll)); cr.paint (); cr.restore (); }@@ -277,6 +299,8 @@ public class Expander : GLib.Object { double offset_y = 0; double offset_x = 0; + update_tool_position (); //FIXME+ if (tool.size > 0) { offset_x = tool.get (0).x; offset_y = tool.get (0).y - text_end;@@ -285,7 +309,7 @@ public class Expander : GLib.Object { cr.save (); foreach (Tool t in tool) { if (t.tool_is_visible ()) {- t.draw_tool (cr, offset_x, offset_y);+ t.draw_tool (cr, offset_x - x, offset_y); } } cr.restore ();@@ -64,18 +64,20 @@ public class FileTools : ToolCollection { theme_label.data = theme; theme_label.select_action.connect((self) => {- TabBar tb; LabelTool s = (LabelTool) self; string theme_file = s.data;- + TabBar tb = MainWindow.get_tab_bar (); Preferences.set ("theme", theme_file); Theme.load_theme (theme_file); Toolbox.redraw_tool_box (); GlyphCanvas.redraw (); - tb = MainWindow.get_tab_bar ();+ file_tools.redraw ();+ font_name.redraw (); tb.redraw (0, 0, tb.width, tb.height);+ + OverviewTools.zoom_expander.redraw (); }); if (!theme.has_prefix ("generated_")) {@@ -132,10 +132,13 @@ public class KerningRange : Tool { TabContent.show_text_input (listener); } - public override void draw (Context cr) {+ public override void draw_tool (Context cr, double px, double py) { double xt, yt; Text label_text; + double x = this.x - px;+ double y = this.y - py;+ xt = x + 5; yt = y + 10; @@ -60,7 +60,7 @@ public class KerningTools : ToolCollection { string label = t_("Kerning class"); KerningRange kr = new KerningRange (font, @"$label $(++next_class)"); classes.add_tool (kr);- Toolbox.redraw_tool_box ();+ classes.redraw (); }); kerning_tools.add_tool (new_kerning_class); @@ -27,13 +27,22 @@ public class LabelTool : Tool { double counter_box_width = 24 * Toolbox.get_scale (); double counter_box_height = 11 * Toolbox.get_scale ();+ + Text label_text; public LabelTool (string label) {+ double text_height;+ base (); this.label = label; this.number = "-"; + label_text = new Text ();+ label_text.set_text (label);+ text_height = 17 * Toolbox.get_scale ();+ label_text.set_font_size (text_height);+ has_delete_button = false; has_counter = false; @@ -48,11 +57,13 @@ public class LabelTool : Tool { }); } - public override void draw (Context cr) {- Text label_text, glyph_count;- double text_height;+ public override void draw_tool (Context cr, double px, double py) {+ Text glyph_count; double bgx, bgy; double center_x, center_y;+ double x = this.x - px;+ double y = this.y - py;+ double text_height; // background if (is_selected ()) {@@ -65,9 +76,6 @@ public class LabelTool : Tool { // tab label cr.save ();- label_text = new Text ();- label_text.set_text (label);- text_height = 17 * Toolbox.get_scale (); if (is_selected ()) { Theme.text_color (label_text, "Text Tool Box");@@ -75,7 +83,6 @@ public class LabelTool : Tool { Theme.text_color (label_text, "Text Tool Box"); } - label_text.set_font_size (text_height); label_text.draw_at_top (cr, x, y); cr.restore (); @@ -1304,7 +1304,6 @@ public class OverView : FontDisplay { character.set_text ((!) c.to_string ()); character.set_font_size (height); character.draw_at_top (cr, x + 10, y);- printd ("Fallback font: " + character.get_font_file_name ()); cr.restore (); } @@ -26,6 +26,8 @@ public class OverviewTools : ToolCollection { public static Gee.ArrayList<Expander> expanders; public ZoomBar zoom_bar;+ + public static Expander zoom_expander; public OverviewTools () { Expander font_name = new Expander ();@@ -72,15 +72,6 @@ public class CachedFont : GLib.Object { return g; }- - public string get_font_file_name () {- if (font == null) {- warning ("No font loaded.");- return "";- }- - return (((!) font).font_file != null) ? (!) ((!) font).font_file : "".dup ();- } } }@@ -44,7 +44,7 @@ public class FallbackFont : GLib.Object { Gee.ArrayList<CachePair> cached; public int max_cached_fonts = 300;-+ public FallbackFont () { string home = Environment.get_home_dir (); @@ -120,7 +120,7 @@ public class FallbackFont : GLib.Object { return (Font) f; }- + Font get_single_fallback_glyph_font (unichar c) { string? font_file; BirdFontFile bf_parser;@@ -151,6 +151,9 @@ public class FallbackFont : GLib.Object { if (glyph_data == null) { font_file = find_font (font_config, (!) c.to_string ()); if (font_file != null) {+ printd ((!) font_file); // FIXME: DELETE+ printd ("\n");+ font = open_font ((!) font_file); glyph_data = get_glyph_in_font (font, c); close_font (font);@@ -57,10 +57,6 @@ public class Text : Widget { set_font_size (size); } - public string get_font_file_name () {- return cached_font.get_font_file_name ();- }- public void use_cache (bool cache) { use_cached_glyphs = cache; }@@ -444,13 +444,15 @@ public class SpinButton : Tool { return v; } - public override void draw (Context cr) {+ public override void draw_tool (Context cr, double px, double py) { double scale = Toolbox.get_scale (); double text_height = 14 * scale; string display_value = get_short_display_value (); Text text = new Text (display_value, text_height);+ double x = x - px;+ double y = y - py; - double text_x = x + (w - text.get_sidebearing_extent ()) / 2;+ double text_x = x + (w - text.get_sidebearing_extent ()) / 2 + 1; double text_y = y + (h - text_height) / 2; if (!show_icon_tool_icon || waiting_for_icon_switch) {@@ -467,8 +469,7 @@ public class SpinButton : Tool { } } - base.draw (cr);- + base.draw_tool (cr, px, py); if (!show_icon_tool_icon || waiting_for_icon_switch) { if (is_selected ()) {@@ -130,6 +130,10 @@ public class Tool : Widget { return false; }); }+ + public override void draw (Context cr) {+ draw_tool (cr, 0, 0);+ } public void redraw () { redraw_tool ();@@ -269,10 +273,6 @@ public class Tool : Widget { return ret; } - public override void draw (Context cr) {- draw_tool (cr,0, 0);- }- public virtual void draw_tool (Context cr, double px, double py) { double xt = x - px; double yt = y - py;@@ -133,6 +133,8 @@ public class Toolbox : GLib.Object { return; } + y -= current_set.scroll;+ foreach (Expander exp in current_set.get_expanders ()) { if (exp.visible) { foreach (Tool t in exp.tool) {@@ -151,6 +153,8 @@ public class Toolbox : GLib.Object { public void release (uint button, double x, double y) { bool active; + y -= current_set.scroll;+ if (MenuTab.suppress_event) { warn_if_test ("Event suppressed"); return;@@ -180,6 +184,8 @@ public class Toolbox : GLib.Object { public void scroll_up (double x, double y) { bool action = false; + y -= current_set.scroll;+ if (MenuTab.suppress_event) { warn_if_test ("Event suppressed"); return;@@ -225,6 +231,8 @@ public class Toolbox : GLib.Object { public void scroll_down (double x, double y) { bool action = false; + y -= current_set.scroll;+ if (!scrolling_toolbox) { foreach (Expander exp in current_set.get_expanders ()) { if (exp.visible) {@@ -260,6 +268,8 @@ public class Toolbox : GLib.Object { bool consumed = false; bool active; + y -= current_set.scroll;+ MainWindow.set_cursor (NativeWindow.VISIBLE); foreach (Expander exp in current_set.get_expanders ()) {@@ -453,14 +463,6 @@ public class Toolbox : GLib.Object { } public void draw (int w, int h, Context cr) { - Test t = new Test.time ("Toolbox drawing");- for (int i = 0; i < 1; i++) { // 30- draw_single (w, h, cr);- }- t.print ();- }- - public void draw_single (int w, int h, Context cr) { cr.save (); Theme.color (cr, "Default Background");@@ -16,7 +16,7 @@ prefix = "" valac = "valac" valaflags = "" cc = "gcc"-cflags = "-g -Wl,-subsystem,windows "+cflags = "-Wl,-subsystem,windows " ldflags = "" library_ldflags= "";