Clone in a terminal:
Commit d0dd7d3
Johan Mattsson - 2014-11-11T21:26:49+00:00
d0dd7d336c5697e1b7e2697c34c7c48830f976b5johan.mattsson.m@gmail.com

Scale selection box when background image is scaled

Changed files (5)

Diff

diff --git a/libbirdfont/BackgroundImage.vala b/libbirdfont/BackgroundImage.valaindex 9723fc4..b592ccb 100644--- a/libbirdfont/BackgroundImage.vala+++ b/libbirdfont/BackgroundImage.vala@@ -21,12 +21,14 @@ public class BackgroundImage { 	 	public string name = ""; 	public Gee.ArrayList<BackgroundSelection> selections;-	++	/** Image position in canvas coordinates. */ 	public double img_x = 0; 	public double img_y = 0;-	+		 	public double img_scale_x = 1; 	public double img_scale_y = 1;+	 	public double img_rotation = 0; 	private int size = -1; diff --git a/libbirdfont/BackgroundSelection.vala b/libbirdfont/BackgroundSelection.valaindex 348e35c..a93f4eb 100644--- a/libbirdfont/BackgroundSelection.vala+++ b/libbirdfont/BackgroundSelection.vala@@ -20,10 +20,50 @@ public class BackgroundSelection : GLib.Object { 	public BackgroundImage? image; 	public BackgroundImage parent_image; 	-	public double x;-	public double y;-	public double w;-	public double h;+	public double x {+		get {+			return x_img * parent_image.img_scale_x + parent_image.img_middle_x;+		}+		+		set {+			x_img = value / parent_image.img_scale_x - parent_image.img_middle_x;+		}+	}+	+	public double y {+		get {+			return y_img * parent_image.img_scale_y + parent_image.img_middle_y;+		}+		+		set {+			y_img = (value - parent_image.img_middle_y) / parent_image.img_scale_y;+		}+	}+	+	public double w {+		get {+			return width * parent_image.img_scale_x;+		}+		+		set {+			width = value / parent_image.img_scale_x;+		}+	}+	+	public double h {+		get {+			return height * parent_image.img_scale_y;+		}+		+		set {+			height = value / parent_image.img_scale_y;+		}+	}+	+	private double height;+	private double width;+	private double x_img;+	private double y_img; 	 	public BackgroundSelection (BackgroundImage? img, BackgroundImage parent_img, 		double x, double y, double w, double h) {diff --git a/libbirdfont/BackgroundTab.vala b/libbirdfont/BackgroundTab.valaindex b917c7a..ceca40c 100644--- a/libbirdfont/BackgroundTab.vala+++ b/libbirdfont/BackgroundTab.vala@@ -49,6 +49,12 @@ public class BackgroundTab : Glyph { 		canvas.set_current_glyph_collection (gc, false); 		DrawingTools.background_scale.set_tool_visibility (true); 	}+	+	public override void draw (WidgetAllocation allocation, Context cr) {+		base.draw (allocation, cr);+		Tool t = Toolbox.background_tools.select_background;+		t.draw_action (t, cr, this);+	} }  }diff --git a/libbirdfont/BackgroundTools.vala b/libbirdfont/BackgroundTools.valaindex ac51edb..95b8498 100644--- a/libbirdfont/BackgroundTools.vala+++ b/libbirdfont/BackgroundTools.vala@@ -15,12 +15,14 @@ namespace BirdFont {  public class BackgroundTools : ToolCollection  {+	+	public BackgroundSelectionTool select_background;+	 	Expander files; 	Expander parts; 	public Gee.ArrayList<Expander> expanders = new Gee.ArrayList<Expander> (); 	 	public BackgroundTools () {-		BackgroundSelectionTool select_background = new BackgroundSelectionTool (); 		Expander background_selection = new Expander (t_("Images")); 		Expander background_tools = new Expander (); @@ -28,6 +30,8 @@ public class BackgroundTools : ToolCollection  { 		font_name.add_tool (new FontName ()); 		font_name.draw_separator = false; +		select_background = new BackgroundSelectionTool ();+ 		files = new Expander (t_("Files")); 		files.set_persistent (true); 		files.set_unique (true);@@ -66,9 +70,23 @@ public class BackgroundTools : ToolCollection  { 		MainWindow.get_tab_bar ().select_tab_name ("Backgrounds"); 	} +	public void update_parts_list (BackgroundImage current_image) {+		parts.tool.clear ();+		+		foreach (BackgroundSelection selection in current_image.selections) {+			add_part (selection);+		}+	}+ 	public void add_part (BackgroundSelection selection) { 		BackgroundPartLabel label;-		label = new BackgroundPartLabel (selection, t_("Select Glyph"));+		+		if (selection.assigned_glyph == null) {+			label = new BackgroundPartLabel (selection, t_("Select Glyph"));+		} else {+			label = new BackgroundPartLabel (selection, (!) selection.assigned_glyph);+		}+		 		label.select_action.connect ((t) => { 			BackgroundPartLabel bpl = (BackgroundPartLabel) t; 			GlyphSelection gs = new GlyphSelection ();@@ -98,6 +116,7 @@ public class BackgroundTools : ToolCollection  { 				GlyphCanvas.set_display (gs);	 			}			 		});+		 		label.delete_action.connect ((t) => { 			// don't invalidate the toolbox iterator 			IdleSource idle = new IdleSource (); @@ -127,8 +146,11 @@ public class BackgroundTools : ToolCollection  { 		}); 		label.has_delete_button = true; 		parts.add_tool (label, 0);-		MainWindow.get_toolbox ().update_expanders ();-		Toolbox.redraw_tool_box ();+		+		if (!is_null (MainWindow.get_toolbox ())) {+			MainWindow.get_toolbox ().update_expanders ();+			Toolbox.redraw_tool_box ();+		} 	}  	public override Gee.ArrayList<Expander> get_expanders () {@@ -183,7 +205,9 @@ public class BackgroundTools : ToolCollection  { 				background_tab.set_background_image (bg.img); 				background_tab.set_background_visible (true); 				ZoomTool.zoom_full_background_image ();+				update_parts_list (bg.img); 				GlyphCanvas.redraw ();+				Toolbox.redraw_tool_box (); 			} 			 			set_default_canvas ();diff --git a/libbirdfont/BirdFontFile.vala b/libbirdfont/BirdFontFile.valaindex 311a71f..b6ead66 100644--- a/libbirdfont/BirdFontFile.vala+++ b/libbirdfont/BirdFontFile.vala@@ -787,14 +787,15 @@ class BirdFontFile : GLib.Object { 				if (new_img != null && name != "") { 					img = (!) new_img; 					img.name = name;+					+					Toolbox.background_tools.add_image (img);+					parse_image_selections (img, t);+					 					img.img_x = x; 					img.img_y = y; 					img.img_scale_x = scale_x; 					img.img_scale_y = scale_y; 					img.img_rotation = rotation;-					Toolbox.background_tools.add_image (img);-					-					parse_imgage_selections (img, t); 				} else { 					warning (@"No image found, name: $name");				 				}@@ -802,7 +803,7 @@ class BirdFontFile : GLib.Object { 		} 	} 	-	private void parse_imgage_selections (BackgroundImage image, Tag tag) {+	private void parse_image_selections (BackgroundImage image, Tag tag) { 		double x, y, w, h; 		string? assigned_glyph; 		BackgroundSelection s;

Contact

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