Commit eb04239
Import png images in a background thread
Changed files (6)
modifiedbirdfont/GtkWindow.valamodifiedlibbirdfont/BackgroundSelection.valamodifiedlibbirdfont/BackgroundTool.valamodifiedlibbirdfont/DrawingTools.valamodifiedlibbirdfont/GlyphBackgroundImage.valamodifiedlibbirdfont/NativeWindow.vala
Diff
@@ -923,6 +923,24 @@ public class GtkWindow : Gtk.Window, NativeWindow { MenuTab.signal_file_saved (); return null; }++ public void load_background_image () {+ unowned Thread<void*> thread;+ + MenuTab.start_background_thread ();+ + try {+ thread = Thread.create<void*> (this.background_image_thread, true);+ } catch (GLib.Error e) {+ warning (e.message);+ }+ }++ public void* background_image_thread () {+ BackgroundTool.load_background_image ();+ MenuTab.stop_background_thread ();+ return null;+ } } class TabbarCanvas : DrawingArea {@@ -314,7 +314,6 @@ class BackgroundSelection : FontDisplay { public override void scroll_wheel_down (double x, double y) { }- } }@@ -1,5 +1,5 @@ /*- Copyright (C) 2012 Johan Mattsson+ Copyright (C) 2012 2014 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 @@ -14,7 +14,7 @@ namespace BirdFont { -class BackgroundTool : Tool {+public class BackgroundTool : Tool { double begin_x = 0; double begin_y = 0;@@ -32,12 +32,16 @@ class BackgroundTool : Tool { bool move_bg; + static GlyphBackgroundImage imported_background;+ public BackgroundTool (string name) { base (name, t_("Move, resize and rotate background image")); top_limit = 0; bottom_limit = 0; + imported_background = new GlyphBackgroundImage ("");+ select_action.connect((self) => { }); @@ -143,6 +147,41 @@ class BackgroundTool : Tool { GlyphCanvas.redraw (); } + public static void load_background_image () {+ // generate png file if needed and load the image with cairo+ imported_background.load ();+ + IdleSource idle = new IdleSource ();+ idle.set_callback (() => {+ TabBar tb = MainWindow.get_tab_bar ();+ Glyph g = MainWindow.get_current_glyph ();+ g.set_background_image (imported_background);+ imported_background.center_in_glyph (); + tb.select_tab_name (g.get_name ());++ Toolbox.select_tool_by_name ("zoom_background_image");+ Toolbox.select_tool_by_name ("cut_background");+ + GlyphCanvas.redraw ();+ return false;+ });+ idle.attach (null);+ }++ internal static void import_background_image () {+ GlyphBackgroundImage bg;+ string? fn;+ string path;+ + fn = MainWindow.file_chooser_open (_("Select background image"));+ + if (fn != null) {+ path = (!) fn;+ bg = new GlyphBackgroundImage (path);+ imported_background = bg;+ MainWindow.native_window.load_background_image ();+ }+ } } }@@ -551,20 +551,9 @@ public class DrawingTools : ToolCollection { }); bg_selection.select_action.connect((self) => {- Glyph? g = null;- FontDisplay fd = MainWindow.get_current_display ();- TooltipArea.show_text (t_("Creating thumbnails"));- - if (fd is Glyph) {- g = (Glyph) fd;- } else {- return;+ if (MainWindow.get_current_display () is Glyph) {+ BackgroundTool.import_background_image (); }- - BackgroundSelection bgs = new BackgroundSelection ();- MainWindow.get_tab_bar ().add_unique_tab (bgs);- - TooltipArea.show_text (""); }); bg_selection.set_show_background (true);@@ -103,6 +103,10 @@ public class GlyphBackgroundImage { img_x = coordinate_x; img_y = coordinate_y; }+ + public void load () {+ get_img ();+ } public ImageSurface get_img () { if (!path.has_suffix (".png")) {@@ -834,6 +838,10 @@ public class GlyphBackgroundImage { update_background (contrast, get_desaturate_background ()); }+ + public void center_in_glyph () {+ Glyph g = MainWindow.get_current_glyph ();+ } } }@@ -65,6 +65,8 @@ public interface NativeWindow : GLib.Object { /** Save font in a background thread. */ public abstract void save (); + /** Load images in a background thread. */+ public abstract void load_background_image (); } }