From e90fe543f0466602687dbea6f568a8f42a0832b3 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 8 Feb 2021 17:16:46 +0000 Subject: [PATCH] add full osx implementation for custom cursors. --- src/Avalonia.Native/Cursor.cs | 18 ++++++++++++++++-- src/Avalonia.Native/avn.idl | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Native/Cursor.cs b/src/Avalonia.Native/Cursor.cs index 2cb085bc7e..ae218e270c 100644 --- a/src/Avalonia.Native/Cursor.cs +++ b/src/Avalonia.Native/Cursor.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using Avalonia.Input; using Avalonia.Platform; using Avalonia.Native.Interop; @@ -39,9 +40,22 @@ namespace Avalonia.Native return new AvaloniaNativeCursor( cursor ); } - public ICursorImpl CreateCursor(IBitmapImpl cursor, PixelPoint hotSpot) + public unsafe ICursorImpl CreateCursor(IBitmapImpl cursor, PixelPoint hotSpot) { - throw new NotImplementedException(); + using(var ms = new MemoryStream()) + { + cursor.Save(ms); + + var imageData = ms.ToArray(); + + fixed(void* ptr = imageData) + { + var avnCursor = _native.CreateCustomCursor(ptr, new IntPtr(imageData.Length), + new AvnPixelSize { Width = hotSpot.X, Height = hotSpot.Y }); + + return new AvaloniaNativeCursor(avnCursor); + } + } } } } diff --git a/src/Avalonia.Native/avn.idl b/src/Avalonia.Native/avn.idl index 166046ca24..3627ff6894 100644 --- a/src/Avalonia.Native/avn.idl +++ b/src/Avalonia.Native/avn.idl @@ -619,6 +619,7 @@ interface IAvnCursor : IUnknown interface IAvnCursorFactory : IUnknown { HRESULT GetCursor(AvnStandardCursorType cursorType, IAvnCursor** retOut); + HRESULT CreateCustomCursor (void* bitmapData, size_t length, AvnPixelSize hotPixel, IAvnCursor** retOut); } [uuid(60452465-8616-40af-bc00-042e69828ce7)]