Clone in a terminal:
Commit bc09c7c
Johan Mattsson - 2014-11-10T12:40:28+00:00
bc09c7cc05e3ac8e18d3edac1c7cdbfe794d30b7johan.mattsson.m@gmail.com

Add images to background selection tab

Changed files (22)

Diff

diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex 9972e0c..e1cd17b 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -536,6 +536,10 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		import_svg_item.activate.connect (() => { SvgParser.import (); });	 		import_svg_item.add_accelerator ("activate", accel_group, 'I', Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE); +		Gtk.MenuItem add_backgrounds = new Gtk.MenuItem.with_mnemonic (t_("Add _Backgrounds"));+		edit_menu.append (add_backgrounds);+		add_backgrounds.activate.connect (() => { MenuTab.show_background_tab (); });	+ 		Gtk.MenuItem simplify_item = new Gtk.MenuItem.with_mnemonic (t_("Simpl_ify Path")); 		edit_menu.append (simplify_item); 		simplify_item.activate.connect (() => { MenuTab.simplify_path (); });	diff --git a/icons/select_background.png b/icons/select_background.pngnew file mode 100644index 0000000..3f8295eBinary files /dev/null and b/icons/select_background.png differdiff --git a/libbirdfont/BackgroundImage.vala b/libbirdfont/BackgroundImage.valaindex 2e9f823..57829f2 100644--- a/libbirdfont/BackgroundImage.vala+++ b/libbirdfont/BackgroundImage.vala@@ -18,6 +18,8 @@ using Math; namespace BirdFont { 	 public class BackgroundImage {+	+	public string name = ""; 		 	public double img_x = 0; 	public double img_y = 0;diff --git a/libbirdfont/BackgroundTab.vala b/libbirdfont/BackgroundTab.valanew file mode 100644index 0000000..b917c7a--- /dev/null+++ b/libbirdfont/BackgroundTab.vala@@ -0,0 +1,54 @@+/*+    Copyright (C) 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 +    published by the Free Software Foundation; either version 3 of the +    License, or (at your option) any later version.++    This library is distributed in the hope that it will be useful, but +    WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +    Lesser General Public License for more details.+*/++using Math;+using Cairo;++namespace BirdFont {++public class BackgroundTab : Glyph {+	+	static BackgroundTab singleton;+	+	public BackgroundTab () {+		base ("", '\0');+		singleton = this;+		add_help_lines ();+	}++	public static BackgroundTab get_instance () {+		if (is_null (singleton)) {+			singleton = new BackgroundTab ();+		}+		return singleton;+	}++	public override string get_name () {+		return "Backgrounds";+	}++	public override string get_label () {+		return t_("Background Image");+	}+	+	public override void selected_canvas () {+		GlyphCanvas canvas = MainWindow.get_glyph_canvas ();+		GlyphCollection gc = new GlyphCollection ('\0', "");+		gc.add_glyph (this);+		canvas.set_current_glyph_collection (gc, false);+		DrawingTools.background_scale.set_tool_visibility (true);+	}+}++}diff --git a/libbirdfont/BackgroundTools.vala b/libbirdfont/BackgroundTools.valanew file mode 100644index 0000000..bf910b8--- /dev/null+++ b/libbirdfont/BackgroundTools.vala@@ -0,0 +1,151 @@+/*+    Copyright (C) 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 +    published by the Free Software Foundation; either version 3 of the +    License, or (at your option) any later version.++    This library is distributed in the hope that it will be useful, but +    WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +    Lesser General Public License for more details.+*/++namespace BirdFont {++public class BackgroundTools : ToolCollection  {+	Expander files;+	public Gee.ArrayList<Expander> expanders = new Gee.ArrayList<Expander> ();+	+	public BackgroundTools () {+		Expander background_selection = new Expander (t_("Images"));+		Expander background_tools = new Expander ();++		Expander font_name = new Expander ();+		font_name.add_tool (new FontName ());+		font_name.draw_separator = false;++		files = new Expander (t_("Files"));+		files.set_persistent (true);+		files.set_unique (true);++		LabelTool add_new_image = new LabelTool (t_("Add"));+		add_new_image.select_action.connect ((t) => {+			load_image ();+		});+		background_selection.add_tool (add_new_image);++		LabelTool remove_image = new LabelTool (t_("Remove"));+		background_selection.add_tool (remove_image);+		+		Tool select_background = new Tool ("select_background", t_("Select Background"));+		select_background.select_action.connect ((self) => {+		});+		+		select_background.editor_events = true;+		select_background.persistent = true;+		background_tools.add_tool (select_background);++		background_tools.add_tool (DrawingTools.move_background);+		background_tools.add_tool (DrawingTools.move_canvas);+		background_tools.add_tool (DrawingTools.background_scale);++		expanders.add (font_name);+		expanders.add (background_tools);+		expanders.add (DrawingTools.view_tools);+		expanders.add (DrawingTools.guideline_tools);+		expanders.add (background_selection);+		expanders.add (files);+	}++	public void remove_images () {+		files.tool.clear ();+	}++	public override Gee.ArrayList<Expander> get_expanders () {+		return expanders;+	}++	void load_image () {+		FileChooser fc = new FileChooser ();+		fc.file_selected.connect ((fn) => {+			if (fn != null) {+				add_image_file ((!) fn);+			}+		});+		+		MainWindow.file_chooser (t_("Open"), fc, FileChooser.LOAD);+	}+	+	void add_image_file (string file_path) {+		Font font = BirdFont.get_current_font ();+		File f = File.new_for_path (file_path);+		string fn = (!) f.get_basename ();+		BackgroundImage image = new BackgroundImage (file_path);+		int i;+		+		i = fn.index_of (".");+		if (i > -1) {+			fn = fn.substring (0, i);+		}+		+		image.name = fn;+		+		add_image (image);+		font.add_background_image (image);+		GlyphCanvas.redraw ();+		Toolbox.redraw_tool_box ();+	}+	+	public void add_image (BackgroundImage image) {+		LabelTool image_selection;+		double xc, yc;+		BackgroundTab bt;++		image_selection = new BackgroundSelection (image, image.name);+		image_selection.select_action.connect ((t) => {+			BackgroundTab background_tab = BackgroundTab.get_instance ();+			BackgroundSelection bg = (BackgroundSelection) t;+			background_tab.set_background_image (bg.img);+			background_tab.set_background_visible (true);+			ZoomTool.zoom_full_background_image ();+			GlyphCanvas.redraw ();		+		});+		files.add_tool (image_selection);++		bt = BackgroundTab.get_instance ();+		bt.set_background_image (image);+		bt.set_background_visible (true);+		ZoomTool.zoom_full_background_image ();+		+		foreach (Tool t in files.tool) {+			t.set_selected (false);+		}+		image_selection.set_selected (true);++		bt.set_background_image (image);+		bt.set_background_visible (true);++		xc = image.img_middle_x;+		yc = image.img_middle_y;++		image.set_img_scale (0.2, 0.2);+		+		image.img_middle_x = xc;+		image.img_middle_y = yc;+				+		image.center_in_glyph ();+		ZoomTool.zoom_full_background_image ();+	}+	+	class BackgroundSelection : LabelTool {+		public BackgroundImage img;+		public BackgroundSelection (BackgroundImage img, string base_name) {+			base (base_name);+			this.img = img;+		}+	}+}++}diff --git a/libbirdfont/BirdFont.vala b/libbirdfont/BirdFont.valaindex 10aefd2..86256c1 100644--- a/libbirdfont/BirdFont.vala+++ b/libbirdfont/BirdFont.vala@@ -529,6 +529,10 @@ public class BirdFont { 			MainWindow.get_drawing_tools ().add_new_grid (); 		} 		+		if (!is_null (Toolbox.background_tools)) {+			Toolbox.background_tools.remove_images ();+		}+		 		KerningTools.update_kerning_classes (); 		 		return current_font;diff --git a/libbirdfont/BirdFontFile.vala b/libbirdfont/BirdFontFile.valaindex 84f0fb7..8a78deb 100644--- a/libbirdfont/BirdFontFile.vala+++ b/libbirdfont/BirdFontFile.vala@@ -125,17 +125,6 @@ class BirdFontFile : GLib.Object { 			write_settings (os); 			 			os.put_string ("\n");-			// FIXME: add this to a font specific settings file-			if (font.background_images.size > 0) {-				os.put_string (@"<images>\n");-				-				foreach (string f in font.background_images) {-					os.put_string (@"\t<img src=\"$f\"/>\n");-				}-			-				os.put_string (@"</images>\n");-				os.put_string ("\n");-			} 			 			font.glyph_cache.for_each ((gc) => { 				try {@@ -148,6 +137,10 @@ class BirdFontFile : GLib.Object { 			}); 			 			os.put_string ("\n");+			+			write_images (os);+			+			os.put_string ("\n"); 			write_ligatures (os); 			 			font.glyph_cache.for_each ((gc) => {@@ -162,16 +155,15 @@ class BirdFontFile : GLib.Object { 							 							if (!bg.is_valid ()) { 								continue;-							}+							}	 							-							os.put_string (@"<background-image sha1=\"");-							os.put_string (bg.get_sha1 ());-							os.put_string ("\" ");-							os.put_string (" data=\"");-							os.put_string (data);-							os.put_string ("\" />\n");	+							write_image (os, bg.get_sha1 (), data); 						} 					}+					+					foreach (BackgroundImage b in font.background_images) {+						write_image (os, b.get_sha1 (), b.get_png_base64 ());+					} 				} catch (GLib.Error ef) { 					warning (@"Failed to save $path \n"); 					warning (@"$(ef.message) \n");@@ -195,6 +187,33 @@ class BirdFontFile : GLib.Object { 		return true; 	} 	+	public void write_images (DataOutputStream os) throws GLib.Error {+		if (font.background_images.size > 0) {+			os.put_string (@"<images>\n");+			+			foreach (BackgroundImage b in font.background_images) {+				+				if (b.name == "") {+					warning ("No name.");+				}+				+				os.put_string (@"\t<image name=\"$(b.name)\" sha1=\"$(b.get_sha1 ())\"/>\n");+			}+		+			os.put_string (@"</images>\n");+			os.put_string ("\n");+		}	+	}+	+	public void write_image (DataOutputStream os, string sha1, string data) throws GLib.Error {+		os.put_string (@"<background-image sha1=\"");+		os.put_string (sha1);+		os.put_string ("\" ");+		os.put_string (" data=\"");+		os.put_string (data);+		os.put_string ("\" />\n");+	}+	 	public void write_root_tag (DataOutputStream os) throws GLib.Error { 		os.put_string ("""<?xml version="1.0" encoding="utf-8" standalone="yes"?>"""); 		os.put_string ("\n");@@ -671,7 +690,11 @@ class BirdFontFile : GLib.Object { 			if (t.get_name () == "weight") { 				font.weight = int.parse (t.get_content ()); 			}-							++			if (t.get_name () == "images") {+				parse_images (t);+			}+										 			TooltipArea.show_text (t_("Loading XML data.")); 		} @@ -679,6 +702,46 @@ class BirdFontFile : GLib.Object { 		return true; 	} 	+	public void parse_images (Tag tag) {+		BackgroundImage? new_img;+		string name;+		File img_file;+		+		foreach (Tag t in tag) {+			if (t.get_name () == "image") {+				name = "";+				new_img = null;+				img_file = get_child (font.get_backgrounds_folder (), "parts");++				foreach (Attribute attr in t.get_attributes ()) {+					if (attr.get_name () == "sha1") {+						img_file = get_child (img_file, attr.get_content () + ".png");++						if (!img_file.query_exists ()) {+							warning (@"Background file has not been created yet. $((!) img_file.get_path ())");+						}+						+						new_img = new BackgroundImage ((!) img_file.get_path ());+					}+					+					if (attr.get_name () == "name") {+						name = attr.get_content ();+					}+				}+				+				if (new_img != null && name != "") {+					((!) new_img).name = name;+					Toolbox.background_tools.add_image ((!) new_img);+				} else {+					warning (@"No image found, name: $name");+					if (new_img == null) {+						warning ("No image created.");+					}					+				}+			}+		}+	}+	 	private void create_background_files (Tag root) { 		foreach (Tag child in root) { 			if (child.get_name () == "name") {diff --git a/libbirdfont/BirdFontPart.vala b/libbirdfont/BirdFontPart.valaindex 2a5b4a7..c3bc8a5 100644--- a/libbirdfont/BirdFontPart.vala+++ b/libbirdfont/BirdFontPart.vala@@ -12,8 +12,6 @@     Lesser General Public License for more details. */ -// FIXME: using Git;- namespace BirdFont {  /** BirdFontPart is a class for parsing .bfp files. The file format is @@ -27,8 +25,6 @@ public class BirdFontPart : GLib.Object{ 	Font font; 	Gee.ArrayList<string> parts; 	string root_directory;-	// Index git_index;-	// Repository? git_repository;  	static string FILE_ATTRIBUTES = "standard::*"; @@ -39,22 +35,6 @@ public class BirdFontPart : GLib.Object{ 		parts = new Gee.ArrayList<string> (); 		root_directory = ""; 	}--	public static void git_init () {-		if (!running_git) {-// FIXME: 			Git.Threads.init ();-		}-		-		running_git = true;-	}--	public static void git_shutdown () {-		if (running_git) {-// FIXME: 			Git.Threads.shutdown ();-		}-		-		running_git = false;-	} 	 	public bool load (string bfp_file) { 		BirdFontFile bf = new BirdFontFile (font);@@ -94,30 +74,6 @@ public class BirdFontPart : GLib.Object{ 		return path; 	} 	-	bool create_git_repository () {-		// FIXME: -		/*-		File root = File.new_for_path (root_directory);-		File git = root.get_child (".git");-		Repository repo;-		-		if (!git.query_exists ()) {-			if (Repository.init (out repo, root_directory, false) != Git.Error.OK) {-				warning ("Can not create git repository.");-				return false;-			}-		}--		if (Repository.open (out git_repository, root_directory) != Git.Error.OK) {-			warning ("Can not open git repository.");-			return false;-		}-					-		// FIXME: ((!) git_repository).get_index (out git_index);-*/-		return true;-	}-	 	public bool save () { 		DataOutputStream os; 		BirdFontFile bf = new BirdFontFile (font);@@ -125,36 +81,11 @@ public class BirdFontPart : GLib.Object{ 		string file_name; 		string glyph_dir_name; 		File glyph_file;-// FIXME: 		Signature? sig;-// FIXME: 		object_id id;-// FIXME: 		Git.Tree tree;-		int nparents;-// FIXME: 		Git.Commit[] parents; 		 		if (root_directory == "") { 			warning ("No directory is created for this birdfont part."); 			return false; 		}-		-		git_init ();-		-		if (!create_git_repository ()) {-			return false;-		}-		-		// FIXME: return_val_if_fail (!is_null (git_repository), false);-		/*-		if (git_index.write_tree (out id) != Git.Error.OK) {-			warning ("write_tree failed");-			error = true;-		}-			-		Signature.create_now (out sig, "Test Namn", "test@test.com");-		-		if (((!) git_repository).lookup_tree(out tree, id) != Git.Error.OK) {-			warning ("Can't find tree.");-			error = true;-		}              		try { 			// remove deleted glyphs@@ -245,28 +176,19 @@ public class BirdFontPart : GLib.Object{ 			bf.write_kerning (os); 			bf.write_closing_root_tag (os); 			os.close ();-			++			os = create_file ("images.bfp");+			bf.write_root_tag (os);+			bf.write_images (os);+			bf.write_closing_root_tag (os);+			os.close ();+						 		} catch (GLib.Error e) { 			warning (@"Failed to save bfp files to $root_directory\n"); 			warning (@"$(e.message) \n"); 			error = true; 		}--		if (((!) git_repository).is_empty) {-			nparents = 0;-		} else {-			nparents = 0;-		}-		-		parents = new Git.Commit[0];-		if (((!) git_repository).create_commit (id, "HEAD", (!) sig, (!) sig, -				"utf-8", "Improved typeface", tree, parents) != Git.Error.OK) {-			warning ("Can't commit");-			error = true;-		} 		-		git_shutdown ();-		*/ 		return !error; 	} diff --git a/libbirdfont/CutBackgroundTool.vala b/libbirdfont/CutBackgroundTool.valaindex debeda2..99b15e7 100644--- a/libbirdfont/CutBackgroundTool.vala+++ b/libbirdfont/CutBackgroundTool.vala@@ -17,7 +17,7 @@ using Math;  namespace BirdFont { -class CutBackgroundTool : Tool {+public class CutBackgroundTool : Tool {  	double x1 = 0; 	double y1 = 0;diff --git a/libbirdfont/DrawingTools.vala b/libbirdfont/DrawingTools.valaindex 4837266..7670a99 100644--- a/libbirdfont/DrawingTools.vala+++ b/libbirdfont/DrawingTools.vala@@ -23,9 +23,11 @@ public class DrawingTools : ToolCollection  { 	public Gee.ArrayList<Expander> expanders = new Gee.ArrayList<Expander> (); 	 	Expander draw_tools;-	Expander draw_tool_modifiers; 	Expander grid_expander; 	Expander shape_tools;+	public static Expander draw_tool_modifiers;+	public static Expander view_tools;+	public static Expander guideline_tools; 	 	public static SpinButton precision; 	@@ -38,11 +40,11 @@ public class DrawingTools : ToolCollection  {  	ForesightTool foresight_tool; 	PointTool point_tool;-	ZoomTool zoom_tool;+	static ZoomTool zoom_tool; 	public static ResizeTool resize_tool; 	StrokeTool stroke_tool; 	TrackTool track_tool;-	BackgroundTool move_background;+	public static BackgroundTool move_background; 	public static Tool move_canvas; 	 	Tool quadratic_points;@@ -50,11 +52,11 @@ public class DrawingTools : ToolCollection  { 	Tool double_points; 	Tool convert_points; -	CutBackgroundTool cut_background;+	public static CutBackgroundTool cut_background; 	Tool show_bg; 	Tool bg_selection; 	SpinButton background_threshold;-	public SpinButton background_scale;+	public static SpinButton background_scale; 	Tool high_contrast_background; 	SpinButton auto_trace_resolution; 	Tool auto_trace;@@ -97,12 +99,12 @@ public class DrawingTools : ToolCollection  { 		draw_tools = new Expander (t_("Drawing Tools")); 		draw_tool_modifiers = new Expander (t_("Control Point Tools")); 		shape_tools = new Expander (t_("Geometrical Shapes"));+		view_tools = new Expander (t_("Zoom"));+		guideline_tools = new Expander (t_("Guidelines & Grid")); 		 		Expander font_name = new Expander (); 		Expander key_tools = new Expander (); // tools on android 		Expander test_tools = new Expander ();-		Expander guideline_tools = new Expander (t_("Guidelines & Grid"));-		Expander view_tools = new Expander (t_("Zoom")); 		Expander grid = new Expander (t_("Grid Size"));  		Expander style_tools = new Expander ();@@ -878,10 +880,7 @@ public class DrawingTools : ToolCollection  { 		zoom_bg.select_action.connect((self) => { 			if (MainWindow.get_current_glyph ().get_background_image () != null) { 				zoom_tool.store_current_view ();					-				glyph_canvas.get_current_display ().reset_zoom ();-				-				zoom_tool.zoom_full_background_image ();-				+				ZoomTool.zoom_full_background_image (); 				glyph_canvas.redraw_area(0, 0, GlyphCanvas.allocation.width, GlyphCanvas.allocation.height); 			} 		});@@ -1147,9 +1146,11 @@ public class DrawingTools : ToolCollection  { 		 		move_background.editor_events = true; 		cut_background.editor_events = true;-				+		move_canvas.editor_events = true;	+		 		move_background.persistent = true; 		cut_background.persistent = true;+		move_canvas.persistent = true;  		precision.persistent = true; 		stroke_width.persistent = true;@@ -1301,9 +1302,9 @@ public class DrawingTools : ToolCollection  { 		flip_horizontal.set_tool_visibility (true); 	} 	-	void update_drawing_and_background_tools (Tool current_tool) {+	public void update_drawing_and_background_tools (Tool current_tool) { 		IdleSource idle = new IdleSource ();-		+ 		idle.set_callback (() => { 			Glyph g = MainWindow.get_current_glyph (); diff --git a/libbirdfont/Expander.vala b/libbirdfont/Expander.valaindex 1485b0f..ea7b725 100644--- a/libbirdfont/Expander.vala+++ b/libbirdfont/Expander.vala@@ -102,7 +102,7 @@ public class Expander : GLib.Object { 		}  		foreach (Tool t in tool) {-			if (t is OverviewTool) {+			if (t is LabelTool) { 				t.w = Toolbox.allocation_width * scale; 				t.h = 15 * scale; 			} else if (t is FontName) {diff --git a/libbirdfont/FileTab.vala b/libbirdfont/FileTab.valaindex eb0cada..d7d7650 100644--- a/libbirdfont/FileTab.vala+++ b/libbirdfont/FileTab.vala@@ -58,7 +58,7 @@ public class FileTab : FontDisplay { 				MainWindow.get_drawing_tools ().parse_grid (v); 			} 			-			MainWindow.get_drawing_tools ().background_scale.set_value (f.background_scale);+			DrawingTools.background_scale.set_value (f.background_scale); 			KerningTools.update_kerning_classes (); 			MenuTab.show_all_available_characters (); 		});diff --git a/libbirdfont/Font.vala b/libbirdfont/Font.valaindex 71d7200..21bfe72 100644--- a/libbirdfont/Font.vala+++ b/libbirdfont/Font.vala@@ -35,7 +35,7 @@ public class Font : GLib.Object { 	/** Table with ligatures. */ 	public GlyphTable ligature; 	-	public Gee.ArrayList<string> background_images = new Gee.ArrayList<string> ();+	public Gee.ArrayList<BackgroundImage> background_images; 	public string background_scale = "1"; 		 	/** Top margin */@@ -128,6 +128,8 @@ public class Font : GLib.Object { 		 		deleted_glyphs = new Gee.ArrayList<Glyph> (); 		ligatures_substitution = new Ligatures ();+		+		background_images = new Gee.ArrayList<BackgroundImage> (); 	}  	public Ligatures get_ligatures () {@@ -540,8 +542,8 @@ public class Font : GLib.Object { 		return null; 	} 	-	public void add_background_image (string file) {-		background_images.add (file);+	public void add_background_image (BackgroundImage image) {+		background_images.add (image); 	} 	 	/** Delete temporary rescue files. */diff --git a/libbirdfont/GlyphCanvas.vala b/libbirdfont/GlyphCanvas.valaindex 074b7ae..4a2de46 100644--- a/libbirdfont/GlyphCanvas.vala+++ b/libbirdfont/GlyphCanvas.vala@@ -55,13 +55,15 @@ public class GlyphCanvas : GLib.Object { 		current_display = fd;
 	}
 	
-	public void set_current_glyph_collection (GlyphCollection gc) {
+	public void set_current_glyph_collection (GlyphCollection gc, bool signal_selected = true) {
 		Glyph g = gc.get_current ();
 		
 		BirdFont.current_glyph_collection = gc;
 		g.resized (allocation);
 		
-		current_display.selected_canvas ();
+		if (signal_selected) {
+			current_display.selected_canvas ();
+		}
 		
 		current_display.redraw_area.connect ((x, y, w, h) => {
 			signal_redraw_area ((int)x, (int)y, (int)w, (int)h);
diff --git a/libbirdfont/LabelTool.vala b/libbirdfont/LabelTool.valanew file mode 100644index 0000000..ea80888--- /dev/null+++ b/libbirdfont/LabelTool.vala@@ -0,0 +1,106 @@+/*+    Copyright (C) 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 +    published by the Free Software Foundation; either version 3 of the +    License, or (at your option) any later version.++    This library is distributed in the hope that it will be useful, but +    WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +    Lesser General Public License for more details.+*/++using Cairo;++namespace BirdFont {++public class LabelTool : Tool {++	private static ImageSurface? counter_background = null;+	public string label { get; set; }+	public string number { get; set; }+	public bool has_counter { get; set; }++	public LabelTool (string label) {+		base ();++		this.label = label;+		this.number = "-";+		+		has_counter = false;+		counter_background = Icons.get_icon ("overview_counter.png");+		+		panel_press_action.connect ((selected, button, tx, ty) => {+		});++		panel_move_action.connect ((selected, button, tx, ty) => {+			return false;+		});+	}+	+	public override void draw (Context cr) {+		Text font_name, glyph_count;+		double text_height;+		double scale, bgx, bgy;+		double center_x, center_y;+		+		// background+		if (is_selected ()) {+			cr.save ();+			cr.set_source_rgba (38 / 255.0, 39 / 255.0, 43 / 255.0, 1);+			cr.rectangle (0, y - 2, w, h + 7);+			cr.fill ();+			cr.restore ();		+		}+		+		// tab label+		cr.save ();+		font_name = new Text ();+		font_name.set_text (label);+		text_height = 18;++		if (is_selected ()) {+			cr.set_source_rgba (1, 1, 1, 1);+		} else {+			cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1);+		}+		+		font_name.draw (cr, x + 14, y - 4.5, text_height);+		cr.restore ();++		// glyph count+		if (has_counter && counter_background != null) {+			cr.save ();+			scale = 30.0 / 111.0; // scale to 320 dpi+			cr.scale (scale, scale);+			+			bgx = Toolbox.allocation_width / scale - ((!) counter_background).get_width () - 15 / scale;+			bgy = y / scale + 2 / scale;+			+			cr.set_source_surface ((!) counter_background, bgx, bgy);+			cr.paint ();+			+			glyph_count = new Text ();+			glyph_count.set_text (@"$(this.number)");+			text_height = 12 / scale;+			+			center_x = bgx + ((!) counter_background).get_width () / 2.0  - glyph_count.get_extent (text_height) / 2.0;+			center_y = bgy + ((!) counter_background).get_height () / 2.0 - text_height / 2.0 - 3 / scale;;+			+			if (is_selected ()) {+				cr.set_source_rgba (1, 1, 1, 1);+			} else {+				cr.set_source_rgba (51 / 255.0, 54 / 255.0, 59 / 255.0, 1);+			}+			+			glyph_count.draw (cr, center_x, center_y, text_height);+									+			cr.restore ();+		}+		+	}+}++}diff --git a/libbirdfont/MainWindow.vala b/libbirdfont/MainWindow.valaindex b68c22e..30c01c2 100644--- a/libbirdfont/MainWindow.vala+++ b/libbirdfont/MainWindow.vala@@ -84,7 +84,7 @@ public class MainWindow : GLib.Object { 	}
 
 	public static DrawingTools get_drawing_tools () {
-		return tools.drawing_tools;
+		return Toolbox.drawing_tools;
 	}
 
 	public void set_native (NativeWindow nw) {
diff --git a/libbirdfont/MenuTab.vala b/libbirdfont/MenuTab.valaindex f1850df..08b1446 100644--- a/libbirdfont/MenuTab.vala+++ b/libbirdfont/MenuTab.vala@@ -135,7 +135,7 @@ public class MenuTab : FontDisplay { 	} 		 	public static void set_font_setting_from_tools (Font f) {	-		f.background_scale = MainWindow.get_drawing_tools ().background_scale.get_display_value ();+		f.background_scale = DrawingTools.background_scale.get_display_value (); 		 		f.grid_width.clear (); 		@@ -521,6 +521,18 @@ public class MenuTab : FontDisplay { 		MainWindow.get_tab_bar ().select_tab_name ("Overview"); 		OverviewTools.show_all_available_characters (); 	}+	+	public static void show_background_tab () {+		BackgroundTab bt;+		+		if (suppress_event) {+			warn_if_test ("Event suppressed");+			return;+		}+		+		bt = BackgroundTab.get_instance ();+		MainWindow.get_tab_bar ().add_unique_tab (bt);+	} }  }diff --git a/libbirdfont/OverviewTool.vala b/libbirdfont/OverviewTool.valadeleted file mode 100644index c4e90fd..0000000--- a/libbirdfont/OverviewTool.vala+++ /dev/null@@ -1,110 +0,0 @@-/*-    Copyright (C) 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 -    published by the Free Software Foundation; either version 3 of the -    License, or (at your option) any later version.--    This library is distributed in the hope that it will be useful, but -    WITHOUT ANY WARRANTY; without even the implied warranty of -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -    Lesser General Public License for more details.-*/--using Cairo;--namespace BirdFont {--public class OverviewTool : Tool {--	private static ImageSurface? counter_background = null;-	public string label { get; set; }-	public string number { get; set; }-	public bool has_counter { get; set; }--	public OverviewTool (string label) {-		base ();--		this.label = label;-		this.number = "-";-		-		has_counter = true;-		counter_background = Icons.get_icon ("overview_counter.png");-		-		panel_press_action.connect ((selected, button, tx, ty) => {-		});--		panel_move_action.connect ((selected, button, tx, ty) => {-			return false;-		});--		panel_release_action.connect ((selected, button, tx, ty) => {-			set_selected (y <= ty <= y + h);-		});-	}-	-	public override void draw (Context cr) {-		Text font_name, glyph_count;-		double text_height;-		double scale, bgx, bgy;-		double center_x, center_y;-		-		// background-		if (is_selected ()) {-			cr.save ();-			cr.set_source_rgba (38 / 255.0, 39 / 255.0, 43 / 255.0, 1);-			cr.rectangle (0, y - 2, w, h + 7);-			cr.fill ();-			cr.restore ();		-		}-		-		// tab label-		cr.save ();-		font_name = new Text ();-		font_name.set_text (label);-		text_height = 18;--		if (is_selected ()) {-			cr.set_source_rgba (1, 1, 1, 1);-		} else {-			cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1);-		}-		-		font_name.draw (cr, x + 14, y - 4.5, text_height);-		cr.restore ();--		// glyph count-		if (has_counter && counter_background != null) {-			cr.save ();-			scale = 30.0 / 111.0; // scale to 320 dpi-			cr.scale (scale, scale);-			-			bgx = Toolbox.allocation_width / scale - ((!) counter_background).get_width () - 15 / scale;-			bgy = y / scale + 2 / scale;-			-			cr.set_source_surface ((!) counter_background, bgx, bgy);-			cr.paint ();-			-			glyph_count = new Text ();-			glyph_count.set_text (@"$(this.number)");-			text_height = 12 / scale;-			-			center_x = bgx + ((!) counter_background).get_width () / 2.0  - glyph_count.get_extent (text_height) / 2.0;-			center_y = bgy + ((!) counter_background).get_height () / 2.0 - text_height / 2.0 - 3 / scale;;-			-			if (is_selected ()) {-				cr.set_source_rgba (1, 1, 1, 1);-			} else {-				cr.set_source_rgba (51 / 255.0, 54 / 255.0, 59 / 255.0, 1);-			}-			-			glyph_count.draw (cr, center_x, center_y, text_height);-									-			cr.restore ();-		}-		-	}-}--}diff --git a/libbirdfont/OverviewTools.vala b/libbirdfont/OverviewTools.valaindex 0aedd6f..c169cde 100644--- a/libbirdfont/OverviewTools.vala+++ b/libbirdfont/OverviewTools.vala@@ -18,11 +18,11 @@ namespace BirdFont {  public class OverviewTools : ToolCollection  { -	static OverviewTool all_glyphs;-	static OverviewTool default_glyphs;-	static OverviewTool unicode;+	static LabelTool all_glyphs;+	static LabelTool default_glyphs;+	static LabelTool unicode; -	static Gee.ArrayList<OverviewTool> custom_character_sets;+	static Gee.ArrayList<LabelTool> custom_character_sets;  	public static Gee.ArrayList<Expander> expanders; @@ -31,12 +31,13 @@ public class OverviewTools : ToolCollection  { 		Expander character_sets = new Expander (t_("Character Sets")); 		 		expanders = new Gee.ArrayList<Expander> ();-		custom_character_sets = new Gee.ArrayList<OverviewTool> ();+		custom_character_sets = new Gee.ArrayList<LabelTool> (); 		 		font_name.add_tool (new FontName ()); 		font_name.draw_separator = false; 				-		all_glyphs = new OverviewTool (t_("All Glyphs"));+		all_glyphs = new LabelTool (t_("All Glyphs"));+		all_glyphs.has_counter = true; 		all_glyphs.select_action.connect ((self) => { 			OverView overview = MainWindow.get_overview (); 			overview.display_all_available_glyphs ();@@ -44,7 +45,8 @@ public class OverviewTools : ToolCollection  { 		}); 		character_sets.add_tool (all_glyphs); -		default_glyphs = new OverviewTool (t_("Default"));+		default_glyphs = new LabelTool (t_("Default"));+		default_glyphs.has_counter = true; 		default_glyphs.select_action.connect ((self) => { 			OverView overview = MainWindow.get_overview (); 			GlyphRange gr = new GlyphRange ();@@ -54,7 +56,8 @@ public class OverviewTools : ToolCollection  { 		}); 		character_sets.add_tool (default_glyphs); -		unicode = new OverviewTool (t_("Unicode"));+		unicode = new LabelTool (t_("Unicode"));+		unicode.has_counter = true; 		unicode.select_action.connect ((self) => { 			OverView overview = MainWindow.get_overview (); 			GlyphRange gr = new GlyphRange ();diff --git a/libbirdfont/PenTool.vala b/libbirdfont/PenTool.valaindex e6db257..fb47c47 100644--- a/libbirdfont/PenTool.vala+++ b/libbirdfont/PenTool.vala@@ -752,7 +752,7 @@ public class PenTool : Tool { 		return_if_fail (g != null);  		if ((double_click && !BirdFont.android)-				|| tb.drawing_tools.inser_point_on_path_tool.is_selected ()) {+				|| Toolbox.drawing_tools.inser_point_on_path_tool.is_selected ()) { 			glyph.insert_new_point_on_path (x, y); 			return; 		}diff --git a/libbirdfont/Toolbox.vala b/libbirdfont/Toolbox.valaindex 7e24e05..247c012 100644--- a/libbirdfont/Toolbox.vala+++ b/libbirdfont/Toolbox.vala@@ -18,12 +18,13 @@ using Math; namespace BirdFont {  public class Toolbox : GLib.Object  {-	ToolCollection current_set; +	public static ToolCollection current_set;  	-	public DrawingTools drawing_tools;+	public static DrawingTools drawing_tools; 	public KerningTools kerning_tools; 	public PreviewTools preview_tools; 	public OverviewTools overview_tools;+	public static BackgroundTools background_tools; 	 	Tool current_tool; 	@@ -51,6 +52,7 @@ public class Toolbox : GLib.Object  { 		kerning_tools = new KerningTools (); 		preview_tools = new PreviewTools (); 		overview_tools = new OverviewTools ();+		background_tools = new BackgroundTools (); 		 		tool_sets.append (drawing_tools); 		tool_sets.append (kerning_tools);@@ -66,6 +68,8 @@ public class Toolbox : GLib.Object  { 				current_set = preview_tools; 			} else if (tab_name == "Overview") { 				current_set = overview_tools;+			} else if (tab_name == "Backgrounds") {+				current_set = background_tools; 			} else { 				current_set = drawing_tools; 			}diff --git a/libbirdfont/ZoomTool.vala b/libbirdfont/ZoomTool.valaindex 2551fa5..c1cc96b 100644--- a/libbirdfont/ZoomTool.vala+++ b/libbirdfont/ZoomTool.vala@@ -14,7 +14,7 @@  namespace BirdFont { -class ZoomTool : Tool {+public class ZoomTool : Tool {  	int zoom_area_begin_x = -1; 	int zoom_area_begin_y = -1;@@ -69,11 +69,13 @@ class ZoomTool : Tool { 		}); 	} -	public void zoom_full_background_image () {+	public static void zoom_full_background_image () { 		BackgroundImage bg; 		Glyph g = MainWindow.get_current_glyph (); 		int x, y; 		+		g.reset_zoom ();+		 		if (g.get_background_image () == null) { 			return; 		}

Contact

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