[f-spot: 9/41] some drawing stuffs



commit d6d361d10605a39c006a882702c0c92d6ea367fb
Author: Stephane Delcroix <stephane delcroix org>
Date:   Mon Jun 8 16:42:44 2009 +0200

    some drawing stuffs

 src/Makefile.am          |    2 +-
 src/Widgets/ImageView.cs |   78 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 75 insertions(+), 5 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index acb1395..6d9d4aa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -460,7 +460,7 @@ FSpot.JobScheduler.dll: $(JOBSCHEDULER_CSFILES) FSpot.Utils.dll
 
 FSpot.Widgets.dll: $(WIDGETS_CSFILES) FSpot.Utils.dll FSpot.Core.dll
 	@echo -e "\n*** Compiling $@"
-	$(CSC_LIB) -out:$@ $(EXTRAFLAGS) $(WIDGETS_CSFILES) $(WIDGETS_ASSEMBLIES)
+	$(CSC_LIB) -out:$@ -unsafe $(EXTRAFLAGS) $(WIDGETS_CSFILES) $(WIDGETS_ASSEMBLIES)
 
 PLATFORM_CSFILES = $(GNOME_PLATFORM_CSFILES)
 PLATFORM_ASSEMBLIES = $(GNOME_PLATFORM_ASSEMBLIES)
diff --git a/src/Widgets/ImageView.cs b/src/Widgets/ImageView.cs
index a79643d..fa7381d 100644
--- a/src/Widgets/ImageView.cs
+++ b/src/Widgets/ImageView.cs
@@ -79,9 +79,15 @@ namespace FSpot.Widgets
 			set { transform = value;} 
 		}
 
+		InterpType interpolation = InterpType.Bilinear;
 		public Gdk.InterpType Interpolation {
-			get { throw new NotImplementedException ();} 
-			set { throw new NotImplementedException ();} 
+			get { return interpolation; } 
+			set { 
+				if (interpolation == value)
+					return;
+				interpolation = value;
+				QueueDraw ();
+			} 
 		}
 
 		double zoom;
@@ -207,6 +213,57 @@ namespace FSpot.Widgets
 		public event EventHandler ZoomChanged;
 		public event EventHandler SelectionChanged;
 
+		void PaintBackground (Rectangle rect)
+		{
+		}
+
+		unsafe void PaintRectangle (Rectangle area, InterpType interpolation)
+		{
+			int scaled_width, scaled_height;
+			if (Pixbuf != null) {
+				scaled_width = (int)Math.Floor (Pixbuf.Width * Zoom + .5);
+				scaled_height = (int)Math.Floor (Pixbuf.Height * Zoom + .5);
+			} else {
+				scaled_width = scaled_height = 0;
+			}
+
+			int x_offset = (Allocation.Width - scaled_width) / 2;
+			int y_offset = (Allocation.Height - scaled_height) / 2;
+
+			//Draw background
+			if (y_offset > 0) 	//Top
+				PaintBackground (new Rectangle (0, 0, Allocation.Width, y_offset));
+			if (x_offset > 0) 	//Left
+				PaintBackground (new Rectangle (0, y_offset, x_offset, scaled_height));
+			if (x_offset >= 0)	//Right
+				PaintBackground (new Rectangle (x_offset + scaled_width, y_offset, Allocation.Width - x_offset - scaled_width, scaled_height));
+			if (y_offset >= 0)	//Bottom
+				PaintBackground (new Rectangle (0, y_offset + scaled_height, Allocation.Width, Allocation.Height - y_offset - scaled_height));
+
+			
+			area.Intersect (new Rectangle (x_offset, y_offset, scaled_width, scaled_height));
+
+			//Short circuit
+//			if (zoom == 1.0 &&
+//			    Pixbuf != null &&
+//			    !Pixbuf.HasAlpha &&
+//			    Pixbuf.BitsPerSample == 8) {
+			if (Pixbuf != null) {
+				byte* pixels = (byte*)Pixbuf.Pixels;
+				this.GetWindow().DrawRgbImageDithalign (Style.BlackGC,
+							      area.X,
+							      area.Y,
+							      area.Width,
+							      area.Height,
+							      RgbDither.Max,
+							      pixels,
+							      Pixbuf.Rowstride,
+							      area.X - x_offset,
+							      area.Y - y_offset);
+			}
+
+		}
+
 		protected override bool OnExposeEvent (EventExpose evnt)
 		{
 			Console.WriteLine ("ImageView OnExposeEvent");
@@ -214,9 +271,22 @@ namespace FSpot.Widgets
 			if (evnt == null)
 				return true;
 
-			foreach (Rectangle rect in evnt.Region.GetRectangles ())
+			foreach (Rectangle area in evnt.Region.GetRectangles ())
 			{
-				Console.WriteLine ("drawing a rect");
+				area.Intersect (Allocation);
+				if (area == Rectangle.Zero)
+					continue;
+
+				//draw synchronously if InterpType.Nearest or zoom 1:1
+				if (Interpolation == InterpType.Nearest || zoom == 1.0) {
+					PaintRectangle (area, Interpolation);
+					continue;
+				}
+				
+				//delay all other interpolation types
+//				GLib.Idle.Add (...);
+
+				PaintRectangle (area, InterpType.Nearest);
 			}
 			return true;
 		}



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