|
|
|
@ -7,29 +7,31 @@ |
|
|
|
namespace Perspex.Cairo |
|
|
|
{ |
|
|
|
using System; |
|
|
|
using Perspex.Platform; |
|
|
|
using Splat; |
|
|
|
using global::Cairo; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
using global::Cairo; |
|
|
|
using Perspex.Cairo.Media; |
|
|
|
using Perspex.Platform; |
|
|
|
using Matrix = Perspex.Matrix; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A cairo renderer.
|
|
|
|
/// </summary>
|
|
|
|
public class Renderer : IRenderer |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// The handle of the window to draw to.
|
|
|
|
/// </summary>
|
|
|
|
private IntPtr hwnd; |
|
|
|
private IPlatformHandle handle; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="Renderer"/> class.
|
|
|
|
/// </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="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>
|
|
|
|
@ -38,7 +40,7 @@ namespace Perspex.Cairo |
|
|
|
/// <param name="visual">The visual to render.</param>
|
|
|
|
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)) |
|
|
|
{ |
|
|
|
this.Render(visual, context); |
|
|
|
@ -52,11 +54,32 @@ namespace Perspex.Cairo |
|
|
|
/// <param name="height">The new height.</param>
|
|
|
|
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")] |
|
|
|
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>
|
|
|
|
/// Renders the specified visual.
|
|
|
|
/// </summary>
|
|
|
|
|