Browse Source

Add blank cursor

pull/2551/head
MarkusKgit 7 years ago
parent
commit
8cfa7c175c
  1. 1
      src/Avalonia.Input/Cursors.cs
  2. 22
      src/Avalonia.X11/X11CursorFactory.cs
  3. 7
      src/Gtk/Avalonia.Gtk3/CursorFactory.cs
  4. 1
      src/Gtk/Avalonia.Gtk3/GdkCursor.cs
  5. 5
      src/Windows/Avalonia.Win32/CursorFactory.cs

1
src/Avalonia.Input/Cursors.cs

@ -38,6 +38,7 @@ namespace Avalonia.Input
DragMove,
DragCopy,
DragLink,
None,
// Not available in GTK directly, see http://www.pixelbeat.org/programming/x_cursors/
// We might enable them later, preferably, by loading pixmax direclty from theme with fallback image

22
src/Avalonia.X11/X11CursorFactory.cs

@ -8,6 +8,8 @@ namespace Avalonia.X11
{
class X11CursorFactory : IStandardCursorFactory
{
private static IntPtr _nullCursor;
private readonly IntPtr _display;
private Dictionary<CursorFontShape, IntPtr> _cursors;
@ -42,16 +44,34 @@ namespace Avalonia.X11
public X11CursorFactory(IntPtr display)
{
_display = display;
_nullCursor = GetNullCursor(display);
_cursors = Enum.GetValues(typeof(CursorFontShape)).Cast<CursorFontShape>()
.ToDictionary(id => id, id => XLib.XCreateFontCursor(_display, id));
}
public IPlatformHandle GetCursor(StandardCursorType cursorType)
{
var handle = s_mapping.TryGetValue(cursorType, out var shape)
IntPtr handle;
if (cursorType == StandardCursorType.None)
{
handle = _nullCursor;
}
else
{
handle = s_mapping.TryGetValue(cursorType, out var shape)
? _cursors[shape]
: _cursors[CursorFontShape.XC_top_left_arrow];
}
return new PlatformHandle(handle, "XCURSOR");
}
private static IntPtr GetNullCursor(IntPtr display)
{
XColor color = new XColor();
byte[] data = new byte[] { 0 };
IntPtr window = XLib.XRootWindow(display, 0);
IntPtr pixmap = XLib.XCreatePixmapFromBitmapData(display, window, data, 1, 1, IntPtr.Zero, IntPtr.Zero, 0);
return XLib.XCreatePixmapCursor(display, pixmap, pixmap, ref color, ref color, 0, 0);
}
}
}

7
src/Gtk/Avalonia.Gtk3/CursorFactory.cs

@ -12,7 +12,8 @@ namespace Avalonia.Gtk3
private static readonly Dictionary<StandardCursorType, object> CursorTypeMapping = new Dictionary
<StandardCursorType, object>
{
{StandardCursorType.AppStarting, CursorType.Watch},
{StandardCursorType.None, CursorType.Blank},
{ StandardCursorType.AppStarting, CursorType.Watch},
{StandardCursorType.Arrow, CursorType.LeftPtr},
{StandardCursorType.Cross, CursorType.Cross},
{StandardCursorType.Hand, CursorType.Hand1},
@ -36,7 +37,7 @@ namespace Avalonia.Gtk3
{StandardCursorType.BottomRightCorner, CursorType.BottomRightCorner},
{StandardCursorType.DragCopy, CursorType.CenterPtr},
{StandardCursorType.DragMove, CursorType.Fleur},
{StandardCursorType.DragLink, CursorType.Cross},
{StandardCursorType.DragLink, CursorType.Cross},
};
private static readonly Dictionary<StandardCursorType, IPlatformHandle> Cache =
@ -80,4 +81,4 @@ namespace Avalonia.Gtk3
return rv;
}
}
}
}

1
src/Gtk/Avalonia.Gtk3/GdkCursor.cs

@ -2,6 +2,7 @@
{
enum GdkCursorType
{
Blank = -2,
CursorIsPixmap = -1,
XCursor = 0,
Arrow = 2,

5
src/Windows/Avalonia.Win32/CursorFactory.cs

@ -41,7 +41,8 @@ namespace Avalonia.Win32
private static readonly Dictionary<StandardCursorType, int> CursorTypeMapping = new Dictionary
<StandardCursorType, int>
{
{StandardCursorType.AppStarting, 32650},
{StandardCursorType.None, 0},
{ StandardCursorType.AppStarting, 32650},
{StandardCursorType.Arrow, 32512},
{StandardCursorType.Cross, 32515},
{StandardCursorType.Hand, 32649},
@ -69,7 +70,7 @@ namespace Avalonia.Win32
// Fallback, should have been loaded from ole32.dll
{StandardCursorType.DragMove, 32516},
{StandardCursorType.DragCopy, 32516},
{StandardCursorType.DragLink, 32516},
{StandardCursorType.DragLink, 32516},
};
private static readonly Dictionary<StandardCursorType, IPlatformHandle> Cache =

Loading…
Cancel
Save