1
1
using System ;
2
2
using System . Reflection ;
3
3
using Myra . Graphics2D . UI . Styles ;
4
- using FontStashSharp . Interfaces ;
5
4
using Myra . Utility ;
6
- using FontStashSharp ;
7
5
using AssetManagementBase ;
6
+ using Myra . Graphics2D . UI ;
7
+ using System . Collections . Generic ;
8
8
9
9
#if MONOGAME || FNA
10
10
using Microsoft . Xna . Framework ;
11
11
using Microsoft . Xna . Framework . Graphics ;
12
+ using Microsoft . Xna . Framework . Input ;
13
+ #if FNA
14
+ using static SDL2 . SDL ;
15
+ using MouseCursor = System . Nullable < System . IntPtr > ;
16
+ #endif
17
+
12
18
#elif STRIDE
13
19
using Stride . Engine ;
14
20
using Stride . Graphics ;
@@ -20,59 +26,95 @@ namespace Myra
20
26
{
21
27
public static class MyraEnvironment
22
28
{
23
- private static AssetManager _defaultAssetManager ;
24
-
25
- [ Obsolete ( "Use FontSystemDefaults.KernelWidth" ) ]
26
- public static int FontKernelWidth
29
+ #if MONOGAME
30
+ private static readonly Dictionary < MouseCursorType , MouseCursor > _mouseCursors = new Dictionary < MouseCursorType , MouseCursor >
27
31
{
28
- get => FontSystemDefaults . KernelWidth ;
29
- set
30
- {
31
- FontSystemDefaults . KernelWidth = value ;
32
- }
33
- }
34
-
35
- [ Obsolete ( "Use FontSystemDefaults.KernelHeight" ) ]
36
- public static int FontKernelHeight
32
+ [ MouseCursorType . Arrow ] = MouseCursor . Arrow ,
33
+ [ MouseCursorType . IBeam ] = MouseCursor . IBeam ,
34
+ [ MouseCursorType . Wait ] = MouseCursor . Wait ,
35
+ [ MouseCursorType . Crosshair ] = MouseCursor . Crosshair ,
36
+ [ MouseCursorType . WaitArrow ] = MouseCursor . WaitArrow ,
37
+ [ MouseCursorType . SizeNWSE ] = MouseCursor . SizeNWSE ,
38
+ [ MouseCursorType . SizeNESW ] = MouseCursor . SizeNESW ,
39
+ [ MouseCursorType . SizeWE ] = MouseCursor . SizeWE ,
40
+ [ MouseCursorType . SizeNS ] = MouseCursor . SizeNS ,
41
+ [ MouseCursorType . SizeAll ] = MouseCursor . SizeAll ,
42
+ [ MouseCursorType . No ] = MouseCursor . No ,
43
+ [ MouseCursorType . Hand ] = MouseCursor . Hand ,
44
+ } ;
45
+ #elif FNA
46
+ private static readonly Dictionary < SDL_SystemCursor , IntPtr > _systemCursors = new Dictionary < SDL_SystemCursor , IntPtr > ( ) ;
47
+
48
+ private static IntPtr GetSystemCursor ( SDL_SystemCursor type )
37
49
{
38
- get => FontSystemDefaults . KernelHeight ;
39
- set
50
+ IntPtr result ;
51
+ if ( _systemCursors . TryGetValue ( type , out result ) )
40
52
{
41
- FontSystemDefaults . KernelHeight = value ;
53
+ return result ;
42
54
}
43
- }
44
55
45
- [ Obsolete ( "Use FontSystemDefaults.PremultiplyAlpha" ) ]
46
- public static bool FontPremultiplyAlpha
47
- {
48
- get => FontSystemDefaults . PremultiplyAlpha ;
49
- set
50
- {
51
- FontSystemDefaults . PremultiplyAlpha = value ;
52
- }
56
+ result = SDL_CreateSystemCursor ( type ) ;
57
+ _systemCursors [ type ] = result ;
58
+
59
+ return result ;
53
60
}
54
61
55
- [ Obsolete ( "Use FontSystemDefaults.FontResolutionFactor" ) ]
56
- public static float FontResolutionFactor
62
+ private static readonly Dictionary < MouseCursorType , SDL_SystemCursor > _mouseCursors = new Dictionary < MouseCursorType , SDL_SystemCursor >
57
63
{
58
- get => FontSystemDefaults . FontResolutionFactor ;
59
- set
60
- {
61
- FontSystemDefaults . FontResolutionFactor = value ;
62
- }
63
- }
64
+ [ MouseCursorType . Arrow ] = SDL_SystemCursor . SDL_SYSTEM_CURSOR_ARROW ,
65
+ [ MouseCursorType . IBeam ] = SDL_SystemCursor . SDL_SYSTEM_CURSOR_IBEAM ,
66
+ [ MouseCursorType . Wait ] = SDL_SystemCursor . SDL_SYSTEM_CURSOR_WAIT ,
67
+ [ MouseCursorType . Crosshair ] = SDL_SystemCursor . SDL_SYSTEM_CURSOR_CROSSHAIR ,
68
+ [ MouseCursorType . WaitArrow ] = SDL_SystemCursor . SDL_SYSTEM_CURSOR_WAITARROW ,
69
+ [ MouseCursorType . SizeNWSE ] = SDL_SystemCursor . SDL_SYSTEM_CURSOR_SIZENWSE ,
70
+ [ MouseCursorType . SizeNESW ] = SDL_SystemCursor . SDL_SYSTEM_CURSOR_SIZENESW ,
71
+ [ MouseCursorType . SizeWE ] = SDL_SystemCursor . SDL_SYSTEM_CURSOR_SIZEWE ,
72
+ [ MouseCursorType . SizeNS ] = SDL_SystemCursor . SDL_SYSTEM_CURSOR_SIZENS ,
73
+ [ MouseCursorType . SizeAll ] = SDL_SystemCursor . SDL_SYSTEM_CURSOR_SIZEALL ,
74
+ [ MouseCursorType . No ] = SDL_SystemCursor . SDL_SYSTEM_CURSOR_NO ,
75
+ [ MouseCursorType . Hand ] = SDL_SystemCursor . SDL_SYSTEM_CURSOR_HAND ,
76
+ } ;
77
+ #endif
64
78
79
+ private static MouseCursorType _mouseCursorType ;
80
+ private static AssetManager _defaultAssetManager ;
65
81
66
- [ Obsolete ( "Use FontSystemDefaults.FontLoader" ) ]
67
- public static IFontLoader FontLoader
82
+ public static MouseCursorType MouseCursorType
68
83
{
69
- get => FontSystemDefaults . FontLoader ;
84
+ get => _mouseCursorType ;
70
85
set
71
86
{
72
- FontSystemDefaults . FontLoader = value ;
87
+ if ( _mouseCursorType == value )
88
+ {
89
+ return ;
90
+ }
91
+
92
+ _mouseCursorType = value ;
93
+ #if MONOGAME
94
+ MouseCursor mouseCursor ;
95
+ if ( ! _mouseCursors . TryGetValue ( value , out mouseCursor ) )
96
+ {
97
+ throw new Exception ( $ "Could not find mouse cursor { value } ") ;
98
+ }
99
+
100
+ Mouse . SetCursor ( mouseCursor ) ;
101
+ #elif FNA
102
+ SDL_SystemCursor mouseCursor ;
103
+ if ( ! _mouseCursors . TryGetValue ( value , out mouseCursor ) )
104
+ {
105
+ throw new Exception ( $ "Could not find mouse cursor { value } ") ;
106
+ }
107
+
108
+ var mouseCursorPtr = GetSystemCursor ( mouseCursor ) ;
109
+ SDL2 . SDL . SDL_SetCursor ( mouseCursorPtr ) ;
110
+ #elif PLATFORM_AGNOSTIC
111
+ Platform . SetMouseCursorType ( value ) ;
112
+ #endif
73
113
}
74
114
}
75
115
116
+ public static MouseCursorType DefaultMouseCursorType { get ; set ; }
117
+
76
118
#if MONOGAME || FNA || STRIDE
77
119
78
120
private static Game _game ;
0 commit comments