| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using System;
- using Avalonia.Media.Imaging;
- using Avalonia.Platform;
- #nullable enable
- namespace Avalonia.Input
- {
- public enum StandardCursorType
- {
- Arrow,
- Ibeam,
- Wait,
- Cross,
- UpArrow,
- SizeWestEast,
- SizeNorthSouth,
- SizeAll,
- No,
- Hand,
- AppStarting,
- Help,
- TopSide,
- BottomSide,
- LeftSide,
- RightSide,
- TopLeftCorner,
- TopRightCorner,
- BottomLeftCorner,
- BottomRightCorner,
- DragMove,
- DragCopy,
- DragLink,
- None,
-
- // Not available in GTK directly, see https://www.pixelbeat.org/programming/x_cursors/
- // We might enable them later, preferably, by loading pixmax directly from theme with fallback image
- // SizeNorthWestSouthEast,
- // SizeNorthEastSouthWest,
- }
- public class Cursor : IDisposable
- {
- public static readonly Cursor Default = new Cursor(StandardCursorType.Arrow);
- internal Cursor(ICursorImpl platformImpl)
- {
- PlatformImpl = platformImpl;
- }
- public Cursor(StandardCursorType cursorType)
- : this(GetCursorFactory().GetCursor(cursorType))
- {
- }
- public Cursor(IBitmap cursor, PixelPoint hotSpot)
- : this(GetCursorFactory().CreateCursor(cursor.PlatformImpl.Item, hotSpot))
- {
- }
- public ICursorImpl PlatformImpl { get; }
- public void Dispose() => PlatformImpl.Dispose();
- public static Cursor Parse(string s)
- {
- return Enum.TryParse<StandardCursorType>(s, true, out var t) ?
- new Cursor(t) :
- throw new ArgumentException($"Unrecognized cursor type '{s}'.");
- }
- private static ICursorFactory GetCursorFactory()
- {
- return AvaloniaLocator.Current.GetRequiredService<ICursorFactory>();
- }
- }
- }
|