[f-spot] Revert commits 74d4e4..83290d



commit 1e31166dded91d01f561f5253f6633f8bf38e5ea
Author: Stephane Delcroix <stephane delcroix org>
Date:   Fri Sep 11 10:19:46 2009 +0200

    Revert commits 74d4e4..83290d
    
    The new behavior is broken, was reported as such, and still waits for a fix.
    In the meantime, I'm reverting as it's annoying.
    
    Revert "Keep the current offsets when a higher quality image gets loaded."
    This reverts commit 83290d9488b1abdd33e03cd0e0e6c8335f870eef.
    
    Revert "Preserve the visual size of things when changing image."
    This reverts commit 1c347ea470123bcae3c25ed1c9cc019e36608a08.
    
    Revert "No need to compute the minimum zoom every time."
    This reverts commit 8b1bcf90b3d331b03624eb6859ef23c214aeb4af.
    
    Revert "Change upscale to a property such that it shouldn't be passed to ZoomFit."
    This reverts commit 808007a2624613d38e3966eb23efb177babf3694.
    
    Revert "Change ComputeMinZoom to void."
    This reverts commit f71bae535905d294b8138f5d7f0c5d099ea433a0.
    
    Revert "Stop zooming to fit whenever a new pixbuf is pushed in."
    This reverts commit 98d84032913a0800e9d0d31712b94499c168167e.
    
    Revert "Refactor image changing API in ImageView."
    This reverts commit 74d4e4ae6168ad509807220583d865aabda07486.

 src/Editors/Editor.cs    |    6 +-
 src/ImportCommand.cs     |    3 +-
 src/PhotoImageView.cs    |   36 +++++++-----
 src/Utils/PixbufUtils.cs |    5 --
 src/Widgets/ImageView.cs |  144 ++++++++++++++++++++--------------------------
 5 files changed, 89 insertions(+), 105 deletions(-)
---
diff --git a/src/Editors/Editor.cs b/src/Editors/Editor.cs
index b14e01e..9542419 100644
--- a/src/Editors/Editor.cs
+++ b/src/Editors/Editor.cs
@@ -203,7 +203,8 @@ namespace FSpot.Editors {
 			}
 
 			Pixbuf previewed = ProcessFast (preview, null);
