Browse Source

Fixed cairo image tests.

pull/141/head
Steven Kirk 11 years ago
parent
commit
0963f913f2
  1. 26
      src/Gtk/Perspex.Cairo/Media/DrawingContext.cs
  2. 24
      src/Perspex.SceneGraph/Rect.cs

26
src/Gtk/Perspex.Cairo/Media/DrawingContext.cs

@ -42,6 +42,9 @@ namespace Perspex.Cairo.Media
CurrentTransform = Matrix.Identity; CurrentTransform = Matrix.Identity;
} }
/// <summary>
/// Gets the current transform of the drawing context.
/// </summary>
public Matrix CurrentTransform public Matrix CurrentTransform
{ {
get; } get; }
@ -54,17 +57,30 @@ namespace Perspex.Cairo.Media
_context.Dispose(); _context.Dispose();
} }
/// <summary>
/// Draws a bitmap image.
/// </summary>
/// <param name="source">The bitmap image.</param>
/// <param name="opacity">The opacity to draw with.</param>
/// <param name="sourceRect">The rect in the image to draw.</param>
/// <param name="destRect">The rect in the output to draw to.</param>
public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect) public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect)
{ {
var impl = bitmap.PlatformImpl as BitmapImpl; var impl = bitmap.PlatformImpl as BitmapImpl;
var size = new Size(impl.PixelWidth, impl.PixelHeight); var size = new Size(impl.PixelWidth, impl.PixelHeight);
var scaleX = destRect.Size.Width / sourceRect.Size.Width; var scale = new Vector(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height);
var scaleY = destRect.Size.Height / sourceRect.Size.Height;
_context.Save(); _context.Save();
_context.Scale(scaleX, scaleY); _context.Scale(scale.X, scale.Y);
Gdk.CairoHelper.SetSourcePixbuf(_context, impl.Surface, (int)sourceRect.X, (int)sourceRect.Y); destRect /= scale;
_context.Rectangle(sourceRect.ToCairo());
Gdk.CairoHelper.SetSourcePixbuf(
_context,
impl.Surface,
-sourceRect.X + destRect.X,
-sourceRect.Y + destRect.Y);
_context.Rectangle(destRect.ToCairo());
_context.Fill(); _context.Fill();
_context.Restore(); _context.Restore();
} }

24
src/Perspex.SceneGraph/Rect.cs

@ -184,15 +184,11 @@ namespace Perspex
/// <returns>The scaled rectangle.</returns> /// <returns>The scaled rectangle.</returns>
public static Rect operator *(Rect rect, Vector scale) public static Rect operator *(Rect rect, Vector scale)
{ {
double centerX = rect._x + (rect._width / 2);
double centerY = rect._y + (rect._height / 2);
double width = rect._width * scale.X;
double height = rect._height * scale.Y;
return new Rect( return new Rect(
centerX - (width / 2), rect.X * scale.X,
centerY - (height / 2), rect.Y * scale.Y,
width, rect.Width * scale.X,
height); rect.Height * scale.Y);
} }
/// <summary> /// <summary>
@ -214,15 +210,11 @@ namespace Perspex
/// <returns>The scaled rectangle.</returns> /// <returns>The scaled rectangle.</returns>
public static Rect operator /(Rect rect, Vector scale) public static Rect operator /(Rect rect, Vector scale)
{ {
double centerX = rect._x + (rect._width / 2);
double centerY = rect._y + (rect._height / 2);
double width = rect._width / scale.X;
double height = rect._height / scale.Y;
return new Rect( return new Rect(
centerX - (width / 2), rect.X / scale.X,
centerY - (height / 2), rect.Y / scale.Y,
width, rect.Width / scale.X,
height); rect.Height / scale.Y);
} }
/// <summary> /// <summary>

Loading…
Cancel
Save