Clone in a terminal:
Commit eb04239
Johan Mattsson - 2014-07-11T21:37:10+00:00
eb042394b5ee1323d5145f2d4705f726947c8f86johan.mattsson.m@gmail.com

Import png images in a background thread

Changed files (6)

Diff

diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex ba64696..1d46663 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -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 {diff --git a/libbirdfont/BackgroundSelection.vala b/libbirdfont/BackgroundSelection.valaindex b0c37ca..61e4e3a 100644--- a/libbirdfont/BackgroundSelection.vala+++ b/libbirdfont/BackgroundSelection.vala@@ -314,7 +314,6 @@ class BackgroundSelection : FontDisplay {  	public override void scroll_wheel_down (double x, double y) { 	}- }  }diff --git a/libbirdfont/BackgroundTool.vala b/libbirdfont/BackgroundTool.valaindex 8f396d6..80bcabf 100644--- a/libbirdfont/BackgroundTool.vala+++ b/libbirdfont/BackgroundTool.vala@@ -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 ();+		}+	} }  }diff --git a/libbirdfont/DrawingTools.vala b/libbirdfont/DrawingTools.valaindex 1b08a8c..3de382d 100644--- a/libbirdfont/DrawingTools.vala+++ b/libbirdfont/DrawingTools.vala@@ -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);diff --git a/libbirdfont/GlyphBackgroundImage.vala b/libbirdfont/GlyphBackgroundImage.valaindex 825270c..7f0361c 100644--- a/libbirdfont/GlyphBackgroundImage.vala+++ b/libbirdfont/GlyphBackgroundImage.vala@@ -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 ();+	} } 	 }diff --git a/libbirdfont/NativeWindow.vala b/libbirdfont/NativeWindow.valaindex 69048b8..be01812 100644--- a/libbirdfont/NativeWindow.vala+++ b/libbirdfont/NativeWindow.vala@@ -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 (); }  }

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112