// ----------------------------------------------------------------------- // // Copyright 2013 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Cairo { using System; using System.Runtime.InteropServices; using global::Cairo; using Perspex.Cairo.Media; using Perspex.Media; using Perspex.Platform; using Perspex.Rendering; using Matrix = Perspex.Matrix; /// /// A cairo renderer. /// public class Renderer : RendererBase { private ImageSurface surface; /// /// Initializes a new instance of the class. /// /// The window handle. /// The width of the window. /// The height of the window. public Renderer(IPlatformHandle handle, double width, double height) { } public Renderer(ImageSurface surface) { this.surface = surface; } /// /// Resizes the renderer. /// /// The new width. /// The new height. public override void Resize(int width, int height) { // Don't need to do anything here. } /// /// Creates a cairo surface that targets a platform-specific resource. /// /// The platform-specific handle. /// A surface wrapped in an . protected override IDrawingContext CreateDrawingContext(IPlatformHandle handle) { switch (handle.HandleDescriptor) { case "HWND": return new DrawingContext(new Win32Surface(GetDC(handle.Handle))); case "RTB": return new DrawingContext(this.surface); case "HDC": return new DrawingContext(new Win32Surface(handle.Handle)); case "GdkWindow": return new DrawingContext(new Gdk.Window(handle.Handle)); default: throw new NotSupportedException(string.Format( "Don't know how to create a Cairo renderer from a '{0}' handle", handle.HandleDescriptor)); } } [DllImport("user32.dll")] private static extern IntPtr GetDC(IntPtr hwnd); } }