18 changed files with 308 additions and 3 deletions
@ -0,0 +1,77 @@ |
|||
namespace Perspex.Gtk |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Gdk; |
|||
using Gtk = global::Gtk; |
|||
using Perspex.Input; |
|||
using Perspex.Platform; |
|||
class CursorFactory : IStandardCursorFactory |
|||
{ |
|||
public static CursorFactory Instance { get; } = new CursorFactory(); |
|||
|
|||
private CursorFactory() |
|||
{ |
|||
} |
|||
|
|||
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.Stock.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.Stock.Help } |
|||
}; |
|||
|
|||
private static readonly Dictionary<StandardCursorType, IPlatformHandle> Cache = |
|||
new Dictionary<StandardCursorType, IPlatformHandle>(); |
|||
|
|||
Gdk.Cursor GetCursor(object desc) |
|||
{ |
|||
Gdk.Cursor rv; |
|||
var name = desc as string; |
|||
if (name != null) |
|||
{ |
|||
var theme = Gtk.IconTheme.Default; |
|||
var icon = theme.LoadIcon(name, 32, default(Gtk.IconLookupFlags)); |
|||
rv = icon == null ? new Gdk.Cursor(CursorType.XCursor) : new Gdk.Cursor(Gdk.Display.Default, icon, 0, 0); |
|||
} |
|||
else |
|||
{ |
|||
rv = new Gdk.Cursor((CursorType) desc); |
|||
} |
|||
|
|||
rv.Owned = false; |
|||
return rv; |
|||
|
|||
} |
|||
|
|||
public IPlatformHandle GetCursor(StandardCursorType cursorType) |
|||
{ |
|||
IPlatformHandle rv; |
|||
if (!Cache.TryGetValue(cursorType, out rv)) |
|||
{ |
|||
Cache[cursorType] = |
|||
rv = |
|||
new PlatformHandle( |
|||
GetCursor(CursorTypeMapping[cursorType]).Handle, |
|||
"GTKCURSOR"); |
|||
} |
|||
|
|||
return rv; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,58 @@ |
|||
namespace Perspex.Input |
|||
{ |
|||
using Splat; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Perspex.Platform; |
|||
|
|||
/* |
|||
========================================================================================= |
|||
NOTE: Cursors are NOT disposable and are cached in platform implementation. |
|||
To support loading custom cursors some measures about that should be taken beforehand |
|||
========================================================================================= |
|||
*/ |
|||
|
|||
public enum StandardCursorType |
|||
{ |
|||
Arrow, |
|||
Ibeam, |
|||
Wait, |
|||
Cross, |
|||
UpArrow, |
|||
SizeWestEast, |
|||
SizeNorthSouth, |
|||
SizeAll, |
|||
No, |
|||
Hand, |
|||
AppStarting, |
|||
Help |
|||
|
|||
// 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
|
|||
// SizeNorthWestSouthEast,
|
|||
// SizeNorthEastSouthWest,
|
|||
|
|||
} |
|||
|
|||
public class Cursor |
|||
{ |
|||
public static Cursor Default = new Cursor(StandardCursorType.Arrow); |
|||
|
|||
internal Cursor(IPlatformHandle platformCursor) |
|||
{ |
|||
this.PlatformCursor = platformCursor; |
|||
} |
|||
|
|||
public Cursor(StandardCursorType cursorType) |
|||
: this( |
|||
((IStandardCursorFactory) Locator.Current.GetService(typeof(IStandardCursorFactory))).GetCursor( |
|||
cursorType)) |
|||
{ |
|||
} |
|||
|
|||
public IPlatformHandle PlatformCursor { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
namespace Perspex.Platform |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Perspex.Input; |
|||
|
|||
public interface IStandardCursorFactory |
|||
{ |
|||
IPlatformHandle GetCursor(StandardCursorType cursorType); |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
using Perspex.Win32.Interop; |
|||
|
|||
namespace Perspex.Win32 |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Perspex.Input; |
|||
using Perspex.Platform; |
|||
|
|||
class CursorFactory : IStandardCursorFactory |
|||
{ |
|||
public static CursorFactory Instance { get; } = new CursorFactory(); |
|||
|
|||
private CursorFactory() |
|||
{ |
|||
} |
|||
|
|||
private static readonly Dictionary<StandardCursorType, int> CursorTypeMapping = new Dictionary |
|||
<StandardCursorType, int> |
|||
{ |
|||
|
|||
{ StandardCursorType.AppStarting, 32650 }, |
|||
{ StandardCursorType.Arrow, 32512 }, |
|||
{ StandardCursorType.Cross, 32515 }, |
|||
{ StandardCursorType.Hand, 32649 }, |
|||
{ StandardCursorType.Help, 32651 }, |
|||
{ StandardCursorType.Ibeam, 32513 }, |
|||
{ StandardCursorType.No, 32648 }, |
|||
{ StandardCursorType.SizeAll, 32646 }, |
|||
|
|||
// { StandardCursorType.SizeNorthEastSouthWest, 32643 },
|
|||
{ StandardCursorType.SizeNorthSouth, 32645 }, |
|||
|
|||
// { StandardCursorType.SizeNorthWestSouthEast, 32642 },
|
|||
{ StandardCursorType.SizeWestEast, 32644 }, |
|||
{ StandardCursorType.UpArrow, 32516 }, |
|||
{ StandardCursorType.Wait, 32514 } |
|||
}; |
|||
|
|||
private static readonly Dictionary<StandardCursorType, IPlatformHandle> Cache = |
|||
new Dictionary<StandardCursorType, IPlatformHandle>(); |
|||
|
|||
public IPlatformHandle GetCursor(StandardCursorType cursorType) |
|||
{ |
|||
IPlatformHandle rv; |
|||
if (!Cache.TryGetValue(cursorType, out rv)) |
|||
{ |
|||
Cache[cursorType] = |
|||
rv = |
|||
new PlatformHandle( |
|||
UnmanagedMethods.LoadCursor(IntPtr.Zero, new IntPtr(CursorTypeMapping[cursorType])), |
|||
PlatformConstants.CursorHandleType); |
|||
} |
|||
|
|||
return rv; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Perspex.Win32 |
|||
{ |
|||
public static class PlatformConstants |
|||
{ |
|||
public const string WindowHandleType = "HWND"; |
|||
public const string CursorHandleType = "HCURSOR"; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue