Clone in a terminal:
Commit 3d8aadf
Johan Mattsson - 2013-07-27T12:34:22+00:00
3d8aadfe20a14125f3f8156c77bd818904fb43dajohan.mattsson.m@gmail.com

keep view after window is resized

Changed files (13)

Diff

diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex 2e70dbc..5f97b6d 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -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);diff --git a/libbirdfont/Allocation.vala b/libbirdfont/Allocation.valaindex 96433fa..3327d20 100644--- a/libbirdfont/Allocation.vala+++ b/libbirdfont/Allocation.vala@@ -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;+	} }  }diff --git a/libbirdfont/BackgroundSelection.vala b/libbirdfont/BackgroundSelection.valaindex 2d1cff8..5739533 100644--- a/libbirdfont/BackgroundSelection.vala+++ b/libbirdfont/BackgroundSelection.vala@@ -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;diff --git a/libbirdfont/FontDisplay.vala b/libbirdfont/FontDisplay.valaindex 5d50eab..eb3e770 100644--- a/libbirdfont/FontDisplay.vala+++ b/libbirdfont/FontDisplay.vala@@ -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 () {diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex 91e76b0..7d06f2f 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -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 ();diff --git a/libbirdfont/GlyphBackgroundImage.vala b/libbirdfont/GlyphBackgroundImage.valaindex 3eeeb2a..08b04d8 100644--- a/libbirdfont/GlyphBackgroundImage.vala+++ b/libbirdfont/GlyphBackgroundImage.vala@@ -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;diff --git a/libbirdfont/GlyphCanvas.vala b/libbirdfont/GlyphCanvas.valaindex a2cded1..5f0b5a4 100644--- a/libbirdfont/GlyphCanvas.vala+++ b/libbirdfont/GlyphCanvas.vala@@ -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");
diff --git a/libbirdfont/KerningDisplay.vala b/libbirdfont/KerningDisplay.valaindex fd1f7e7..cdeda38 100644--- a/libbirdfont/KerningDisplay.vala+++ b/libbirdfont/KerningDisplay.vala@@ -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;diff --git a/libbirdfont/Line.vala b/libbirdfont/Line.valaindex f9658c0..284e6fc 100644--- a/libbirdfont/Line.vala+++ b/libbirdfont/Line.vala@@ -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;diff --git a/libbirdfont/OverView.vala b/libbirdfont/OverView.valaindex 81b019c..7219714 100644--- a/libbirdfont/OverView.vala+++ b/libbirdfont/OverView.vala@@ -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 (); 		diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex fee18f2..2b0617e 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -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;diff --git a/libbirdfont/TooltipArea.vala b/libbirdfont/TooltipArea.valaindex e65f431..a1918d5 100644--- a/libbirdfont/TooltipArea.vala+++ b/libbirdfont/TooltipArea.vala@@ -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 ();diff --git a/libbirdfont/ZoomView.vala b/libbirdfont/ZoomView.valaindex 3c52c34..8dced87 100644--- a/libbirdfont/ZoomView.vala+++ b/libbirdfont/ZoomView.vala@@ -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;

Contact

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