Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Commit

Permalink
Add SetCursorPosition to IGameWindow (#186)
Browse files Browse the repository at this point in the history
* Add SetCursorPosition to IGameWindow

Mouse.SetPosition is not suitable for all hosts (e.g. when the game is hosted in an editor)

* Add empty SetCursorPosition to AndroidGameWindow
  • Loading branch information
hach-que committed Jun 4, 2017
1 parent 4cdf437 commit 44b4fb9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void Update(ComponentizedEntity entity, IGameContext gameContext, IUpdate
var limit = MathHelper.PiOver2 - MathHelper.ToRadians(5);
_firstPersonCameraComponent.Pitch = MathHelper.Clamp(_firstPersonCameraComponent.Pitch, -limit, limit);

Mouse.SetPosition(centerX, centerY);
gameContext.Window.SetCursorPosition(centerX, centerY);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion Protogame/Component/Builtin/FlyAroundInputComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class FlyAroundInputComponent : IEventfulComponent, IEnabledComponent
var limit = MathHelper.PiOver2 - MathHelper.ToRadians(5);
_firstPersonCameraComponent.Pitch = MathHelper.Clamp(_firstPersonCameraComponent.Pitch, -limit, limit);

Mouse.SetPosition(centerX, centerY);
gameContext.Window.SetCursorPosition(centerX, centerY);

return true;
}
Expand Down
7 changes: 7 additions & 0 deletions Protogame/Core/IGameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public interface IGameWindow
Microsoft.Xna.Framework.AndroidGameWindow PlatformWindow { get; }
#endif

/// <summary>
/// Sets the position of the mouse cursor on the screen, relative to the window.
/// </summary>
/// <param name="x">The horizontal position of the cursor.</param>
/// <param name="y">The vertical position of the cursor.</param>
void SetCursorPosition(int x, int y);

#if PLATFORM_WINDOWS
void Maximize();

Expand Down
4 changes: 4 additions & 0 deletions Protogame/Platform/AndroidGameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public AndroidMonoGameWindow PlatformWindow
{
get { return this.m_GameWindow; }
}

public void SetCursorPosition(int x, int y)
{
}
}
}
#endif
6 changes: 6 additions & 0 deletions Protogame/Platform/DefaultGameWindow.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma warning disable CS1591

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

#if PLATFORM_WINDOWS || PLATFORM_MACOS || PLATFORM_LINUX || PLATFORM_WEB || PLATFORM_IOS

Expand Down Expand Up @@ -62,6 +63,11 @@ public GameWindow PlatformWindow
get { return _gameWindow; }
}

public void SetCursorPosition(int x, int y)
{
Mouse.SetPosition(x, y);
}

#if PLATFORM_WINDOWS
public void Maximize()
{
Expand Down

0 comments on commit 44b4fb9

Please sign in to comment.