Clone in a terminal:
Commit 9e6a32e
Johan Mattsson - 2014-11-10T21:03:18+00:00
9e6a32e551a3df23482b3d2d6ac9f91402e18f2fjohan.mattsson.m@gmail.com

Assign backgrounds to glyphs

Changed files (7)

Diff

diff --git a/libbirdfont/BackgroundSelection.vala b/libbirdfont/BackgroundSelection.valaindex 2616365..700bf4e 100644--- a/libbirdfont/BackgroundSelection.vala+++ b/libbirdfont/BackgroundSelection.vala@@ -16,7 +16,7 @@ namespace BirdFont {  public class BackgroundSelection : GLib.Object { 	-	public Glyph? assigned_glyph;+	public GlyphCollection? assigned_glyph; 	public BackgroundImage image; 	public BackgroundImage parent_image; 	diff --git a/libbirdfont/BackgroundTools.vala b/libbirdfont/BackgroundTools.valaindex 2c53a10..507eb3c 100644--- a/libbirdfont/BackgroundTools.vala+++ b/libbirdfont/BackgroundTools.vala@@ -36,22 +36,14 @@ public class BackgroundTools : ToolCollection  { 		parts.set_persistent (true); 		parts.set_unique (true); 		+		background_tools.add_tool (select_background);+		 		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);--		select_background.select_action.connect ((t) => {-			foreach (Tool tool in background_tools.tool) {-				tool.set_selected (false);-			}-		});-		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);@@ -70,30 +62,46 @@ public class BackgroundTools : ToolCollection  { 		parts.tool.clear (); 	} +	void set_default_canvas () {+		MainWindow.get_tab_bar ().select_tab_name ("Backgrounds");+	}+ 	public void add_part (BackgroundSelection selection) { 		BackgroundPartLabel label; 		label = new BackgroundPartLabel (selection, t_("No Glyph Selected")); 		label.select_action.connect ((t) => { 			BackgroundPartLabel bpl = (BackgroundPartLabel) t;+			GlyphSelection gs = new GlyphSelection (); +			gs.selected_glyph.connect ((gc) => {+				bpl.selection.assigned_glyph = gc;+				bpl.label = gc.get_name ();+				set_default_canvas ();+			});+			+			if (!bpl.deleted) {+				GlyphCanvas.set_display (gs);	+			}			 		}); 		label.delete_action.connect ((t) => { 			// don't invalidate the toolbox iterator 			IdleSource idle = new IdleSource ();  			idle.set_callback (() => {-				Glyph g;+				GlyphCollection g; 				BackgroundPartLabel bpl; 				 				bpl = (BackgroundPartLabel) t;+				bpl.deleted = true; 				 				if (bpl.selection.assigned_glyph != null){ 					g = (!) bpl.selection.assigned_glyph;-					g.set_background_image (null);+					g.get_current ().set_background_image (null); 				} 			 				parts.tool.remove (bpl); 				bpl.selection.parent_image.selections.remove (bpl.selection); 				MainWindow.get_toolbox ().update_expanders ();+				set_default_canvas (); 				Toolbox.redraw_tool_box (); 				GlyphCanvas.redraw (); 				return false;@@ -122,7 +130,6 @@ public class BackgroundTools : ToolCollection  { 	} 	 	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);@@ -136,7 +143,7 @@ public class BackgroundTools : ToolCollection  { 		image.name = fn; 		 		add_image (image);-		font.add_background_image (image);+		 		GlyphCanvas.redraw (); 		MainWindow.get_toolbox ().update_expanders (); 		Toolbox.redraw_tool_box ();@@ -146,16 +153,50 @@ public class BackgroundTools : ToolCollection  { 		LabelTool image_selection; 		double xc, yc; 		BackgroundTab bt;+		Font font;+		+		font = BirdFont.get_current_font ();  		image_selection = new BackgroundSelectionLabel (image, image.name); 		image_selection.select_action.connect ((t) => { 			BackgroundTab background_tab = BackgroundTab.get_instance (); 			BackgroundSelectionLabel bg = (BackgroundSelectionLabel) t;-			background_tab.set_background_image (bg.img);-			background_tab.set_background_visible (true);-			ZoomTool.zoom_full_background_image ();-			GlyphCanvas.redraw ();		+			+			if (!bg.deleted) {+				background_tab.set_background_image (bg.img);+				background_tab.set_background_visible (true);+				ZoomTool.zoom_full_background_image ();+				GlyphCanvas.redraw ();+			}+			+			set_default_canvas (); 		});+		+		image_selection.delete_action.connect ((t) => {+			// don't invalidate the toolbox iterator+			IdleSource idle = new IdleSource (); +			idle.set_callback (() => {+				GlyphCollection g;+				BackgroundSelectionLabel bsl;+				Font f = BirdFont.get_current_font ();+				+				bsl = (BackgroundSelectionLabel) t;+				bsl.deleted = true;+			+				files.tool.remove (bsl);+				f.background_images.remove (bsl.img);++				MainWindow.get_toolbox ().update_expanders ();+				set_default_canvas ();+				Toolbox.redraw_tool_box ();+				GlyphCanvas.redraw ();+				return false;+			});+			idle.attach (null);+		});+		+		image_selection.has_delete_button = true;+		 		files.add_tool (image_selection);  		bt = BackgroundTab.get_instance ();@@ -181,21 +222,27 @@ public class BackgroundTools : ToolCollection  { 				 		image.center_in_glyph (); 		ZoomTool.zoom_full_background_image ();+		+		font.add_background_image (image); 	} 	 	class BackgroundSelectionLabel : LabelTool { 		public BackgroundImage img;+		public bool deleted; 		public BackgroundSelectionLabel (BackgroundImage img, string base_name) { 			base (base_name); 			this.img = img;+			deleted = false; 		} 	}  	class BackgroundPartLabel : LabelTool {+		public bool deleted; 		public BackgroundSelection selection; 		public BackgroundPartLabel (BackgroundSelection selection, string base_name) { 			base (base_name); 			this.selection = selection;+			deleted = false; 		} 	} }diff --git a/libbirdfont/BirdFontFile.vala b/libbirdfont/BirdFontFile.valaindex 8a78deb..3f50503 100644--- a/libbirdfont/BirdFontFile.vala+++ b/libbirdfont/BirdFontFile.vala@@ -733,10 +733,7 @@ class BirdFontFile : GLib.Object { 					((!) 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.");-					}					+					warning (@"No image found, name: $name");				 				} 			} 		}diff --git a/libbirdfont/GlyphCanvas.vala b/libbirdfont/GlyphCanvas.valaindex 4a2de46..68a013f 100644--- a/libbirdfont/GlyphCanvas.vala+++ b/libbirdfont/GlyphCanvas.vala@@ -88,7 +88,7 @@ public class GlyphCanvas : GLib.Object { 		if (MenuTab.suppress_event) {
 			warning ("Do not call redraw from background thread.");
 		} else {
-			signal_redraw_area (x, y, w, h);;
+			signal_redraw_area (x, y, w, h);
 		}
 	}
 	
diff --git a/libbirdfont/GlyphSelection.vala b/libbirdfont/GlyphSelection.valanew file mode 100644index 0000000..3f2c074--- /dev/null+++ b/libbirdfont/GlyphSelection.vala@@ -0,0 +1,32 @@+/*+    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 GlyphSelection : OverView {++	public signal void selected_glyph (GlyphCollection gc);++	public GlyphSelection () {+		base (null, false);+		display_all_available_glyphs ();+		+		open_glyph_signal.connect ((gc) => {+			selected_glyph (gc);+			Toolbox.redraw_tool_box ();+		});+	}+}++}diff --git a/libbirdfont/OverView.vala b/libbirdfont/OverView.valaindex 9336af6..9fa1650 100644--- a/libbirdfont/OverView.vala+++ b/libbirdfont/OverView.vala@@ -53,7 +53,7 @@ public class OverView : FontDisplay { 	 	double scroll_size = 1; 	-	public OverView (GlyphRange? range = null) {+	public OverView (GlyphRange? range = null, bool open_selected = true) { 		GlyphRange gr;  		if (range == null) {@@ -62,49 +62,51 @@ public class OverView : FontDisplay { 		}  		reset_zoom ();--		this.open_glyph_signal.connect ((glyph_collection) => {-			TabBar tabs = MainWindow.get_tab_bar ();-			string n = glyph_collection.get_current ().name;-			bool selected = tabs.select_char (n);-			GlyphCanvas canvas;-			Glyph g = glyph_collection.get_current (); -			-			if (!selected) {-				canvas = MainWindow.get_glyph_canvas ();-				tabs.add_tab (g, true, glyph_collection);-				canvas.set_current_glyph_collection (glyph_collection);-				set_initial_zoom ();-			}-		});--		this.open_new_glyph_signal.connect ((character) => {-			StringBuilder name = new StringBuilder ();-			TabBar tabs = MainWindow.get_tab_bar ();-			bool selected;-			Glyph glyph;-			GlyphCollection glyph_collection;-			GlyphCanvas canvas;+		+		if (open_selected) {+			this.open_glyph_signal.connect ((glyph_collection) => {+				TabBar tabs = MainWindow.get_tab_bar ();+				string n = glyph_collection.get_current ().name;+				bool selected = tabs.select_char (n);+				GlyphCanvas canvas;+				Glyph g = glyph_collection.get_current ();  				-			name.append_unichar (character);-			selected = tabs.select_char (name.str);+				if (!selected) {+					canvas = MainWindow.get_glyph_canvas ();+					tabs.add_tab (g, true, glyph_collection);+					canvas.set_current_glyph_collection (glyph_collection);+					set_initial_zoom ();+				}+			});++			this.open_new_glyph_signal.connect ((character) => {+				StringBuilder name = new StringBuilder ();+				TabBar tabs = MainWindow.get_tab_bar ();+				bool selected;+				Glyph glyph;+				GlyphCollection glyph_collection;+				GlyphCanvas canvas; 					-			if (!selected) {-				glyph_collection = add_character_to_font (character);-				-				glyph = glyph_collection.get_current ();-				tabs.add_tab (glyph, true, glyph_collection);-				-				selected_items.add (glyph_collection);-				-				canvas = MainWindow.get_glyph_canvas ();-				canvas.set_current_glyph_collection (glyph_collection);+				name.append_unichar (character);+				selected = tabs.select_char (name.str);+						+				if (!selected) {+					glyph_collection = add_character_to_font (character);+					+					glyph = glyph_collection.get_current ();+					tabs.add_tab (glyph, true, glyph_collection);+					+					selected_items.add (glyph_collection);+					+					canvas = MainWindow.get_glyph_canvas ();+					canvas.set_current_glyph_collection (glyph_collection);+					+					set_initial_zoom ();+				} 				-				set_initial_zoom ();-			}-			-			OverviewTools.update_overview_characterset ();-		});+				OverviewTools.update_overview_characterset ();+			});+		} 		 		update_scrollbar (); 	}@@ -216,21 +218,21 @@ public class OverView : FontDisplay { 	public override void scroll_wheel_up (double x, double y) { 		key_up (); 		update_scrollbar ();-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	} 	 	public override void scroll_wheel_down (double x, double y) { 		key_down (); 		update_scrollbar ();-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	} 	 	public override void selected_canvas () { 		OverviewTools.update_overview_characterset ();-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 		KeyBindings.set_require_modifier (true); 		update_scrollbar ();-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	} 	 	public override void zoom_min () {@@ -238,7 +240,7 @@ public class OverView : FontDisplay { 		OverViewItem.height = OverViewItem.DEFAULT_HEIGHT * 0.5; 		OverViewItem.margin = OverViewItem.DEFAULT_MARGIN * 0.5; 		-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	} 	 	public override void reset_zoom () {@@ -246,27 +248,27 @@ public class OverView : FontDisplay { 		OverViewItem.height = OverViewItem.DEFAULT_HEIGHT; 		OverViewItem.margin = OverViewItem.DEFAULT_MARGIN; 		-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	}  	public override void zoom_max () { 		OverViewItem.width = allocation.width; 		OverViewItem.height = allocation.height;-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	} 	 	public override void zoom_in () { 		OverViewItem.width *= 1.1; 		OverViewItem.height *= 1.1; 		OverViewItem.margin *= 1.1;		-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	} 	 	public override void zoom_out () { 		OverViewItem.width *= 0.9; 		OverViewItem.height *= 0.9; 		OverViewItem.margin *= 0.9;	-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	}  	public override void store_current_view () {@@ -504,7 +506,7 @@ public class OverView : FontDisplay { 		 		scroll_to_position ((int64) r); 		-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	} 		 	private void scroll (double pixel_adjustment) {@@ -641,7 +643,7 @@ public class OverView : FontDisplay { 	} 	 	public override void key_press (uint keyval) {-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw ();  		if (KeyBindings.modifier == CTRL) { 			return;@@ -727,7 +729,7 @@ public class OverView : FontDisplay { 		} 		 		undo_items.remove_at (undo_items.size - 1);-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	} 	 	public override void redo () {@@ -748,7 +750,7 @@ public class OverView : FontDisplay { 		} 		 		redo_items.remove_at (redo_items.size - 1);-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	}	 	 	public OverViewUndoItem get_current_state (OverViewUndoItem previous_collection) {@@ -886,15 +888,28 @@ public class OverView : FontDisplay { 	} 	 	public override void double_click (uint button, double ex, double ey) -	requires (!is_null (visible_items)) {+		requires (!is_null (visible_items) && !is_null (allocation)) {+		+		return_if_fail (!is_null (this)); 		 		foreach (OverViewItem i in visible_items) {-			i.double_click (button, ex, ey);+			if (i.double_click (button, ex, ey)) {+				open_overview_item (i);+			} 		} 	-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	} +	public void open_overview_item (OverViewItem i) {+		if (i.glyphs != null) {+			open_glyph_signal ((!) i.glyphs);+			((!) i.glyphs).get_current ().close_path ();+		} else {+			open_new_glyph_signal (i.character);+		}+	}+	 	public void set_character_info (CharacterInfo i) { 		character_info = i; 	}@@ -927,7 +942,7 @@ public class OverView : FontDisplay { 		 		if (character_info != null) { 			character_info = null;-			redraw_area (0, 0, allocation.width, allocation.height);+			GlyphCanvas.redraw (); 			return; 		} 		@@ -960,7 +975,7 @@ public class OverView : FontDisplay { 		} 	 		update_item_list ();-		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	}  	/** Returns true if overview shows the last character. */@@ -991,7 +1006,7 @@ public class OverView : FontDisplay {  		// TODO: scroll down to c -		redraw_area (0, 0, allocation.width, allocation.height);+		GlyphCanvas.redraw (); 	}  	public void select_next_glyph () {@@ -999,7 +1014,7 @@ public class OverView : FontDisplay { 	} 	 	public void open_current_glyph () {-		selected_item.edit_glyph ();+		open_overview_item (selected_item); 	}  	public void update_scrollbar () {diff --git a/libbirdfont/OverViewItem.vala b/libbirdfont/OverViewItem.valaindex 3fe9fcc..86575a6 100644--- a/libbirdfont/OverViewItem.vala+++ b/libbirdfont/OverViewItem.vala@@ -90,25 +90,11 @@ public class OverViewItem : GLib.Object { 		return s; 	} -	public void double_click (uint button, double px, double py) {+	public bool double_click (uint button, double px, double py) { 		selected = (x <= px <= x + width) && (y <= py <= y + height);-		-		if (selected) {-			edit_glyph ();-		}-	}-	-	public void edit_glyph () {-		OverView overview = MainWindow.get_overview ();-		-		if (glyphs == null) {-			overview.open_new_glyph_signal (character);-		} else {-			overview.open_glyph_signal ((!) glyphs);-			((!) glyphs).get_current ().close_path ();-		}		+		return selected; 	}-	+ 	public void draw (Context cr) { 		cr.save (); 		cr.set_source_rgba (1, 1, 1, 1);

Contact

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