Commit d0dd7d3
Scale selection box when background image is scaled
Changed files (5)
modifiedlibbirdfont/BackgroundImage.valamodifiedlibbirdfont/BackgroundSelection.valamodifiedlibbirdfont/BackgroundTab.valamodifiedlibbirdfont/BackgroundTools.valamodifiedlibbirdfont/BirdFontFile.vala
Diff
@@ -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; @@ -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) {@@ -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);+ } } }@@ -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 ();@@ -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;