7 changed files with 195 additions and 10 deletions
@ -0,0 +1,79 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using Avalonia.Gtk3.Interop; |
||||
|
using Avalonia.Input; |
||||
|
using Avalonia.Platform; |
||||
|
using CursorType = Avalonia.Gtk3.GdkCursorType; |
||||
|
namespace Avalonia.Gtk3 |
||||
|
{ |
||||
|
class CursorFactory : IStandardCursorFactory |
||||
|
{ |
||||
|
private static readonly Dictionary<StandardCursorType, object> CursorTypeMapping = new Dictionary |
||||
|
<StandardCursorType, object> |
||||
|
{ |
||||
|
{StandardCursorType.AppStarting, CursorType.Watch}, |
||||
|
{StandardCursorType.Arrow, CursorType.LeftPtr}, |
||||
|
{StandardCursorType.Cross, CursorType.Cross}, |
||||
|
{StandardCursorType.Hand, CursorType.Hand1}, |
||||
|
{StandardCursorType.Ibeam, CursorType.Xterm}, |
||||
|
{StandardCursorType.No, "gtk-cancel"}, |
||||
|
{StandardCursorType.SizeAll, CursorType.Sizing}, |
||||
|
//{ StandardCursorType.SizeNorthEastSouthWest, 32643 },
|
||||
|
{StandardCursorType.SizeNorthSouth, CursorType.SbVDoubleArrow}, |
||||
|
//{ StandardCursorType.SizeNorthWestSouthEast, 32642 },
|
||||
|
{StandardCursorType.SizeWestEast, CursorType.SbHDoubleArrow}, |
||||
|
{StandardCursorType.UpArrow, CursorType.BasedArrowUp}, |
||||
|
{StandardCursorType.Wait, CursorType.Watch}, |
||||
|
{StandardCursorType.Help, "gtk-help"}, |
||||
|
{StandardCursorType.TopSide, CursorType.TopSide}, |
||||
|
{StandardCursorType.BottomSize, CursorType.BottomSide}, |
||||
|
{StandardCursorType.LeftSide, CursorType.LeftSide}, |
||||
|
{StandardCursorType.RightSide, CursorType.RightSide}, |
||||
|
{StandardCursorType.TopLeftCorner, CursorType.TopLeftCorner}, |
||||
|
{StandardCursorType.TopRightCorner, CursorType.TopRightCorner}, |
||||
|
{StandardCursorType.BottomLeftCorner, CursorType.BottomLeftCorner}, |
||||
|
{StandardCursorType.BottomRightCorner, CursorType.BottomRightCorner} |
||||
|
}; |
||||
|
|
||||
|
private static readonly Dictionary<StandardCursorType, IPlatformHandle> Cache = |
||||
|
new Dictionary<StandardCursorType, IPlatformHandle>(); |
||||
|
|
||||
|
private IntPtr GetCursor(object desc) |
||||
|
{ |
||||
|
IntPtr rv; |
||||
|
var name = desc as string; |
||||
|
if (name != null) |
||||
|
{ |
||||
|
var theme = Native.GtkIconThemeGetDefault(); |
||||
|
IntPtr icon, error; |
||||
|
using (var u = new Utf8Buffer(name)) |
||||
|
icon = Native.GtkIconThemeLoadIcon(theme, u, 32, 0, out error); |
||||
|
rv = icon == IntPtr.Zero |
||||
|
? Native.GdkCursorNew(GdkCursorType.XCursor) |
||||
|
: Native.GdkCursorNewFromPixbuf(Native.GdkGetDefaultDisplay(), icon, 0, 0); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
rv = Native.GdkCursorNew((CursorType)desc); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
return rv; |
||||
|
} |
||||
|
|
||||
|
public IPlatformHandle GetCursor(StandardCursorType cursorType) |
||||
|
{ |
||||
|
IPlatformHandle rv; |
||||
|
if (!Cache.TryGetValue(cursorType, out rv)) |
||||
|
{ |
||||
|
Cache[cursorType] = |
||||
|
rv = |
||||
|
new PlatformHandle( |
||||
|
GetCursor(CursorTypeMapping[cursorType]), |
||||
|
"GTKCURSOR"); |
||||
|
} |
||||
|
|
||||
|
return rv; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,91 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Avalonia.Gtk3 |
||||
|
{ |
||||
|
enum GdkCursorType |
||||
|
{ |
||||
|
CursorIsPixmap = -1, |
||||
|
XCursor = 0, |
||||
|
Arrow = 2, |
||||
|
BasedArrowDown = 4, |
||||
|
BasedArrowUp = 6, |
||||
|
Boat = 8, |
||||
|
Bogosity = 10, |
||||
|
BottomLeftCorner = 12, |
||||
|
BottomRightCorner = 14, |
||||
|
BottomSide = 16, |
||||
|
BottomTee = 18, |
||||
|
BoxSpiral = 20, |
||||
|
CenterPtr = 22, |
||||
|
Circle = 24, |
||||
|
Clock = 26, |
||||
|
CoffeeMug = 28, |
||||
|
Cross = 30, |
||||
|
CrossReverse = 32, |
||||
|
Crosshair = 34, |
||||
|
DiamondCross = 36, |
||||
|
Dot = 38, |
||||
|
Dotbox = 40, |
||||
|
DoubleArrow = 42, |
||||
|
DraftLarge = 44, |
||||
|
DraftSmall = 46, |
||||
|
DrapedBox = 48, |
||||
|
Exchange = 50, |
||||
|
Fleur = 52, |
||||
|
Gobbler = 54, |
||||
|
Gumby = 56, |
||||
|
Hand1 = 58, |
||||
|
Hand2 = 60, |
||||
|
Heart = 62, |
||||
|
Icon = 64, |
||||
|
IronCross = 66, |
||||
|
LeftPtr = 68, |
||||
|
LeftSide = 70, |
||||
|
LeftTee = 72, |
||||
|
Leftbutton = 74, |
||||
|
LlAngle = 76, |
||||
|
LrAngle = 78, |
||||
|
Man = 80, |
||||
|
Middlebutton = 82, |
||||
|
Mouse = 84, |
||||
|
Pencil = 86, |
||||
|
Pirate = 88, |
||||
|
Plus = 90, |
||||
|
QuestionArrow = 92, |
||||
|
RightPtr = 94, |
||||
|
RightSide = 96, |
||||
|
RightTee = 98, |
||||
|
Rightbutton = 100, |
||||
|
RtlLogo = 102, |
||||
|
Sailboat = 104, |
||||
|
SbDownArrow = 106, |
||||
|
SbHDoubleArrow = 108, |
||||
|
SbLeftArrow = 110, |
||||
|
SbRightArrow = 112, |
||||
|
SbUpArrow = 114, |
||||
|
SbVDoubleArrow = 116, |
||||
|
Shuttle = 118, |
||||
|
Sizing = 120, |
||||
|
Spider = 122, |
||||
|
Spraycan = 124, |
||||
|
Star = 126, |
||||
|
Target = 128, |
||||
|
Tcross = 130, |
||||
|
TopLeftArrow = 132, |
||||
|
TopLeftCorner = 134, |
||||
|
TopRightCorner = 136, |
||||
|
TopSide = 138, |
||||
|
TopTee = 140, |
||||
|
Trek = 142, |
||||
|
UlAngle = 144, |
||||
|
Umbrella = 146, |
||||
|
UrAngle = 148, |
||||
|
Watch = 150, |
||||
|
Xterm = 152, |
||||
|
LastCursor = 153, |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue