Commit 3d8aadf
keep view after window is resized
Changed files (13)
modifiedbirdfont/GtkWindow.valamodifiedlibbirdfont/Allocation.valamodifiedlibbirdfont/BackgroundSelection.valamodifiedlibbirdfont/FontDisplay.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/GlyphBackgroundImage.valamodifiedlibbirdfont/GlyphCanvas.valamodifiedlibbirdfont/KerningDisplay.valamodifiedlibbirdfont/Line.valamodifiedlibbirdfont/OverView.valamodifiedlibbirdfont/Path.valamodifiedlibbirdfont/TooltipArea.valamodifiedlibbirdfont/ZoomView.vala
Diff
@@ -892,8 +892,9 @@ class ToolboxCanvas : DrawingArea { public class GlyphCanvasArea : DrawingArea { GlyphCanvas glyph_canvas;- Gtk.Allocation alloc;-+ WidgetAllocation alloc = new WidgetAllocation ();+ WidgetAllocation prev_alloc = new WidgetAllocation ();+ public GlyphCanvasArea (GlyphCanvas gc) { int event_flags; @@ -915,23 +916,28 @@ public class GlyphCanvasArea : DrawingArea { Gtk.Allocation allocation; get_allocation (out allocation); - glyph_canvas.allocation.width = allocation.width;- glyph_canvas.allocation.height = allocation.height;- glyph_canvas.allocation.y = allocation.x;- glyph_canvas.allocation.y = allocation.y;- - if (unlikely (allocation != alloc && alloc.width != 0)) {- BirdFont.current_glyph.resized ();- }+ alloc = new WidgetAllocation ();++ alloc.width = allocation.width;+ alloc.height = allocation.height;+ alloc.x = allocation.x;+ alloc.y = allocation.y; - alloc = allocation;+ glyph_canvas.set_allocation (alloc);+ BirdFont.current_glyph.resized (alloc);+ + prev_alloc = new WidgetAllocation ();+ prev_alloc.width = allocation.width;+ prev_alloc.height = allocation.height;+ prev_alloc.x = allocation.x;+ prev_alloc.y = allocation.y; Context cw = cairo_create (get_window()); - Surface s = new Surface.similar (cw.get_target (), Cairo.Content.COLOR_ALPHA, allocation.width, allocation.height);+ Surface s = new Surface.similar (cw.get_target (), Cairo.Content.COLOR_ALPHA, alloc.width, alloc.height); Context c = new Context (s); - glyph_canvas.current_display.draw (glyph_canvas.allocation, c);+ glyph_canvas.current_display.draw (alloc, c); cw.save (); cw.set_source_surface (c.get_target (), 0, 0);@@ -1011,8 +1017,9 @@ public class TooltipCanvas : DrawingArea { tooltip_area = ta; expose_event.connect ((t, e)=> {- Allocation allocation = {0, 0, 0, 0};+ WidgetAllocation allocation = new WidgetAllocation (); Gtk.Allocation alloc;+ Context cr = cairo_create (get_window ()); get_allocation (out alloc);@@ -14,11 +14,20 @@ namespace BirdFont { -public struct Allocation {- public int width;- public int height;- public int x;- public int y;+public class WidgetAllocation : GLib.Object {+ public int width = 0;+ public int height = 0;+ public int x = 0;+ public int y = 0;+ + public WidgetAllocation copy () {+ WidgetAllocation w = new WidgetAllocation ();+ w.x = x;+ w.y = y;+ w.width = width;+ w.height = height;+ return w;+ } } }@@ -22,7 +22,7 @@ class BackgroundSelection : FontDisplay { int active_box = -1; ImageSurface add_icon; List <string> background_images = new List <string> ();- Allocation allocation;+ WidgetAllocation allocation; Glyph glyph; public BackgroundSelection () {@@ -44,7 +44,7 @@ class BackgroundSelection : FontDisplay { return "Backgrounds"; } - public override void draw (Allocation allocation, Context cr) { + public override void draw (WidgetAllocation allocation, Context cr) { double x, y, zoom; int box_index = 0; Font font;@@ -84,7 +84,7 @@ public abstract class FontDisplay : GLib.Object { return ""; } - public virtual void draw (Allocation allocation, Context cr) {+ public virtual void draw (WidgetAllocation allocation, Context cr) { } public virtual void selected_canvas () {@@ -57,7 +57,7 @@ public class Glyph : FontDisplay { public double move_offset_x = 0; public double move_offset_y = 0; - public Allocation allocation;+ public static WidgetAllocation allocation = new WidgetAllocation (); public string name; @@ -255,19 +255,19 @@ public class Glyph : FontDisplay { return 1 / MainWindow.get_current_glyph ().view_zoom; } - public void resized () {- double a, b, c, d;- - if (view_zoom > 1) { - a = vertical_help_lines.first ().data.get_coordinate ();- c = horizontal_help_lines.first ().data.get_coordinate ();- - b = vertical_help_lines.first ().data.get_coordinate ();- d = horizontal_help_lines.first ().data.get_coordinate ();+ public void resized (WidgetAllocation alloc) {+ double a, b, c, d, e;++ a = Glyph.path_coordinate_x (0);+ b = Glyph.path_coordinate_y (0); - view_offset_x -= a - b;- view_offset_y -= c - d;- }+ this.allocation = alloc;++ c = Glyph.path_coordinate_x (0);+ d = Glyph.path_coordinate_y (0);++ view_offset_x -= c - a;+ view_offset_y -= b - d; } public void set_background_image (GlyphBackgroundImage? b) {@@ -1392,7 +1392,7 @@ public class Glyph : FontDisplay { } } - public override void draw (Allocation allocation, Context cr) {+ public override void draw (WidgetAllocation allocation, Context cr) { Tool tool; this.allocation = allocation;@@ -1692,7 +1692,7 @@ public class Glyph : FontDisplay { return false; } - public void juxtapose (Allocation allocation, Context cr) {+ public void juxtapose (WidgetAllocation allocation, Context cr) { string glyph_sequence = Preferences.get ("glyph_sequence"); unichar c; Font font = BirdFont.get_current_font ();@@ -269,7 +269,7 @@ public class GlyphBackgroundImage { img_offset_y = g.get_line ("top").pos; } - public void draw (Context cr, Allocation allocation, double view_offset_x, double view_offset_y, double view_zoom) {+ public void draw (Context cr, WidgetAllocation allocation, double view_offset_x, double view_offset_y, double view_zoom) { double x, y; double iw, ih; int h, w;@@ -24,11 +24,15 @@ public class GlyphCanvas : GLib.Object { public FontDisplay current_display; public signal void signal_redraw_area (int x, int y, int w, int h); - public Allocation allocation; + public static WidgetAllocation allocation = new WidgetAllocation (); public GlyphCanvas () { } - + + public static void set_allocation (WidgetAllocation w) { + allocation = w.copy (); + } + public void key_release (uint e) { current_display.key_release (e); } @@ -42,9 +46,7 @@ public class GlyphCanvas : GLib.Object { Glyph g = (Glyph) fd; BirdFont.current_glyph = g; - BirdFont.current_glyph.resized (); - - g.allocation = allocation; + BirdFont.current_glyph.resized (allocation); if (g.allocation.width == 0 || g.allocation.height == 0) { warning ("area is zero in glyph canvas"); @@ -38,7 +38,7 @@ public class KerningDisplay : FontDisplay { return "Kerning"; } - public override void draw (Allocation allocation, Context cr) {+ public override void draw (WidgetAllocation allocation, Context cr) { Glyph glyph; double x, y, w, kern, alpha; double x2;@@ -123,12 +123,12 @@ public class Line : GLib.Object { } } - public void move_line_to (double x, double y, Allocation allocation) {+ public void move_line_to (double x, double y, WidgetAllocation allocation) { set_move (true); event_move_to (x, y, allocation); } - public bool event_move_to (double x, double y, Allocation allocation) {+ public bool event_move_to (double x, double y, WidgetAllocation allocation) { double p, c; bool a = false; Glyph g = MainWindow.get_current_glyph ();@@ -239,7 +239,7 @@ public class Line : GLib.Object { return (get_active ()) ? (10 * ivz) : (5 * ivz); } - public void draw (Context cr, Allocation allocation) {+ public void draw (Context cr, WidgetAllocation allocation) { Glyph g = MainWindow.get_current_glyph (); double p, h, w;@@ -18,7 +18,7 @@ namespace BirdFont { /** A display with all glyphs present in this font. */ public class OverView : FontDisplay {- public Allocation allocation;+ public WidgetAllocation allocation = new WidgetAllocation (); int selected = 0; int first_visible = 0;@@ -288,7 +288,7 @@ public class OverView : FontDisplay { } } - public override void draw (Allocation allocation, Context cr) {+ public override void draw (WidgetAllocation allocation, Context cr) { this.allocation = allocation; update_item_list ();@@ -314,7 +314,7 @@ public class OverView : FontDisplay { } } - void draw_empty_canvas (Allocation allocation, Context cr) {+ void draw_empty_canvas (WidgetAllocation allocation, Context cr) { cr.save (); cr.set_source_rgba (156/255.0, 156/255.0, 156/255.0, 1); cr.move_to (30, 40);@@ -777,7 +777,7 @@ public class OverView : FontDisplay { int len = 0; int length = 0; bool see_also = false;- Allocation allocation = MainWindow.get_overview ().allocation;+ WidgetAllocation allocation = MainWindow.get_overview ().allocation; entry = ((!)character_info).get_entry (); @@ -114,7 +114,7 @@ public class Path { return points.length () == 0; } - public void draw_outline (Context cr, Allocation allocation, double view_zoom) {+ public void draw_outline (Context cr, WidgetAllocation allocation, double view_zoom) { unowned List<EditPoint> ep = points; unowned EditPoint? n = null;@@ -147,7 +147,7 @@ public class Path { cr.stroke (); } - public void draw_edit_points (Context cr, Allocation allocation, double view_zoom) {+ public void draw_edit_points (Context cr, WidgetAllocation allocation, double view_zoom) { unowned List<EditPoint> ep = points; if (is_editable ()) {@@ -164,7 +164,7 @@ public class Path { } } - public void fill_path (Context cr, Allocation allocation, double view_zoom) {+ public void fill_path (Context cr, WidgetAllocation allocation, double view_zoom) { unowned List<EditPoint> ep = points; unowned EditPoint? n = null;@@ -1487,7 +1487,7 @@ public class Path { a1 = d1; } - public void plot (Context cr, Allocation allocation, double view_zoom) {+ public void plot (Context cr, WidgetAllocation allocation, double view_zoom) { double px = 0, py = 0; double xc = allocation.width / 2.0; double yc = allocation.height / 2.0;@@ -93,7 +93,7 @@ public class TooltipArea : GLib.Object { } - public void draw (Context cr, Allocation alloc) {+ public void draw (Context cr, WidgetAllocation alloc) { int w; cr.save ();@@ -18,9 +18,9 @@ class ZoomView : GLib.Object { public double x; public double y; public double zoom;- public Allocation allocation;+ public WidgetAllocation allocation; - public ZoomView (double x, double y, double zoom, Allocation allocation) {+ public ZoomView (double x, double y, double zoom, WidgetAllocation allocation) { this.x = x; this.y = y; this.zoom = zoom;