[f-spot: 30/41] drop the old selection api



commit 070ff55db59b298764fc11105d1c88e68b480b57
Author: Stephane Delcroix <stephane delcroix org>
Date:   Thu Jun 11 15:05:23 2009 +0200

    drop the old selection api

 src/Editors/Editor.cs     |    1 +
 src/PhotoImageView.cs     |    2 +-
 src/TagCommands.cs        |   21 ++--
 src/Widgets/EditorPage.cs |    9 +-
 src/Widgets/ImageView.cs  |  391 ++++++++++++++++++++++-----------------------
 5 files changed, 213 insertions(+), 211 deletions(-)
---
diff --git a/src/Editors/Editor.cs b/src/Editors/Editor.cs
index 47a13c3..5e96edd 100644
--- a/src/Editors/Editor.cs
+++ b/src/Editors/Editor.cs
@@ -30,6 +30,7 @@ namespace FSpot.Editors {
 		}
 	}
 
+	[Obsolete ("use a Gdk.Rectangle")]
 	public class EditorSelection {
 		public int x, y;
 		public int width, height;
diff --git a/src/PhotoImageView.cs b/src/PhotoImageView.cs
index 2d9dd63..d2e9da7 100644
--- a/src/PhotoImageView.cs
+++ b/src/PhotoImageView.cs
@@ -324,7 +324,7 @@ namespace FSpot.Widgets {
 				this.ZoomFit ();
 			}
 			
-			this.UnsetSelection ();
+			Selection = Gdk.Rectangle.Zero;
 
 			if (PhotoChanged != null)
 				PhotoChanged (this);
diff --git a/src/TagCommands.cs b/src/TagCommands.cs
index c2a9cb5..743382c 100644
--- a/src/TagCommands.cs
+++ b/src/TagCommands.cs
@@ -416,23 +416,22 @@ public class TagCommands {
 
 		private void HandleSelectionChanged (object sender, EventArgs e)
 		{
-			int x, y, width, height;
-			Gdk.Pixbuf tmp = null;
+		       	int x = image_view.Selection.X;
+		       	int y = image_view.Selection.Y;
+			int width = image_view.Selection.Width;
+			int height = image_view.Selection.Height;
 		       
-			image_view.GetSelection (out x, out y, out width, out height);
 //			if (width > 0 && height > 0) 
 //				icon_view.Selection.Clear ();
 				
 			if (image_view.Pixbuf != null) {
 				if (width > 0 && height > 0) {
-					tmp = new Gdk.Pixbuf (image_view.Pixbuf, x, y, width, height);
-					
-					//FIXME
-					PreviewPixbuf = PixbufUtils.TagIconFromPixbuf (tmp);
-					PreviewPixbuf_WithoutProfile = PreviewPixbuf.Copy();
-					FSpot.ColorManagement.ApplyScreenProfile (PreviewPixbuf);
-					
-					tmp.Dispose ();
+					using (var tmp = new Gdk.Pixbuf (image_view.Pixbuf, x, y, width, height)) {	
+						//FIXME
+						PreviewPixbuf = PixbufUtils.TagIconFromPixbuf (tmp);
+						PreviewPixbuf_WithoutProfile = PreviewPixbuf.Copy();
+						FSpot.ColorManagement.ApplyScreenProfile (PreviewPixbuf);
+					}
 				} else {
 					//FIXME
 					PreviewPixbuf = PixbufUtils.TagIconFromPixbuf (image_view.Pixbuf);
diff --git a/src/Widgets/EditorPage.cs b/src/Widgets/EditorPage.cs
index 0ff435e..a732a3c 100644
--- a/src/Widgets/EditorPage.cs
+++ b/src/Widgets/EditorPage.cs
@@ -175,10 +175,13 @@ namespace FSpot.Widgets {
 			PhotoImageView photo_view = MainWindow.Toplevel.PhotoView.View;
 
 			if (Page.InPhotoView && photo_view != null) {
-				if (photo_view.GetSelection (out selection.x, out selection.y,
-							out selection.width, out selection.height))
+				if (photo_view.Selection != Gdk.Rectangle.Zero) {
+					selection.x = photo_view.Selection.X;
+					selection.y = photo_view.Selection.Y;
+					selection.width = photo_view.Selection.Width;
+					selection.height = photo_view.Selection.Height;
 					state.Selection = selection;
-				else
+				} else
 					state.Selection = null;
 				state.PhotoImageView = photo_view;
 			} else {
diff --git a/src/Widgets/ImageView.cs b/src/Widgets/ImageView.cs
index 02615b6..91ae4cf 100644
--- a/src/Widgets/ImageView.cs
+++ b/src/Widgets/ImageView.cs
@@ -18,17 +18,6 @@ namespace FSpot.Widgets
 {
 	public class ImageView : Container
 	{
-		public static double ZOOM_FACTOR = 1.1;
-
-		protected double max_zoom = 10.0;
-		protected double MAX_ZOOM {
-			get { return max_zoom; }
-		}
-
-		protected double min_zoom = 0.1;
-		protected double MIN_ZOOM {
-			get { return min_zoom; }
-		}
 
 #region public API
 		public ImageView () : base ()
@@ -82,7 +71,6 @@ namespace FSpot.Widgets
 			get { return vadjustment; }
 		}
 
-
 		Gdk.Rectangle selection = Rectangle.Zero;
 		public Gdk.Rectangle Selection {
 			get { return selection; }
@@ -125,37 +113,12 @@ namespace FSpot.Widgets
 			get { return zoom; }
 			set { DoZoom (value, false, 0, 0); }
 		}
-#endregion
-
-		int XOffset { get; set;}
-		int YOffset { get; set;}
-
-		void DoZoom (double zoom, bool use_anchor, int x, int y)
-		{
-Console.WriteLine ("DoZoom {0} {1} {2} {3}", zoom, use_anchor, x, y);
-			if (zoom == this.zoom)
-				return;
-
-			if (zoom > MAX_ZOOM)
-				zoom = MAX_ZOOM;
-			else if (zoom < MIN_ZOOM)
-				zoom = MIN_ZOOM;
-
-			this.zoom = zoom;
-			ComputeScaledSize ();
-
-			EventHandler eh = ZoomChanged;
-			if (eh != null)
-				eh (this, EventArgs.Empty);
-
-			QueueDraw ();
-		}
 
 		public void ZoomAboutPoint (double zoom_increment, int x, int y)
 		{
 			DoZoom (zoom * zoom_increment, true, x, y);
-		}
-		
+		}	
+
 		public Gdk.Point WindowCoordsToImage (Point win)
 		{
 			throw new NotImplementedException ();
@@ -178,165 +141,47 @@ Console.WriteLine ("DoZoom {0} {1} {2} {3}", zoom, use_anchor, x, y);
 			return win;
 		}
 
-		[Obsolete ("use the Selection Property")]
-		public bool GetSelection (out int x, out int y, out int width, out int height)
-		{
-			if (selection == Rectangle.Zero) {
-				x = y = width = height = 0;
-				return false;
-			}
-
-			x = Selection.X;
-			y = Selection.Y;
-			width = Selection.Width;
-			height = Selection.Height;
-			return true;
-		}
-
-		[Obsolete ("set the Selection property to Gdk.Rectangle.Zero instead")]
-		public void UnsetSelection () 
-		{
-			Selection = Gdk.Rectangle.Zero;
-		}
-
 		public event EventHandler ZoomChanged;
 		public event EventHandler SelectionChanged;
+#endregion
 
-		void PaintBackground (Rectangle backgound, Rectangle area)
-		{
-		}
-
-		void PaintRectangle (Rectangle area, InterpType interpolation)
-		{
-Console.WriteLine ("PaintRectangle {0}", area);
-			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;
-			//Draw background
-			if (y_offset > 0) 	//Top
-				PaintBackground (new Rectangle (0, 0, Allocation.Width, y_offset), area);
-			if (x_offset > 0) 	//Left
-				PaintBackground (new Rectangle (0, y_offset, x_offset, (int)scaled_height), area);
-			if (x_offset >= 0)	//Right
-				PaintBackground (new Rectangle (x_offset + (int)scaled_width, y_offset, Allocation.Width - x_offset - (int)scaled_width, (int)scaled_height), area);
-			if (y_offset >= 0)	//Bottom
-				PaintBackground (new Rectangle (0, y_offset + (int)scaled_height, Allocation.Width, Allocation.Height - y_offset - (int)scaled_height), area);
-
-			if (Pixbuf == null)
-				return;
-
-			area.Intersect (new Rectangle (x_offset, y_offset, (int)scaled_width, (int)scaled_height));
-
-			//Short circuit for 1:1 zoom
-			if (zoom == 1.0 &&
-			    !Pixbuf.HasAlpha &&
-			    Pixbuf.BitsPerSample == 8) {
-				GdkWindow.DrawPixbuf (Style.BlackGC,
-						      Pixbuf,
-						      area.X - x_offset, area.Y - y_offset,
-						      area.X, area.Y,
-						      area.Width, area.Height,
-						      RgbDither.Max,
-						      area.X - x_offset, area.Y - y_offset);
-				return;
-			}
-
-			using (Pixbuf temp_pixbuf = new Pixbuf (Colorspace.Rgb, false, 8, area.Width, area.Height)) {
-				if (Pixbuf.HasAlpha)
-					temp_pixbuf.Fill (0x00000000);
-
-				Pixbuf.CompositeColor (temp_pixbuf,
-						       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,
-						       CheckPattern.CheckSize, CheckPattern.Color1, CheckPattern.Color2);
-
-				GdkWindow.DrawPixbuf (Style.BlackGC,
-						      temp_pixbuf,
-						      0, 0,
-						      area.X, area.Y,
-						      area.Width, area.Height,
-						      RgbDither.Max,
-						      area.X - x_offset, area.Y - y_offset);
-			}
-		}
-
-		bool dragging = false;
-		int draganchor_x = 0;
-		int draganchor_y = 0;
-		protected override bool OnButtonPressEvent (EventButton evnt)
-		{
-			Console.WriteLine ("OnButtonPressEvent {0}", evnt.Button);
-			if (!HasFocus)
-				GrabFocus ();
-
-			if (dragging)
-				return base.OnButtonPressEvent (evnt);
-
-			switch (evnt.Button) {
-			case 1:	
-				dragging = true;
-				draganchor_x = (int)evnt.X;
-				draganchor_y = (int)evnt.Y;
-
-				return true;
-			default:
-				break;
-			}
-
-			return base.OnButtonPressEvent (evnt);
+#region protectedAPI
+		protected static double ZOOM_FACTOR = 1.1;
+		protected double max_zoom = 10.0;
+		protected double MAX_ZOOM {
+			get { return max_zoom; }
 		}
 
-		protected override bool OnScrollEvent (EventScroll evnt)
-		{
-			if ((evnt.State & ModifierType.ShiftMask) == 0) {//no shift, let's zoom
-				ZoomAboutPoint ((evnt.Direction == ScrollDirection.Up || evnt.Direction == ScrollDirection.Right) ? ZOOM_FACTOR : 1.0 / ZOOM_FACTOR,
-						 (int)evnt.X, (int)evnt.Y);
-				return true;
-			}
-			return base.OnScrollEvent (evnt);
+		protected double min_zoom = 0.1;
+		protected double MIN_ZOOM {
+			get { return min_zoom; }
 		}
 
-		uint scaled_width, scaled_height;
-		void ComputeScaledSize ()
-		{
-			if (Pixbuf != null) {
-				scaled_width = (uint)Math.Floor (Pixbuf.Width * Zoom + .5);
-				scaled_height = (uint)Math.Floor (Pixbuf.Height * Zoom + .5);
-			} else {
-				scaled_width = scaled_height = 0;
-			}
+#endregion
 
-			Hadjustment.Value = scaled_width;
-			Vadjustment.Value = scaled_height;
-		}
-#region widgetry
+#region GtkWidgetry
 		protected override void OnRealized ()
 		{
-Console.WriteLine ("ImageView.OnRealized");
 			SetFlag (Gtk.WidgetFlags.Realized);
-
-			Gdk.WindowAttr attributes = new Gdk.WindowAttr {
-							     WindowType = Gdk.WindowType.Child,
-							     X = Allocation.X,
-							     Y = Allocation.Y,
-							     Width = Allocation.Width,
-							     Height = Allocation.Height,
-							     Wclass = Gdk.WindowClass.InputOutput,
-							     Visual = this.Visual,
-							     Colormap = this.Colormap,
-							     Mask = this.Events
-							     	  | EventMask.ExposureMask
-								  | EventMask.ButtonPressMask
-								  | EventMask.ButtonReleaseMask
-								  | EventMask.PointerMotionMask
-								  | EventMask.PointerMotionHintMask
-								  | EventMask.ScrollMask
-								  | EventMask.KeyPressMask };
-			GdkWindow = new Gdk.Window (ParentWindow, attributes, 
-						     Gdk.WindowAttributesType.X | Gdk.WindowAttributesType.Y | Gdk.WindowAttributesType.Visual | Gdk.WindowAttributesType.Colormap);
+			GdkWindow = new Gdk.Window (ParentWindow,
+						    new Gdk.WindowAttr { WindowType = Gdk.WindowType.Child,
+									 X = Allocation.X,
+									 Y = Allocation.Y,
+									 Width = Allocation.Width,
+									 Height = Allocation.Height,
+									 Wclass = Gdk.WindowClass.InputOutput,
+									 Visual = this.Visual,
+									 Colormap = this.Colormap,
+									 Mask = this.Events
+									      | EventMask.ExposureMask
+									      | EventMask.ButtonPressMask
+									      | EventMask.ButtonReleaseMask
+									      | EventMask.PointerMotionMask
+									      | EventMask.PointerMotionHintMask
+									      | EventMask.ScrollMask
+									      | EventMask.KeyPressMask },
+						     Gdk.WindowAttributesType.X | Gdk.WindowAttributesType.Y |
+						     Gdk.WindowAttributesType.Visual | Gdk.WindowAttributesType.Colormap);
 
 			GdkWindow.SetBackPixmap (null, false);
 			GdkWindow.UserData = Handle;
@@ -344,20 +189,17 @@ Console.WriteLine ("ImageView.OnRealized");
 			Style.Attach (GdkWindow);
 			Style.SetBackground (GdkWindow, Gtk.StateType.Normal);
 
-			foreach (var child in children) {
+			foreach (var child in children)
 				child.Widget.ParentWindow = GdkWindow;
-			}
-
 		}
 
 		protected override void OnMapped ()
 		{
 			SetFlag (Gtk.WidgetFlags.Mapped);
 
-			foreach (var child in children) {
+			foreach (var child in children)
 				if (child.Widget.Visible && !child.Widget.IsMapped)
 					child.Widget.Map ();
-			}
 			GdkWindow.Show ();
 		}
 
@@ -365,20 +207,18 @@ Console.WriteLine ("ImageView.OnRealized");
 		{
 			requisition.Width = requisition.Height = 0;
 
-			foreach (var child in children) {
+			foreach (var child in children)
 				child.Widget.SizeRequest ();
-			}
 		}
 
 		protected override void OnSizeAllocated (Gdk.Rectangle allocation)
 		{
 			if (Pixbuf == null)
 				min_zoom = 0.1;
-			else {
+			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;
@@ -462,6 +302,165 @@ Console.WriteLine ("\n\nLayout.OnSetScrollAdjustments");
 				HandleAdjustmentsValueChanged (this, EventArgs.Empty);
 		}	
 
+
+#endregion
+		int XOffset { get; set;}
+		int YOffset { get; set;}
+
+		void DoZoom (double zoom, bool use_anchor, int x, int y)
+		{
+Console.WriteLine ("DoZoom {0} {1} {2} {3}", zoom, use_anchor, x, y);
+			if (zoom == this.zoom)
+				return;
+
+			if (zoom > MAX_ZOOM)
+				zoom = MAX_ZOOM;
+			else if (zoom < MIN_ZOOM)
+				zoom = MIN_ZOOM;
+
+			this.zoom = zoom;
+			ComputeScaledSize ();
+
+			EventHandler eh = ZoomChanged;
+			if (eh != null)
+				eh (this, EventArgs.Empty);
+
+			QueueDraw ();
+		}
+
+	
+//		[Obsolete ("use the Selection Property")]
+//		public bool GetSelection (out int x, out int y, out int width, out int height)
+//		{
+//			if (selection == Rectangle.Zero) {
+//				x = y = width = height = 0;
+//				return false;
+//			}
+//
+//			x = Selection.X;
+//			y = Selection.Y;
+//			width = Selection.Width;
+//			height = Selection.Height;
+//			return true;
+//		}
+//
+//		[Obsolete ("set the Selection property to Gdk.Rectangle.Zero instead")]
+//		public void UnsetSelection () 
+//		{
+//			Selection = Gdk.Rectangle.Zero;
+//		}
+
+		void PaintBackground (Rectangle backgound, Rectangle area)
+		{
+		}
+
+		void PaintRectangle (Rectangle area, InterpType interpolation)
+		{
+Console.WriteLine ("PaintRectangle {0}", area);
+			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;
+			//Draw background
+			if (y_offset > 0) 	//Top
+				PaintBackground (new Rectangle (0, 0, Allocation.Width, y_offset), area);
+			if (x_offset > 0) 	//Left
+				PaintBackground (new Rectangle (0, y_offset, x_offset, (int)scaled_height), area);
+			if (x_offset >= 0)	//Right
+				PaintBackground (new Rectangle (x_offset + (int)scaled_width, y_offset, Allocation.Width - x_offset - (int)scaled_width, (int)scaled_height), area);
+			if (y_offset >= 0)	//Bottom
+				PaintBackground (new Rectangle (0, y_offset + (int)scaled_height, Allocation.Width, Allocation.Height - y_offset - (int)scaled_height), area);
+
+			if (Pixbuf == null)
+				return;
+
+			area.Intersect (new Rectangle (x_offset, y_offset, (int)scaled_width, (int)scaled_height));
+
+			//Short circuit for 1:1 zoom
+			if (zoom == 1.0 &&
+			    !Pixbuf.HasAlpha &&
+			    Pixbuf.BitsPerSample == 8) {
+				GdkWindow.DrawPixbuf (Style.BlackGC,
+						      Pixbuf,
+						      area.X - x_offset, area.Y - y_offset,
+						      area.X, area.Y,
+						      area.Width, area.Height,
+						      RgbDither.Max,
+						      area.X - x_offset, area.Y - y_offset);
+				return;
+			}
+
+			using (Pixbuf temp_pixbuf = new Pixbuf (Colorspace.Rgb, false, 8, area.Width, area.Height)) {
+				if (Pixbuf.HasAlpha)
+					temp_pixbuf.Fill (0x00000000);
+
+				Pixbuf.CompositeColor (temp_pixbuf,
+						       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,
+						       CheckPattern.CheckSize, CheckPattern.Color1, CheckPattern.Color2);
+
+				GdkWindow.DrawPixbuf (Style.BlackGC,
+						      temp_pixbuf,
+						      0, 0,
+						      area.X, area.Y,
+						      area.Width, area.Height,
+						      RgbDither.Max,
+						      area.X - x_offset, area.Y - y_offset);
+			}
+		}
+
+		bool dragging = false;
+		int draganchor_x = 0;
+		int draganchor_y = 0;
+		protected override bool OnButtonPressEvent (EventButton evnt)
+		{
+			Console.WriteLine ("OnButtonPressEvent {0}", evnt.Button);
+			if (!HasFocus)
+				GrabFocus ();
+
+			if (dragging)
+				return base.OnButtonPressEvent (evnt);
+
+			switch (evnt.Button) {
+			case 1:	
+				dragging = true;
+				draganchor_x = (int)evnt.X;
+				draganchor_y = (int)evnt.Y;
+
+				return true;
+			default:
+				break;
+			}
+
+			return base.OnButtonPressEvent (evnt);
+		}
+
+		protected override bool OnScrollEvent (EventScroll evnt)
+		{
+			if ((evnt.State & ModifierType.ShiftMask) == 0) {//no shift, let's zoom
+				ZoomAboutPoint ((evnt.Direction == ScrollDirection.Up || evnt.Direction == ScrollDirection.Right) ? ZOOM_FACTOR : 1.0 / ZOOM_FACTOR,
+						 (int)evnt.X, (int)evnt.Y);
+				return true;
+			}
+			return base.OnScrollEvent (evnt);
+		}
+
+		uint scaled_width, scaled_height;
+		void ComputeScaledSize ()
+		{
+			if (Pixbuf != null) {
+				scaled_width = (uint)Math.Floor (Pixbuf.Width * Zoom + .5);
+				scaled_height = (uint)Math.Floor (Pixbuf.Height * Zoom + .5);
+			} else {
+				scaled_width = scaled_height = 0;
+			}
+
+			Hadjustment.Value = scaled_width;
+			Vadjustment.Value = scaled_height;
+		}
+#region widgetry
 		void HandleAdjustmentsValueChanged (object sender, EventArgs e) {
 			Console.WriteLine ("Adjustment(s) value changed");
 		}



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