Browse Source

Added images and clipping to cairo renderer.

pull/10/head
Steven Kirk 11 years ago
parent
commit
6f363de0e6
  1. 24
      Cairo/Perspex.Cairo/CairoExtensions.cs
  2. 31
      Cairo/Perspex.Cairo/Media/DrawingContext.cs
  3. 79
      Cairo/Perspex.Cairo/Media/Imaging/BitmapImpl.cs
  4. 1
      Cairo/Perspex.Cairo/Perspex.Cairo.csproj

24
Cairo/Perspex.Cairo/CairoExtensions.cs

@ -0,0 +1,24 @@
// -----------------------------------------------------------------------
// <copyright file="CairoPlatform.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Cairo
{
using Cairo = global::Cairo;
public static class CairoExtensions
{
public static Cairo.Matrix ToCairo(this Matrix m)
{
return new Cairo.Matrix(m.M11, m.M12, m.M21, m.M22, m.OffsetX, m.OffsetY);
}
public static Cairo.Rectangle ToCairo(this Rect rect)
{
return new Cairo.Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
}
}
}

31
Cairo/Perspex.Cairo/Media/DrawingContext.cs

@ -3,6 +3,7 @@
// Copyright 2013 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
using Perspex.Cairo.Media.Imaging;
namespace Perspex.Cairo.Media
{
@ -83,7 +84,10 @@ namespace Perspex.Cairo.Media
public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect)
{
throw new NotImplementedException();
var impl = bitmap.PlatformImpl as BitmapImpl;
this.context.SetSourceSurface(impl.Surface, 0, 0);
this.context.Rectangle(destRect.ToCairo());
this.context.Fill();
}
/// <summary>
@ -116,7 +120,7 @@ namespace Perspex.Cairo.Media
public void DrawRectange(Pen pen, Rect rect)
{
this.SetPen(pen);
this.context.Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
this.context.Rectangle(rect.ToCairo());
this.context.Stroke();
}
@ -142,7 +146,7 @@ namespace Perspex.Cairo.Media
public void FillRectange(Perspex.Media.Brush brush, Rect rect)
{
this.SetBrush(brush);
this.context.Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
this.context.Rectangle(rect.ToCairo());
this.context.Fill();
}
@ -153,7 +157,11 @@ namespace Perspex.Cairo.Media
/// <returns>A disposable used to undo the clip rectangle.</returns>
public IDisposable PushClip(Rect clip)
{
return Disposable.Empty;
this.context.Save();
this.context.Rectangle(clip.ToCairo());
this.context.Clip();
return Disposable.Create(() => this.context.Restore());
}
/// <summary>
@ -163,19 +171,10 @@ namespace Perspex.Cairo.Media
/// <returns>A disposable used to undo the transformation.</returns>
public IDisposable PushTransform(Matrix matrix)
{
var m = Convert(matrix);
this.context.Transform(m);
this.context.Save();
this.context.Transform(matrix.ToCairo());
return Disposable.Create(() =>
{
m.Invert();
this.context.Transform(m);
});
}
private static Cairo.Matrix Convert(Matrix m)
{
return new Cairo.Matrix(m.M11, m.M12, m.M21, m.M22, m.OffsetX, m.OffsetY);
return Disposable.Create(() => this.context.Restore());
}
private void SetBrush(Brush brush)

79
Cairo/Perspex.Cairo/Media/Imaging/BitmapImpl.cs

@ -1,37 +1,42 @@
// -----------------------------------------------------------------------
// <copyright file="BitmapImpl.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Cairo.Media.Imaging
{
using System;
using global::Cairo;
using Perspex.Platform;
public class BitmapImpl : IBitmapImpl
{
private ImageSurface surface;
public BitmapImpl(ImageSurface surface)
{
this.surface = surface;
}
public int PixelWidth
{
get { return this.surface.Width; }
}
public int PixelHeight
{
get { return this.surface.Height; }
}
public void Save(string fileName)
{
throw new NotImplementedException();
}
}
}
// -----------------------------------------------------------------------
// <copyright file="BitmapImpl.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Cairo.Media.Imaging
{
using System;
using Perspex.Platform;
using Cairo = global::Cairo;
public class BitmapImpl : IBitmapImpl
{
public BitmapImpl(Cairo.ImageSurface surface)
{
this.Surface = surface;
}
public int PixelWidth
{
get { return this.Surface.Width; }
}
public int PixelHeight
{
get { return this.Surface.Height; }
}
public Cairo.ImageSurface Surface
{
get;
private set;
}
public void Save(string fileName)
{
throw new NotImplementedException();
}
}
}

1
Cairo/Perspex.Cairo/Perspex.Cairo.csproj

@ -70,6 +70,7 @@
<Compile Include="Media\TextService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Renderer.cs" />
<Compile Include="CairoExtensions.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Perspex.Base\Perspex.Base.csproj">

Loading…
Cancel
Save