[f-spot: 13/41] drop UpdateMinZoom()



commit 1e96fbbbcab74fc3c966c927ed0d9748b05bc08c
Author: Stephane Delcroix <stephane delcroix org>
Date:   Tue Jun 9 10:18:29 2009 +0200

    drop UpdateMinZoom()
    
    the min zoom is now computed on set_Pixbuf or OnSizeAllocated ()

 src/PhotoImageView.cs    |    5 ---
 src/Widgets/ImageView.cs |   85 ++++++++++++++++++++++------------------------
 2 files changed, 41 insertions(+), 49 deletions(-)
---
diff --git a/src/PhotoImageView.cs b/src/PhotoImageView.cs
index 10beb7b..7f7d31a 100644
--- a/src/PhotoImageView.cs
+++ b/src/PhotoImageView.cs
@@ -149,7 +149,6 @@ namespace FSpot.Widgets {
 			if (prev != null)
 				prev.Dispose ();
 
-			UpdateMinZoom ();
 			this.ZoomFit (args.ReducedResolution);
 		}
 
@@ -182,14 +181,12 @@ namespace FSpot.Widgets {
 				if (this.Pixbuf == null) {
 					LoadErrorImage (ex);
 				} else {
-					UpdateMinZoom ();
 					this.ZoomFit ();
 				}
 			} else {
 				this.Pixbuf = loader.Pixbuf;
 
 				if (!loader.Prepared || !ShowProgress) {
-					UpdateMinZoom ();
 					this.ZoomFit ();
 				}
 			}
@@ -279,7 +276,6 @@ namespace FSpot.Widgets {
 			if (old != null)
 				old.Dispose ();
 			
-			UpdateMinZoom ();
 			this.ZoomFit ();
 		}
 
@@ -330,7 +326,6 @@ namespace FSpot.Widgets {
 				if (old != null)
 					old.Dispose ();
 
-				UpdateMinZoom ();
 				this.ZoomFit ();
 			}
 			
diff --git a/src/Widgets/ImageView.cs b/src/Widgets/ImageView.cs
index dbd0459..68c69d6 100644
--- a/src/Widgets/ImageView.cs
+++ b/src/Widgets/ImageView.cs
@@ -38,6 +38,14 @@ namespace FSpot.Widgets
 			get { return pixbuf; } 
 			set {
 				pixbuf = value;
+				if (pixbuf == null)
+					min_zoom = 0.1;
+				else {
+					min_zoom = Math.Min (1.0,
+						Math.Min ((double)Allocation.Width / (double)Pixbuf.Width,
+						(double)Allocation.Height / (double)Pixbuf.Height));
+				}
+
 				//scroll_to_view
 				QueueDraw ();
 			} 
@@ -100,6 +108,7 @@ namespace FSpot.Widgets
 				EventHandler eh = ZoomChanged;
 				if (eh != null)
 					eh (this, EventArgs.Empty);
+				QueueDraw ();
 			}
 		}
 
@@ -196,23 +205,6 @@ namespace FSpot.Widgets
 			Selection = Gdk.Rectangle.Zero;
 		}
 
-		[Obsolete ("drop this, this should be done automatically on pixbuf or allocation changed")]
-		protected void UpdateMinZoom ()
-		{
-			if (Pixbuf == null)
-				min_zoom = 0.1;
-			else {
-				min_zoom = Math.Min (1.0,
-					Math.Min ((double)Allocation.Width / (double)Pixbuf.Width,
-					(double)Allocation.Height / (double)Pixbuf.Height));
-			}
-
-			// Since this affects the zoom_scale we should alert it
-			EventHandler eh = ZoomChanged;
-			if (eh != null)
-				eh (this, System.EventArgs.Empty);
-		}
-
 		public event EventHandler ZoomChanged;
 		public event EventHandler SelectionChanged;
 
@@ -252,14 +244,11 @@ namespace FSpot.Widgets
 			if (zoom == 1.0) {
 				BinWindow.DrawPixbuf (Style.BlackGC,
 						      Pixbuf,
-						      area.X,
-						      area.Y,
-						      area.X,
-						      area.Y,
+						      area.X, area.Y,
+						      area.X, area.Y,
 						      area.Width, area.Height,
 						      RgbDither.Max,
-						      area.X - x_offset,
-						      area.Y - y_offset);
+						      area.X - x_offset, area.Y - y_offset);
 				return;
 			}
 
@@ -273,35 +262,43 @@ namespace FSpot.Widgets
 				int check_medium = 8;
 
 				Pixbuf.CompositeColor (temp_pixbuf,
-						       0,
-						       0,
-						       area.Width,
-						       area.Height,
-						       -(area.X - x_offset),
-						       -(area.Y - y_offset),
-						       zoom,
-						       zoom,
+						       0, 0,
+						       area.Width, area.Height,
+						       -(area.X - x_offset), -(area.Y - y_offset),
+						       zoom, zoom,
 						       zoom == 1.0 ? InterpType.Nearest : interpolation, 255,
-						       area.X - x_offset,
-						       area.Y - y_offset,
-						       check_medium,
-						       check_black,
-						       check_dark);
+						       area.X - x_offset, area.Y - y_offset,
+						       check_medium, check_black, check_dark);
 
 				BinWindow.DrawPixbuf (Style.BlackGC,
 						      temp_pixbuf,
-						      0,
-						      0,
-						      area.X,
-						      area.Y,
-						      area.Width,
-						      area.Height,
+						      0, 0,
+						      area.X, area.Y,
+						      area.Width, area.Height,
 						      RgbDither.Max,
-						      area.X - x_offset,
-						      area.Y - y_offset);
+						      area.X - x_offset, area.Y - y_offset);
 			}
 		}
 
+		protected override void OnSizeAllocated (Rectangle allocation)
+		{
+			if (Pixbuf == null)
+				min_zoom = 0.1;
+			else {
+				min_zoom = Math.Min (1.0,
+					Math.Min ((double)Allocation.Width / (double)Pixbuf.Width,
+					(double)Allocation.Height / (double)Pixbuf.Height));
+			}
+
+			if (zoom < min_zoom)
+				zoom = min_zoom;
+			// Since this affects the zoom_scale we should alert it
+			EventHandler eh = ZoomChanged;
+			if (eh != null)
+				eh (this, System.EventArgs.Empty);
+	
+		}
+
 		protected override bool OnExposeEvent (EventExpose evnt)
 		{
 			if (evnt == null)



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