Browse Source

Make Perspex.Cairo compile again.

pull/10/head
Steven Kirk 12 years ago
parent
commit
775e516dee
  1. 2
      Cairo/Perspex.Cairo/CairoPlatform.cs
  2. 39
      Cairo/Perspex.Cairo/Renderer.cs

2
Cairo/Perspex.Cairo/CairoPlatform.cs

@ -38,7 +38,7 @@ namespace Perspex.Cairo
//return new BitmapImpl(imagingFactory, width, height); //return new BitmapImpl(imagingFactory, width, height);
} }
public IRenderer CreateRenderer(IntPtr handle, double width, double height) public IRenderer CreateRenderer(IPlatformHandle handle, double width, double height)
{ {
return new Renderer(handle, width, height); return new Renderer(handle, width, height);
} }

39
Cairo/Perspex.Cairo/Renderer.cs

@ -7,29 +7,31 @@
namespace Perspex.Cairo namespace Perspex.Cairo
{ {
using System; using System;
using Perspex.Platform;
using Splat;
using global::Cairo;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using global::Cairo;
using Perspex.Cairo.Media; using Perspex.Cairo.Media;
using Perspex.Platform;
using Matrix = Perspex.Matrix; using Matrix = Perspex.Matrix;
/// <summary>
/// A cairo renderer.
/// </summary>
public class Renderer : IRenderer public class Renderer : IRenderer
{ {
/// <summary> /// <summary>
/// The handle of the window to draw to. /// The handle of the window to draw to.
/// </summary> /// </summary>
private IntPtr hwnd; private IPlatformHandle handle;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Renderer"/> class. /// Initializes a new instance of the <see cref="Renderer"/> class.
/// </summary> /// </summary>
/// <param name="hwnd">The window handle.</param> /// <param name="handle">The window handle.</param>
/// <param name="width">The width of the window.</param> /// <param name="width">The width of the window.</param>
/// <param name="height">The height of the window.</param> /// <param name="height">The height of the window.</param>
public Renderer(IntPtr hwnd, double width, double height) public Renderer(IPlatformHandle handle, double width, double height)
{ {
this.hwnd = hwnd; this.handle = handle;
} }
/// <summary> /// <summary>
@ -38,7 +40,7 @@ namespace Perspex.Cairo
/// <param name="visual">The visual to render.</param> /// <param name="visual">The visual to render.</param>
public void Render(IVisual visual) public void Render(IVisual visual)
{ {
using (var surface = new Win32Surface(GetDC(this.hwnd))) using (var surface = CreateSurface(this.handle))
using (DrawingContext context = new DrawingContext(surface)) using (DrawingContext context = new DrawingContext(surface))
{ {
this.Render(visual, context); this.Render(visual, context);
@ -52,11 +54,32 @@ namespace Perspex.Cairo
/// <param name="height">The new height.</param> /// <param name="height">The new height.</param>
public void Resize(int width, int height) public void Resize(int width, int height)
{ {
// Don't need to do anything here as we create a new Win32Surface on each render.
} }
[DllImport("user32.dll")] [DllImport("user32.dll")]
private static extern IntPtr GetDC(IntPtr hWnd); private static extern IntPtr GetDC(IntPtr hWnd);
/// <summary>
/// Creates a cairo surface that targets a platform-specific resource.
/// </summary>
/// <param name="handle">The platform-specific handle.</param>
/// <returns>A surface.</returns>
private static Surface CreateSurface(IPlatformHandle handle)
{
switch (handle.HandleDescriptor)
{
case "HWND":
return new Win32Surface(GetDC(handle.Handle));
case "HDC":
return new Win32Surface(handle.Handle);
default:
throw new NotSupportedException(string.Format(
"Don't know how to create a Cairo renderer from a '{0}' handle",
handle.HandleDescriptor));
}
}
/// <summary> /// <summary>
/// Renders the specified visual. /// Renders the specified visual.
/// </summary> /// </summary>

Loading…
Cancel
Save