-			State.PhotoImageView.ChangeImage (previewed, State.PhotoImageView.PixbufOrientation, false, false);
+			State.PhotoImageView.Pixbuf = previewed;
+			State.PhotoImageView.ZoomFit (false);
 			MainWindow.Toplevel.InfoBox.UpdateHistogram (previewed);
 
 			if (old_preview != null) {
@@ -234,7 +235,8 @@ namespace FSpot.Editors {
 
 		public void Restore () {
 			if (original != null && State.PhotoImageView != null) {
-				State.PhotoImageView.ChangeImage (original, state.PhotoImageView.PixbufOrientation, false, false);
+				State.PhotoImageView.Pixbuf = original;
+				State.PhotoImageView.ZoomFit (false);
 
 				MainWindow.Toplevel.InfoBox.UpdateHistogram (null);
 			}
diff --git a/src/ImportCommand.cs b/src/ImportCommand.cs
index 74b747e..47f84a6 100644
--- a/src/ImportCommand.cs
+++ b/src/ImportCommand.cs
@@ -638,7 +638,8 @@ public class ImportCommand : GladeDialog
 		GtkUtil.ModifyColors (photo_scrolled);
 		GtkUtil.ModifyColors (photo_view);
 
-		photo_view.ChangeImage (GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "f-spot", 128, (Gtk.IconLookupFlags)0), PixbufOrientation.TopLeft, true, false);
+		photo_view.Pixbuf = GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "f-spot", 128, (Gtk.IconLookupFlags)0);
+		photo_view.ZoomFit (false);
 			
 		tag_entry = new FSpot.Widgets.TagEntry (MainWindow.Toplevel.Database.Tags, false);
 		tag_entry.UpdateFromTagNames (new string []{});
diff --git a/src/PhotoImageView.cs b/src/PhotoImageView.cs
index 75d5174..84d48b2 100644
--- a/src/PhotoImageView.cs
+++ b/src/PhotoImageView.cs
@@ -195,15 +195,12 @@ namespace FSpot.Widgets {
 #region loader		
 		uint timer;
 		IImageLoader loader;
-		bool prepared_is_new;
-
 		void Load (Uri uri)
 		{
 			timer = Log.DebugTimerStart ();
 			if (loader != null)
 				loader.Dispose ();
 
-			prepared_is_new = true;
 			loader = ImageLoader.Create (uri);
 			loader.AreaPrepared += HandlePixbufPrepared;
 			loader.AreaUpdated += HandlePixbufAreaUpdated;
@@ -220,13 +217,13 @@ namespace FSpot.Widgets {
 			if (!ShowProgress)
 				return;
 
-			Gdk.Pixbuf prev = Pixbuf;
-			PixbufOrientation orientation = Accelerometer.GetViewOrientation (loader.PixbufOrientation);
-			ChangeImage (loader.Pixbuf, orientation, prepared_is_new, args.ReducedResolution);
-			prepared_is_new = false;
-
+			Gdk.Pixbuf prev = this.Pixbuf;
+			this.Pixbuf = loader.Pixbuf;
+			PixbufOrientation = Accelerometer.GetViewOrientation (loader.PixbufOrientation);
 			if (prev != null)
 				prev.Dispose ();
+
+			this.ZoomFit (args.ReducedResolution);
 		}
 
 		void HandlePixbufAreaUpdated (object sender, AreaUpdatedEventArgs args)
@@ -251,7 +248,7 @@ namespace FSpot.Widgets {
 
 			Pixbuf prev = this.Pixbuf;
 			if (Pixbuf != loader.Pixbuf)
-				ChangeImage (loader.Pixbuf, Accelerometer.GetViewOrientation (loader.PixbufOrientation), false, false);
+				Pixbuf = loader.Pixbuf;
 
 			if (Pixbuf == null) {
 				// FIXME: Do we have test cases for this ???
@@ -261,14 +258,21 @@ namespace FSpot.Widgets {
 				// than try to load the image one last time.
 				try {
 					Log.Warning ("Falling back to file loader");
-					ChangeImage (PhotoLoader.Load (item.Collection, item.Index), PixbufOrientation.TopLeft, true, false);
+					Pixbuf = PhotoLoader.Load (item.Collection, item.Index);
 				} catch (Exception e) {
 					LoadErrorImage (e);
 				}
 			}
 
+			if (loader.Pixbuf != null) //FIXME: this test in case the photo was loaded with the direct loader
+				PixbufOrientation = Accelerometer.GetViewOrientation (loader.PixbufOrientation);
+			else
+				PixbufOrientation = PixbufOrientation.TopLeft;
+
 			if (Pixbuf == null)
 				LoadErrorImage (null);
+			else
+				ZoomFit ();
 
 			progressive_display = true;
 
@@ -298,15 +302,17 @@ namespace FSpot.Widgets {
 			// like offer the user a chance to locate the moved file and
 			// update the db entry, but for now just set the error pixbuf	
 			Pixbuf old = Pixbuf;
-			Pixbuf err = new Pixbuf (PixbufUtils.ErrorPixbuf, 0, 0,
-									 PixbufUtils.ErrorPixbuf.Width,
-									 PixbufUtils.ErrorPixbuf.Height);
-			ChangeImage (err, PixbufOrientation.TopLeft, true, false);
+			Pixbuf = new Pixbuf (PixbufUtils.ErrorPixbuf, 0, 0, 
+					     PixbufUtils.ErrorPixbuf.Width, 
+					     PixbufUtils.ErrorPixbuf.Height);
 			if (old != null)
 				old.Dispose ();
+
+			PixbufOrientation = PixbufOrientation.TopLeft;
+			ZoomFit (false);
 		}
 
-		void HandlePhotoItemChanged (object sender, BrowsablePointerChangedEventArgs args)
+		void HandlePhotoItemChanged (object sender, BrowsablePointerChangedEventArgs args) 
 		{
 			// If it is just the position that changed fall out
 			if (args != null && 
diff --git a/src/Utils/PixbufUtils.cs b/src/Utils/PixbufUtils.cs
index c4d9bd8..68ff5d4 100644
--- a/src/Utils/PixbufUtils.cs
+++ b/src/Utils/PixbufUtils.cs
@@ -222,10 +222,5 @@ 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 c55e06b..0bf8c26 100644
--- a/src/Widgets/ImageView.cs
+++ b/src/Widgets/ImageView.cs
@@ -40,61 +40,38 @@ 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
-		// version).
-		public void ChangeImage (Pixbuf pixbuf, PixbufOrientation orientation, bool is_new, bool upscale)
-		{
-			if (Pixbuf == pixbuf)
-				return;
-
-			Pixbuf = pixbuf;
-			PixbufOrientation = orientation;
-			Upscale = upscale;
-
-			ComputeMinZoom ();
-			ComputeScaledSize ();
-
-			if (is_new) {
-				ZoomFit ();
-				ScrollTo (0, 0, true);
-				prev_width = PixbufUtils.UprightWidth (Pixbuf, PixbufOrientation);
-			} else {
-				// Recalculate the zoom and offset based on the new image size.
-				double ratio = (double) PixbufUtils.UprightWidth (Pixbuf, PixbufOrientation) /
-							   (double) prev_width;
-
-				int new_x = XOffset;
-				int new_y = YOffset;
-				Zoom /= ratio;
-				ScrollTo (new_x, new_y, true);
+		Pixbuf pixbuf;
+		public Pixbuf Pixbuf {
+			get { return pixbuf; } 
+			set {
+				if (pixbuf == value)
+					return;
 
-				prev_width = PixbufUtils.UprightWidth (Pixbuf, PixbufOrientation);
-			}
+				pixbuf = value;
+				min_zoom = ComputeMinZoom (upscale);
 
-			QueueDraw ();
+				ComputeScaledSize ();
+				AdjustmentsChanged -= ScrollToAdjustments;
+				Hadjustment.Value = Vadjustment.Value = 0;
+				XOffset = YOffset = 0;
+				AdjustmentsChanged += ScrollToAdjustments;
+				QueueDraw ();
+			} 
 		}
 
-		public void ChangeOrientation (PixbufOrientation orientation)
-		{
-			if (orientation == PixbufOrientation)
-				return;
-
-			PixbufOrientation = orientation;
-			ComputeMinZoom ();
-			ComputeScaledSize ();
-			QueueDraw ();
+		PixbufOrientation pixbuf_orientation;
+		public PixbufOrientation PixbufOrientation {
+			get { return pixbuf_orientation; }
+			set {
+				if (value == pixbuf_orientation)
+					return;
+				pixbuf_orientation = value;
+				min_zoom = ComputeMinZoom (upscale);
+				ComputeScaledSize ();
+				QueueDraw ();
+			}
 		}
 
-		public Pixbuf Pixbuf { get; private set; }
-
-		public PixbufOrientation PixbufOrientation { get; private set; }
-
 		CheckPattern check_pattern = CheckPattern.Dark;
 		public CheckPattern CheckPattern {
 			get { return check_pattern; } 
@@ -213,14 +190,18 @@ namespace FSpot.Widgets
 			get { return fit; } 
 		}
 
-		public void ZoomFit ()
+		public void ZoomFit (bool upscale)
 		{
 			Gtk.ScrolledWindow scrolled = Parent as Gtk.ScrolledWindow;
 			if (scrolled != null)
 				scrolled.SetPolicy (Gtk.PolicyType.Never, Gtk.PolicyType.Never);
+			
+			min_zoom = ComputeMinZoom (upscale);
+			
+			this.upscale = upscale;
 
 			fit = true;
-			Zoom = MIN_ZOOM;
+			DoZoom (MIN_ZOOM, false, 0, 0);
 
 			if (scrolled != null)
 				GLib.Idle.Add (delegate {scrolled.SetPolicy (Gtk.PolicyType.Automatic, Gtk.PolicyType.Automatic); return false;});
@@ -237,7 +218,7 @@ namespace FSpot.Widgets
 			win.X = Clamp (win.X - x_offset, 0, (int)scaled_width - 1);
 			win.Y = Clamp (win.Y - y_offset, 0, (int)scaled_height - 1);
 
-			win = PixbufUtils.TransformOrientation ((int)scaled_width, (int)scaled_height, win, PixbufUtils.ReverseTransformation (PixbufOrientation));
+			win = PixbufUtils.TransformOrientation ((int)scaled_width, (int)scaled_height, win, PixbufUtils.ReverseTransformation (pixbuf_orientation));
 
 			return  new Point ((int) Math.Floor (win.X * (double)(((int)PixbufOrientation <= 4 ? Pixbuf.Width : Pixbuf.Height) - 1) / (double)(scaled_width - 1) + .5),
 					   (int) Math.Floor (win.Y * (double)(((int)PixbufOrientation <= 4 ? Pixbuf.Height : Pixbuf.Width) - 1) / (double)(scaled_height - 1) + .5));
@@ -280,8 +261,11 @@ namespace FSpot.Widgets
 			get { return min_zoom; }
 		}
 
-
-		bool Upscale { get; set; }
+		bool upscale;
+		protected void ZoomFit ()
+		{
+			ZoomFit (upscale);
+		}
 
 		protected virtual void ApplyColorTransform (Pixbuf pixbuf)
 		{
@@ -292,12 +276,12 @@ namespace FSpot.Widgets
 			if (this.Pixbuf == null)
 				return Point.Zero;
 
-			image = PixbufUtils.TransformOrientation (Pixbuf.Width, Pixbuf.Height, image, PixbufOrientation);
+			image = PixbufUtils.TransformOrientation (Pixbuf.Width, Pixbuf.Height, image, pixbuf_orientation);
 			int x_offset = scaled_width < Allocation.Width ? (int)(Allocation.Width - scaled_width) / 2 : -XOffset;
 			int y_offset = scaled_height < Allocation.Height ? (int)(Allocation.Height - scaled_height) / 2 : -YOffset;
 
-			return new Point ((int) Math.Floor (image.X * (double) (scaled_width - 1) / (((int)PixbufOrientation <= 4 ? Pixbuf.Width : Pixbuf.Height) - 1) + 0.5) + x_offset,
-					  (int) Math.Floor (image.Y * (double) (scaled_height - 1) / (((int)PixbufOrientation <= 4 ? Pixbuf.Height : Pixbuf.Width) - 1) + 0.5) + y_offset);
+			return new Point ((int) Math.Floor (image.X * (double) (scaled_width - 1) / (((int)pixbuf_orientation <= 4 ? Pixbuf.Width : Pixbuf.Height) - 1) + 0.5) + x_offset,
+					  (int) Math.Floor (image.Y * (double) (scaled_height - 1) / (((int)pixbuf_orientation <= 4 ? Pixbuf.Height : Pixbuf.Width) - 1) + 0.5) + y_offset);
 		}
 
 		protected Rectangle ImageCoordsToWindow (Rectangle image)
@@ -305,15 +289,15 @@ namespace FSpot.Widgets
 			if (this.Pixbuf == null)
 				return Gdk.Rectangle.Zero;
 
-			image = PixbufUtils.TransformOrientation (Pixbuf.Width, Pixbuf.Height, image, PixbufOrientation);
+			image = PixbufUtils.TransformOrientation (Pixbuf.Width, Pixbuf.Height, image, pixbuf_orientation);
 			int x_offset = scaled_width < Allocation.Width ? (int)(Allocation.Width - scaled_width) / 2 : -XOffset;
 			int y_offset = scaled_height < Allocation.Height ? (int)(Allocation.Height - scaled_height) / 2 : -YOffset;
 
 			Gdk.Rectangle win = Gdk.Rectangle.Zero;
-			win.X = (int) Math.Floor (image.X * (double) (scaled_width - 1) / (((int)PixbufOrientation <= 4 ? Pixbuf.Width : Pixbuf.Height) - 1) + 0.5) + x_offset;
-			win.Y = (int) Math.Floor (image.Y * (double) (scaled_height - 1) / (((int)PixbufOrientation <= 4 ? Pixbuf.Height : Pixbuf.Width) - 1) + 0.5) + y_offset;
-			win.Width = (int) Math.Floor ((image.X + image.Width) * (double) (scaled_width - 1) / (((int)PixbufOrientation <= 4 ? Pixbuf.Width : Pixbuf.Height) - 1) + 0.5) - win.X + x_offset;
-			win.Height = (int) Math.Floor ((image.Y + image.Height) * (double) (scaled_height - 1) / (((int)PixbufOrientation <= 4 ? Pixbuf.Height : Pixbuf.Width) - 1) + 0.5) - win.Y + y_offset;
+			win.X = (int) Math.Floor (image.X * (double) (scaled_width - 1) / (((int)pixbuf_orientation <= 4 ? Pixbuf.Width : Pixbuf.Height) - 1) + 0.5) + x_offset;
+			win.Y = (int) Math.Floor (image.Y * (double) (scaled_height - 1) / (((int)pixbuf_orientation <= 4 ? Pixbuf.Height : Pixbuf.Width) - 1) + 0.5) + y_offset;
+			win.Width = (int) Math.Floor ((image.X + image.Width) * (double) (scaled_width - 1) / (((int)pixbuf_orientation <= 4 ? Pixbuf.Width : Pixbuf.Height) - 1) + 0.5) - win.X + x_offset;
+			win.Height = (int) Math.Floor ((image.Y + image.Height) * (double) (scaled_height - 1) / (((int)pixbuf_orientation <= 4 ? Pixbuf.Height : Pixbuf.Width) - 1) + 0.5) - win.Y + y_offset;
 
 			return win;
 		}
@@ -402,7 +386,7 @@ namespace FSpot.Widgets
 
 		protected override void OnSizeAllocated (Gdk.Rectangle allocation)
 		{
-			ComputeMinZoom ();
+			min_zoom = ComputeMinZoom (upscale);
 
 			if (fit || zoom < MIN_ZOOM)
 				zoom = MIN_ZOOM;
@@ -440,7 +424,7 @@ namespace FSpot.Widgets
 			base.OnSizeAllocated (allocation);
 
 			if (fit)
-				ZoomFit ();
+				ZoomFit (upscale);
 		}
 
 		protected override bool OnExposeEvent (Gdk.EventExpose evnt)
@@ -721,7 +705,7 @@ namespace FSpot.Widgets
 			if (zoom == 1.0 &&
 			    !Pixbuf.HasAlpha &&
 			    Pixbuf.BitsPerSample == 8 &&
-			    PixbufOrientation == PixbufOrientation.TopLeft) {
+			    pixbuf_orientation == PixbufOrientation.TopLeft) {
 				GdkWindow.DrawPixbuf (Style.BlackGC,
 						      Pixbuf,
 						      area.X - x_offset, area.Y - y_offset,
@@ -738,7 +722,7 @@ namespace FSpot.Widgets
 												 (area.Y - y_offset),
 												 area.Width,
 												 area.Height),
-										  PixbufUtils.ReverseTransformation (PixbufOrientation));
+										  PixbufUtils.ReverseTransformation (pixbuf_orientation));
 			using (Pixbuf temp_pixbuf = new Pixbuf (Colorspace.Rgb, false, 8, pixbuf_area.Width, pixbuf_area.Height)) {
 				if (Pixbuf.HasAlpha)
 					temp_pixbuf.Fill (0x00000000);
@@ -755,7 +739,7 @@ namespace FSpot.Widgets
 
 				ApplyColorTransform (temp_pixbuf);
 
-				using (var dest_pixbuf = PixbufUtils.TransformOrientation (temp_pixbuf, PixbufOrientation)) {
+				using (var dest_pixbuf = PixbufUtils.TransformOrientation (temp_pixbuf, pixbuf_orientation)) {
 					GdkWindow.DrawPixbuf (Style.BlackGC,
 							      dest_pixbuf,
 							      0, 0,
@@ -775,7 +759,7 @@ namespace FSpot.Widgets
 			else {
 				double width;
 				double height;
-				if ((int)PixbufOrientation <= 4 ) { //TopLeft, TopRight, BottomRight, BottomLeft
+				if ((int)pixbuf_orientation <= 4 ) { //TopLeft, TopRight, BottomRight, BottomLeft
 					width = Pixbuf.Width;
 					height = Pixbuf.Height;
 				} else {			//LeftTop, RightTop, RightBottom, LeftBottom
@@ -836,30 +820,26 @@ namespace FSpot.Widgets
 			return Math.Min (Math.Max (value, min), max);
 		}
 
-		void ComputeMinZoom ()
+		double ComputeMinZoom (bool upscale)
 		{
-			if (Pixbuf == null) {
-				min_zoom = 0.1;
-				return;
-			}
+			if (Pixbuf == null)
+				return 0.1;
 
 			double width;
 			double height;
-			if ((int)PixbufOrientation <= 4 ) { //TopLeft, TopRight, BottomRight, BottomLeft
+			if ((int)pixbuf_orientation <= 4 ) { //TopLeft, TopRight, BottomRight, BottomLeft
 				width = Pixbuf.Width;
 				height = Pixbuf.Height;
 			} else {			//LeftTop, RightTop, RightBottom, LeftBottom
 				width = Pixbuf.Height;
 				height = Pixbuf.Width;
 			}
-
-			if (Upscale)
-				min_zoom = Math.Min ((double)Allocation.Width / width,
-									 (double)Allocation.Height / height);
-			else
-				min_zoom = Math.Min (1.0,
-									 Math.Min ((double)Allocation.Width / width,
-											   (double)Allocation.Height / height));
+			if (upscale)
+				return Math.Min ((double)Allocation.Width / width,
+						 (double)Allocation.Height / height);
+			return Math.Min (1.0,
+					 Math.Min ((double)Allocation.Width / width,
+						   (double)Allocation.Height / height));
 		}
 #endregion
 



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