[f-spot] Preserve the visual size of things when changing image.



commit 1c347ea470123bcae3c25ed1c9cc019e36608a08
Author: Ruben Vermeersch <ruben savanne be>
Date:   Thu Jul 23 20:42:21 2009 +0200

    Preserve the visual size of things when changing image.
    
    Makes sure that things continue to look as big as they used to look
    after a higher resolution version is loaded.

 src/Utils/PixbufUtils.cs |    5 +++++
 src/Widgets/ImageView.cs |   16 +++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/src/Utils/PixbufUtils.cs b/src/Utils/PixbufUtils.cs
index 68ff5d4..c4d9bd8 100644
--- a/src/Utils/PixbufUtils.cs
+++ b/src/Utils/PixbufUtils.cs
@@ -222,5 +222,10 @@ namespace FSpot.Utils
 				PixbufUtils.SetOption (dest, "tEXt::Thumb::MTime", src.GetOption ("tEXt::Thumb::MTime"));
 			}
 		}
+
+		public static int UprightWidth (Pixbuf src, PixbufOrientation orientation)
+		{
+			return (int)orientation <= 4 ? src.Width : src.Height;
+		}
 	}
 }
diff --git a/src/Widgets/ImageView.cs b/src/Widgets/ImageView.cs
index 7cea212..add9637 100644
--- a/src/Widgets/ImageView.cs
+++ b/src/Widgets/ImageView.cs
@@ -40,6 +40,10 @@ namespace FSpot.Widgets
 		{
 		}
 
+		// This value will be used to calculate the new zoom and offsets when
+		// the image is changed.
+		int prev_width;
+
 		// The is_new parameter denotes whether it's a newly loaded image
 		// (true, in that case the scrolling can be reset), or a new version of
 		// the currently loaded image (false, e.g. a higher resolution
@@ -49,8 +53,6 @@ namespace FSpot.Widgets
 			if (Pixbuf == pixbuf)
 				return;
 
-			Pixbuf prev = Pixbuf;
-
 			Pixbuf = pixbuf;
 			PixbufOrientation = orientation;
 			Upscale = upscale;
@@ -63,10 +65,18 @@ namespace FSpot.Widgets
 				Hadjustment.Value = Vadjustment.Value = 0;
 				XOffset = YOffset = 0;
 				AdjustmentsChanged += ScrollToAdjustments;
+				prev_width = PixbufUtils.UprightWidth (Pixbuf, PixbufOrientation);
 				ZoomFit ();
 			} else {
 				// TODO: Recalculate the adjustments and offsets such that the
 				// view on the image is maintained.
+
+				// Recalculate the zoom based on the new image size.
+				double ratio = (double) PixbufUtils.UprightWidth (Pixbuf, PixbufOrientation) /
+							   (double) prev_width;
+				Zoom /= ratio;
+
+				prev_width = PixbufUtils.UprightWidth (Pixbuf, PixbufOrientation);
 			}
 
 			QueueDraw ();
@@ -212,7 +222,7 @@ namespace FSpot.Widgets
 				scrolled.SetPolicy (Gtk.PolicyType.Never, Gtk.PolicyType.Never);
 
 			fit = true;
-			DoZoom (MIN_ZOOM, false, 0, 0);
+			Zoom = MIN_ZOOM;
 
 			if (scrolled != null)
 				GLib.Idle.Add (delegate {scrolled.SetPolicy (Gtk.PolicyType.Automatic, Gtk.PolicyType.Automatic); return false;});



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]