From c7354c07d939d5605853813ccba77116551f9807 Mon Sep 17 00:00:00 2001
From: Dave Green <34277803+SoloByte@users.noreply.github.com>
Date: Wed, 19 Aug 2026 10:34:44 +0200
Subject: [PATCH] Refactor: Changed GameVirtual.cs ChangeMousePos signature to
return bool and have an out parameter for new mouse position. The old
ChangeMousePos signature was deprecated but still exists. (Marked as
Obsolete) Refactor: GameloopExamples.cs ChangeMousePos override changed to
new signature. Refactor: GameGameloop.cs now uses new ChangeMousePos
signature to only move the mouse cursor when actually requested.
---
Examples/GameloopExamples.cs | 18 ++++++++++++------
ShapeEngine/Core/GameDef/GameGameloop.cs | 5 ++++-
ShapeEngine/Core/GameDef/GameVirtual.cs | 18 ++++++++++++++++++
3 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/Examples/GameloopExamples.cs b/Examples/GameloopExamples.cs
index 8f054283..263ebf79 100644
--- a/Examples/GameloopExamples.cs
+++ b/Examples/GameloopExamples.cs
@@ -535,9 +535,10 @@ protected override void LoadContent()
contentPackAll.Clear();
}
- protected override Vector2 ChangeMousePos(float dt, Vector2 mousePos, Rect screenArea)
+ protected override bool ChangeMousePos(float dt, Vector2 mousePos, Rect screenArea, out Vector2 newMousePos)
{
- if (!MouseControlEnabled) return mousePos;
+ newMousePos = mousePos;
+ if (!MouseControlEnabled) return false;
if (Input.CurrentInputDeviceType == InputDeviceType.Gamepad && Input.GamepadManager.LastUsedGamepad != null &&
Input.GamepadManager.LastUsedGamepad.IsDown(ShapeGamepadTriggerAxis.RIGHT))
@@ -550,10 +551,14 @@ protected override Vector2 ChangeMousePos(float dt, Vector2 mousePos, Rect scree
var movement = new Vector2(x, y);
float l = movement.Length();
- if (l <= 0f) return mousePos;
+ if (l <= 0f)
+ {
+ return false;
+ }
var dir = movement / l;
- return mousePos + dir * l * speed;
+ newMousePos = mousePos + dir * l * speed;
+ return true;
}
if (Input.CurrentInputDeviceType == InputDeviceType.Keyboard)
@@ -568,11 +573,12 @@ protected override Vector2 ChangeMousePos(float dt, Vector2 mousePos, Rect scree
var movement = new Vector2(x, y);
if (movement.LengthSquared() <= 0f) mouseMovementTimer = 0f;
- return mousePos + movement.Normalize() * speed;
+ newMousePos = mousePos + movement.Normalize() * speed;
+ return true;
}
mouseMovementTimer = 0f;
- return mousePos;
+ return false;
}
protected override void EndRun()
diff --git a/ShapeEngine/Core/GameDef/GameGameloop.cs b/ShapeEngine/Core/GameDef/GameGameloop.cs
index 2b8e1e06..bb9efb17 100644
--- a/ShapeEngine/Core/GameDef/GameGameloop.cs
+++ b/ShapeEngine/Core/GameDef/GameGameloop.cs
@@ -106,7 +106,10 @@ private void RunGameloop()
{
if (Input.CurrentInputDeviceType is InputDeviceType.Keyboard or InputDeviceType.Gamepad)
{
- Window.MoveMouse(ChangeMousePos(dt, Window.MousePosition, Window.ScreenArea));
+ if (ChangeMousePos(dt, Window.MousePosition, Window.ScreenArea, out var newMousePos))
+ {
+ Window.MoveMouse(newMousePos);
+ }
}
}
diff --git a/ShapeEngine/Core/GameDef/GameVirtual.cs b/ShapeEngine/Core/GameDef/GameVirtual.cs
index 68d48c4f..6aba7105 100644
--- a/ShapeEngine/Core/GameDef/GameVirtual.cs
+++ b/ShapeEngine/Core/GameDef/GameVirtual.cs
@@ -239,6 +239,9 @@ protected virtual void OnWindowTopmostChanged(bool topmost)
{
}
+ ///
+ /// This function will be removed in a future version. Use instead.
+ ///
///
/// Allows modification of the mouse position before it's used for input processing.
///
@@ -246,8 +249,23 @@ protected virtual void OnWindowTopmostChanged(bool topmost)
/// The current mouse position.
/// The screen area rectangle.
/// The modified mouse position.
+ [Obsolete("Use ChangeMousePos(float, Vector2, Rect, out Vector2) instead.", error: false)]
protected virtual Vector2 ChangeMousePos(float dt, Vector2 mousePos, Rect screenArea) => mousePos;
+ ///
+ /// Allows modification of the mouse position before it's used for input processing.
+ ///
+ /// Delta time since the last frame.
+ /// The current mouse position.
+ /// The screen area rectangle.
+ /// The modified mouse position.
+ /// Whether the mouse position was modified and should be changed.
+ protected virtual bool ChangeMousePos(float dt, Vector2 mousePos, Rect screenArea, out Vector2 newMousePos)
+ {
+ newMousePos = mousePos;
+ return false;
+ }
+
///
/// Called when an input button is pressed.
///