The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Speed optimizations in toolbox

These changes was commited to the Birdfont repository Fri, 29 May 2015 22:00:03 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Fri, 29 May 2015 22:00:03 +0000 (00:00 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Fri, 29 May 2015 22:00:03 +0000 (00:00 +0200)
commit f2514911524bc28fa644db00d0e7af4d90e40b9e
tree 89167cb49be368fa068abaf7f475553e86e70623
parent 5b021d30a564faf1abd5854f8748afd011600c70
Speed optimizations in toolbox

17 files changed:
libbirdfont/BackgroundTools.vala
libbirdfont/DrawingTools.vala
libbirdfont/Expander.vala
libbirdfont/FileTools.vala
libbirdfont/KerningRange.vala
libbirdfont/KerningTools.vala
libbirdfont/LabelTool.vala
libbirdfont/OverView.vala
libbirdfont/OverviewTools.vala
libbirdfont/Renderer/CachedFont.vala
libbirdfont/Renderer/FallbackFont.vala
libbirdfont/Renderer/Text.vala
libbirdfont/SpinButton.vala
libbirdfont/Tool.vala
libbirdfont/Toolbox.vala
scripts/windows_build.py
--- a/libbirdfont/BackgroundTools.vala +++ b/libbirdfont/BackgroundTools.vala @@ -54,7 +54,6 @@ 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);
--- a/libbirdfont/DrawingTools.vala +++ b/libbirdfont/DrawingTools.vala @@ -28,7 +28,6 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ || 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; });
--- a/libbirdfont/Expander.vala +++ b/libbirdfont/Expander.vala @@ -93,7 +93,7 @@ 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 @@ foreach (Tool t in tool) { if (t.tool_is_visible ()) { - has_visible_tools = true; + has_visible_tools = true; break; } } @@ -114,7 +114,7 @@ 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; @@ -147,6 +147,19 @@ foreach (Tool t in tool) { 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; @@ -154,7 +167,7 @@ yt += previous.h; if (t is LabelTool) { - yt += 0 * scale; + // yt += 0 * scale; } else { yt += 7 * scale; } @@ -164,7 +177,11 @@ t.y = yt; xt += t.w + 7 * scale; - + + if (previous is ZoomBar) { + content_height += 7 * scale; + } + previous = t; first_row = false; } @@ -179,6 +196,11 @@ public void set_offset (double ty) { y = ty; update_tool_position (); + } + + public void redraw () { + cached = null; + Toolbox.redraw_tool_box (); } public void add_tool (Tool t, int position = -1) { @@ -196,36 +218,36 @@ 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 @@ 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 @@ 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 (); } @@ -276,6 +298,8 @@ public void draw_content (Context cr, double text_end) { double offset_y = 0; double offset_x = 0; + + update_tool_position (); //FIXME if (tool.size > 0) { offset_x = tool.get (0).x; @@ -285,7 +309,7 @@ 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 ();
--- a/libbirdfont/FileTools.vala +++ b/libbirdfont/FileTools.vala @@ -64,18 +64,20 @@ 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_")) {
--- a/libbirdfont/KerningRange.vala +++ b/libbirdfont/KerningRange.vala @@ -132,10 +132,13 @@ 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;
--- a/libbirdfont/KerningTools.vala +++ b/libbirdfont/KerningTools.vala @@ -60,7 +60,7 @@ 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);
--- a/libbirdfont/LabelTool.vala +++ b/libbirdfont/LabelTool.vala @@ -27,13 +27,22 @@ 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 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 @@ // 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 @@ 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 ();
--- a/libbirdfont/OverView.vala +++ b/libbirdfont/OverView.vala @@ -1304,7 +1304,6 @@ 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 (); }
--- a/libbirdfont/OverviewTools.vala +++ b/libbirdfont/OverviewTools.vala @@ -26,6 +26,8 @@ public static Gee.ArrayList<Expander> expanders; public ZoomBar zoom_bar; + + public static Expander zoom_expander; public OverviewTools () { Expander font_name = new Expander ();
--- a/libbirdfont/Renderer/CachedFont.vala +++ b/libbirdfont/Renderer/CachedFont.vala @@ -71,17 +71,8 @@ } 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 (); } } }
--- a/libbirdfont/Renderer/FallbackFont.vala +++ b/libbirdfont/Renderer/FallbackFont.vala @@ -44,7 +44,7 @@ Gee.ArrayList<CachePair> cached; public int max_cached_fonts = 300; - + public FallbackFont () { string home = Environment.get_home_dir (); @@ -120,7 +120,7 @@ return (Font) f; } - + Font get_single_fallback_glyph_font (unichar c) { string? font_file; BirdFontFile bf_parser; @@ -151,6 +151,9 @@ 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);
--- a/libbirdfont/Renderer/Text.vala +++ b/libbirdfont/Renderer/Text.vala @@ -55,10 +55,6 @@ set_text (text); set_font_size (size); - } - - public string get_font_file_name () { - return cached_font.get_font_file_name (); } public void use_cache (bool cache) {
--- a/libbirdfont/SpinButton.vala +++ b/libbirdfont/SpinButton.vala @@ -444,13 +444,15 @@ 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 @@ } } - base.draw (cr); - + base.draw_tool (cr, px, py); if (!show_icon_tool_icon || waiting_for_icon_switch) { if (is_selected ()) {
--- a/libbirdfont/Tool.vala +++ b/libbirdfont/Tool.vala @@ -129,6 +129,10 @@ } return false; }); + } + + public override void draw (Context cr) { + draw_tool (cr, 0, 0); } public void redraw () { @@ -267,10 +271,6 @@ bool ret = (active != ac); active = ac; return ret; - } - - public override void draw (Context cr) { - draw_tool (cr,0, 0); } public virtual void draw_tool (Context cr, double px, double py) {
--- a/libbirdfont/Toolbox.vala +++ b/libbirdfont/Toolbox.vala @@ -132,6 +132,8 @@ warn_if_test ("Event suppressed"); return; } + + y -= current_set.scroll; foreach (Expander exp in current_set.get_expanders ()) { if (exp.visible) { @@ -150,6 +152,8 @@ public void release (uint button, double x, double y) { bool active; + + y -= current_set.scroll; if (MenuTab.suppress_event) { warn_if_test ("Event suppressed"); @@ -179,6 +183,8 @@ public void scroll_up (double x, double y) { bool action = false; + + y -= current_set.scroll; if (MenuTab.suppress_event) { warn_if_test ("Event suppressed"); @@ -225,6 +231,8 @@ 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) { @@ -259,6 +267,8 @@ bool a; bool consumed = false; bool active; + + y -= current_set.scroll; MainWindow.set_cursor (NativeWindow.VISIBLE); @@ -453,14 +463,6 @@ } 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");
--- a/scripts/windows_build.py +++ b/scripts/windows_build.py @@ -16,7 +16,7 @@ valac = "valac" valaflags = "" cc = "gcc" - cflags = "-g -Wl,-subsystem,windows " + cflags = "-Wl,-subsystem,windows " ldflags = "" library_ldflags= "";