summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/CursorPosition.cs8
-rw-r--r--src/SMAPI/Framework/Input/SInputState.cs14
2 files changed, 12 insertions, 10 deletions
diff --git a/src/SMAPI/Framework/CursorPosition.cs b/src/SMAPI/Framework/CursorPosition.cs
index 079917f2..2008ccce 100644
--- a/src/SMAPI/Framework/CursorPosition.cs
+++ b/src/SMAPI/Framework/CursorPosition.cs
@@ -8,10 +8,10 @@ namespace StardewModdingAPI.Framework
/*********
** Accessors
*********/
- /// <summary>The pixel position relative to the top-left corner of the in-game map.</summary>
+ /// <summary>The pixel position relative to the top-left corner of the in-game map, adjusted for pixel zoom.</summary>
public Vector2 AbsolutePixels { get; }
- /// <summary>The pixel position relative to the top-left corner of the visible screen.</summary>
+ /// <summary>The pixel position relative to the top-left corner of the visible screen, adjusted for pixel zoom.</summary>
public Vector2 ScreenPixels { get; }
/// <summary>The tile position under the cursor relative to the top-left corner of the map.</summary>
@@ -25,8 +25,8 @@ namespace StardewModdingAPI.Framework
** Public methods
*********/
/// <summary>Construct an instance.</summary>
- /// <param name="absolutePixels">The pixel position relative to the top-left corner of the in-game map.</param>
- /// <param name="screenPixels">The pixel position relative to the top-left corner of the visible screen.</param>
+ /// <param name="absolutePixels">The pixel position relative to the top-left corner of the in-game map, adjusted for pixel zoom.</param>
+ /// <param name="screenPixels">The pixel position relative to the top-left corner of the visible screen, adjusted for pixel zoom.</param>
/// <param name="tile">The tile position relative to the top-left corner of the map.</param>
/// <param name="grabTile">The tile position that the game considers under the cursor for purposes of clicking actions.</param>
public CursorPosition(Vector2 absolutePixels, Vector2 screenPixels, Vector2 tile, Vector2 grabTile)
diff --git a/src/SMAPI/Framework/Input/SInputState.cs b/src/SMAPI/Framework/Input/SInputState.cs
index a15272d5..d69e5604 100644
--- a/src/SMAPI/Framework/Input/SInputState.cs
+++ b/src/SMAPI/Framework/Input/SInputState.cs
@@ -80,12 +80,14 @@ namespace StardewModdingAPI.Framework.Input
{
try
{
+ float zoomMultiplier = (1f / Game1.options.zoomLevel);
+
// get new states
GamePadState realController = GamePad.GetState(PlayerIndex.One);
KeyboardState realKeyboard = Keyboard.GetState();
MouseState realMouse = Mouse.GetState();
var activeButtons = this.DeriveStatuses(this.ActiveButtons, realKeyboard, realMouse, realController);
- Vector2 cursorAbsolutePos = new Vector2(realMouse.X + Game1.viewport.X, realMouse.Y + Game1.viewport.Y);
+ Vector2 cursorAbsolutePos = new Vector2((realMouse.X * zoomMultiplier) + Game1.viewport.X, (realMouse.Y * zoomMultiplier) + Game1.viewport.Y);
Vector2? playerTilePos = Context.IsPlayerFree ? Game1.player.getTileLocation() : (Vector2?)null;
// update real states
@@ -96,7 +98,7 @@ namespace StardewModdingAPI.Framework.Input
if (cursorAbsolutePos != this.CursorPositionImpl?.AbsolutePixels || playerTilePos != this.LastPlayerTile)
{
this.LastPlayerTile = playerTilePos;
- this.CursorPositionImpl = this.GetCursorPosition(realMouse, cursorAbsolutePos);
+ this.CursorPositionImpl = this.GetCursorPosition(realMouse, cursorAbsolutePos, zoomMultiplier);
}
// update suppressed states
@@ -170,11 +172,11 @@ namespace StardewModdingAPI.Framework.Input
*********/
/// <summary>Get the current cursor position.</summary>
/// <param name="mouseState">The current mouse state.</param>
- /// <param name="absolutePixels">The absolute pixel position relative to the map.</param>
- private CursorPosition GetCursorPosition(MouseState mouseState, Vector2 absolutePixels)
+ /// <param name="absolutePixels">The absolute pixel position relative to the map, adjusted for pixel zoom.</param>
+ /// <param name="zoomMultiplier">The multiplier applied to pixel coordinates to adjust them for pixel zoom.</param>
+ private CursorPosition GetCursorPosition(MouseState mouseState, Vector2 absolutePixels, float zoomMultiplier)
{
- Vector2 rawPixels = new Vector2(mouseState.X, mouseState.Y);
- Vector2 screenPixels = rawPixels * new Vector2((float)1.0 / Game1.options.zoomLevel); // derived from Game1::getMouseX
+ Vector2 screenPixels = new Vector2(mouseState.X * zoomMultiplier, mouseState.Y * zoomMultiplier);
Vector2 tile = new Vector2((int)((Game1.viewport.X + screenPixels.X) / Game1.tileSize), (int)((Game1.viewport.Y + screenPixels.Y) / Game1.tileSize));
Vector2 grabTile = (Game1.mouseCursorTransparency > 0 && Utility.tileWithinRadiusOfPlayer((int)tile.X, (int)tile.Y, 1, Game1.player)) // derived from Game1.pressActionButton
? tile