fna-workbench

fna-workbench Commit Details


Date:2016-01-14 09:59:43 (9 years 7 months ago)
Author:Ethan Lee
Branch:master
Commit:497681b71200378a3e96d7c4a91fbb80ea63672a
Parents: 04bf5baceaed32b63ddba8bd237961d91d5ef3d7
Message:Mouse uses FNAPlatform rather than SDL2 directly

Changes:

File differences

FNA.csproj
308308
309309
310310
311
311312
312313
313314
......
335336
336337
337338
338
339339
340340
341341
<Compile Include="src\Input\KeyboardState.cs" />
<Compile Include="src\Input\Keys.cs" />
<Compile Include="src\Input\KeyState.cs" />
<Compile Include="src\Input\Mouse.cs" />
<Compile Include="src\Input\MouseState.cs" />
<Compile Include="src\Input\TextInputEXT.cs" />
<Compile Include="src\IUpdateable.cs" />
<Compile Include="src\Rectangle.cs" />
<Compile Include="src\SDL2\Input\SDL2_GamePad.cs" />
<Compile Include="src\SDL2\Input\SDL2_KeyboardUtil.cs" />
<Compile Include="src\SDL2\Input\SDL2_Mouse.cs" />
<Compile Include="src\SDL2\SDL2_FNAPlatform.cs" />
<Compile Include="src\SDL2\SDL2_GameWindow.cs" />
<Compile Include="src\Storage\StorageContainer.cs" />
Makefile
274274
275275
276276
277
277278
278279
279280
......
301302
302303
303304
304
305305
306306
307307
src/Input/KeyboardState.cs \
src/Input/Keys.cs \
src/Input/KeyState.cs \
src/Input/Mouse.cs \
src/Input/MouseState.cs \
src/Input/TextInputEXT.cs \
src/IUpdateable.cs \
src/Rectangle.cs \
src/SDL2/Input/SDL2_GamePad.cs \
src/SDL2/Input/SDL2_KeyboardUtil.cs \
src/SDL2/Input/SDL2_Mouse.cs \
src/SDL2/SDL2_FNAPlatform.cs \
src/SDL2/SDL2_GameWindow.cs \
src/Storage/StorageContainer.cs \
src/FNAPlatform.cs
4242
4343
4444
45
46
4547
4648
4749
......
7678
7779
7880
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
7999
80100
81101
SetPresentationInterval =SDL2_FNAPlatform.SetPresentationInterval;
GetGraphicsAdapters =SDL2_FNAPlatform.GetGraphicsAdapters;
GetKeyFromScancode =SDL2_FNAPlatform.GetKeyFromScancode;
GetMouseState =SDL2_FNAPlatform.GetMouseState;
SetMousePosition =SDL2_FNAPlatform.SetMousePosition;
OnIsMouseVisibleChanged =SDL2_FNAPlatform.OnIsMouseVisibleChanged;
GetStorageRoot =SDL2_FNAPlatform.GetStorageRoot;
IsStoragePathConnected =SDL2_FNAPlatform.IsStoragePathConnected;
public delegate Keys GetKeyFromScancodeFunc(Keys scancode);
public static GetKeyFromScancodeFunc GetKeyFromScancode;
public delegate void GetMouseStateFunc(
out int x,
out int y,
out ButtonState left,
out ButtonState middle,
out ButtonState right,
out ButtonState x1,
out ButtonState x2
);
public static GetMouseStateFunc GetMouseState;
public delegate void SetMousePositionFunc(
IntPtr window,
int x,
int y
);
public static SetMousePositionFunc SetMousePosition;
public delegate void OnIsMouseVisibleChangedFunc(bool visible);
public static OnIsMouseVisibleChangedFunc OnIsMouseVisibleChanged;
src/Input/Mouse.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#region License
/* FNA - XNA4 Reimplementation for Desktop Platforms
* Copyright 2009-2016 Ethan Lee and the MonoGame Team
*
* Released under the Microsoft Public License.
* See LICENSE for details.
*/
#endregion
#region Using Statements
using System;
#endregion
namespace Microsoft.Xna.Framework.Input
{
/// <summary>
/// Allows reading position and button click information from mouse.
/// </summary>
public static class Mouse
{
#region Public Properties
public static IntPtr WindowHandle
{
get;
set;
}
#endregion
#region Internal Variables
internal static int INTERNAL_WindowWidth = 800;
internal static int INTERNAL_WindowHeight = 600;
internal static int INTERNAL_MouseWheel = 0;
// FIXME: Remove when global mouse state is accessible! -flibit
internal static bool INTERNAL_IsWarped = false;
internal static int INTERNAL_warpX = 0;
internal static int INTERNAL_warpY = 0;
#endregion
#region Public Interface
/// <summary>
/// Gets mouse state information that includes position and button
/// presses for the provided window
/// </summary>
/// <returns>Current state of the mouse.</returns>
public static MouseState GetState()
{
int x, y;
ButtonState left, middle, right, x1, x2;
FNAPlatform.GetMouseState(
out x,
out y,
out left,
out middle,
out right,
out x1,
out x2
);
// If we warped the mouse, we've already done this in SetPosition.
if (INTERNAL_IsWarped)
{
x = INTERNAL_warpX;
y = INTERNAL_warpY;
}
else
{
// Scale the mouse coordinates for the faux-backbuffer
x = (int) ((double) x * Game.Instance.GraphicsDevice.GLDevice.Backbuffer.Width / INTERNAL_WindowWidth);
y = (int) ((double) y * Game.Instance.GraphicsDevice.GLDevice.Backbuffer.Height / INTERNAL_WindowHeight);
}
return new MouseState(
x,
y,
INTERNAL_MouseWheel,
left,
middle,
right,
x1,
x2
);
}
/// <summary>
/// Sets mouse cursor's relative position to game-window.
/// </summary>
/// <param name="x">Relative horizontal position of the cursor.</param>
/// <param name="y">Relative vertical position of the cursor.</param>
public static void SetPosition(int x, int y)
{
// The state should appear to be what they _think_ they're setting first.
INTERNAL_warpX = x;
INTERNAL_warpY = y;
// Scale the mouse coordinates for the faux-backbuffer
x = (int) ((double) x * INTERNAL_WindowWidth / Game.Instance.GraphicsDevice.GLDevice.Backbuffer.Width);
y = (int) ((double) y * INTERNAL_WindowHeight / Game.Instance.GraphicsDevice.GLDevice.Backbuffer.Height);
FNAPlatform.SetMousePosition(WindowHandle, x, y);
INTERNAL_IsWarped = true;
}
#endregion
}
}
src/SDL2/Input/SDL2_Mouse.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#region License
/* FNA - XNA4 Reimplementation for Desktop Platforms
* Copyright 2009-2016 Ethan Lee and the MonoGame Team
*
* Released under the Microsoft Public License.
* See LICENSE for details.
*/
#endregion
#region Using Statements
using System;
using SDL2;
#endregion
namespace Microsoft.Xna.Framework.Input
{
/// <summary>
/// Allows reading position and button click information from mouse.
/// </summary>
public static class Mouse
{
#region Public Properties
public static IntPtr WindowHandle
{
get;
set;
}
#endregion
#region Internal Variables
internal static int INTERNAL_WindowWidth = 800;
internal static int INTERNAL_WindowHeight = 600;
internal static int INTERNAL_MouseWheel = 0;
internal static bool INTERNAL_IsWarped = false;
#endregion
#region Private Variables
private static MouseState state;
#endregion
#region Public Interface
/// <summary>
/// Gets mouse state information that includes position and button
/// presses for the provided window
/// </summary>
/// <returns>Current state of the mouse.</returns>
public static MouseState GetState()
{
int x, y;
uint flags = SDL.SDL_GetMouseState(out x, out y);
// If we warped the mouse, we've already done this in SetPosition.
if (!INTERNAL_IsWarped)
{
// Scale the mouse coordinates for the faux-backbuffer
state.X = (int) ((double) x * Game.Instance.GraphicsDevice.GLDevice.Backbuffer.Width / INTERNAL_WindowWidth);
state.Y = (int) ((double) y * Game.Instance.GraphicsDevice.GLDevice.Backbuffer.Height / INTERNAL_WindowHeight);
}
state.LeftButton =(ButtonState) (flags & SDL.SDL_BUTTON_LMASK);
state.MiddleButton =(ButtonState) ((flags & SDL.SDL_BUTTON_MMASK) >> 1);
state.RightButton =(ButtonState) ((flags & SDL.SDL_BUTTON_RMASK) >> 2);
state.XButton1 =(ButtonState) ((flags & SDL.SDL_BUTTON_X1MASK) >> 3);
state.XButton2 =(ButtonState) ((flags & SDL.SDL_BUTTON_X2MASK) >> 4);
state.ScrollWheelValue = INTERNAL_MouseWheel;
return state;
}
/// <summary>
/// Sets mouse cursor's relative position to game-window.
/// </summary>
/// <param name="x">Relative horizontal position of the cursor.</param>
/// <param name="y">Relative vertical position of the cursor.</param>
public static void SetPosition(int x, int y)
{
// The state should appear to be what they _think_ they're setting first.
state.X = x;
state.Y = y;
// Scale the mouse coordinates for the faux-backbuffer
x = (int) ((double) x * INTERNAL_WindowWidth / Game.Instance.GraphicsDevice.GLDevice.Backbuffer.Width);
y = (int) ((double) y * INTERNAL_WindowHeight / Game.Instance.GraphicsDevice.GLDevice.Backbuffer.Height);
SDL.SDL_WarpMouseInWindow(WindowHandle, x, y);
INTERNAL_IsWarped = true;
}
#endregion
}
}
src/SDL2/SDL2_FNAPlatform.cs
522522
523523
524524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
525547
526548
527549
return SDL2_KeyboardUtil.KeyFromScancode(scancode);
}
public static void GetMouseState(
out int x,
out int y,
out ButtonState left,
out ButtonState middle,
out ButtonState right,
out ButtonState x1,
out ButtonState x2
) {
uint flags = SDL.SDL_GetMouseState(out x, out y);
left =(ButtonState) (flags & SDL.SDL_BUTTON_LMASK);
middle =(ButtonState) ((flags & SDL.SDL_BUTTON_MMASK) >> 1);
right =(ButtonState) ((flags & SDL.SDL_BUTTON_RMASK) >> 2);
x1 =(ButtonState) ((flags & SDL.SDL_BUTTON_X1MASK) >> 3);
x2 =(ButtonState) ((flags & SDL.SDL_BUTTON_X2MASK) >> 4);
}
public static void SetMousePosition(IntPtr window, int x, int y)
{
SDL.SDL_WarpMouseInWindow(window, x, y);
}
public static void OnIsMouseVisibleChanged(bool visible)
{
SDL.SDL_ShowCursor(visible ? 1 : 0);

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.49719s using 13 queries.