csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.6 KiB
61 lines
1.6 KiB
using System;
|
|
using System.IO;
|
|
using Avalonia.Input;
|
|
using Avalonia.Platform;
|
|
using Avalonia.Native.Interop;
|
|
|
|
namespace Avalonia.Native
|
|
{
|
|
class AvaloniaNativeCursor : ICursorImpl, IDisposable
|
|
{
|
|
public IAvnCursor Cursor { get; private set; }
|
|
public IntPtr Handle => IntPtr.Zero;
|
|
|
|
public string HandleDescriptor => "<none>";
|
|
|
|
public AvaloniaNativeCursor(IAvnCursor cursor)
|
|
{
|
|
Cursor = cursor;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Cursor.Dispose();
|
|
Cursor = null;
|
|
}
|
|
}
|
|
|
|
class CursorFactory : ICursorFactory
|
|
{
|
|
IAvnCursorFactory _native;
|
|
|
|
public CursorFactory(IAvnCursorFactory native)
|
|
{
|
|
_native = native;
|
|
}
|
|
|
|
public ICursorImpl GetCursor(StandardCursorType cursorType)
|
|
{
|
|
var cursor = _native.GetCursor((AvnStandardCursorType)cursorType);
|
|
return new AvaloniaNativeCursor( cursor );
|
|
}
|
|
|
|
public unsafe ICursorImpl CreateCursor(IBitmapImpl cursor, PixelPoint hotSpot)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|