GetDeltaMouse () added. Returns a Vector2 with the difference between the current and previous position of the mouse.

Useful for creating camera scrolling, among others.
This commit is contained in:
Adrian Guerrero Vera 2021-05-28 21:08:34 +02:00
parent 470574517a
commit 6cb07d92f2
2 changed files with 14 additions and 0 deletions

View File

@ -434,6 +434,9 @@ typedef struct CoreData {
Vector2 offset; // Mouse offset
Vector2 scale; // Mouse scaling
Vector2 delta; // Mouse movement per frame
Vector2 previousPosition; // Previus frame position
int cursor; // Tracks current mouse cursor
bool cursorHidden; // Track if cursor is hidden
bool cursorOnScreen; // Tracks if cursor is inside client area
@ -3387,6 +3390,12 @@ Vector2 GetMousePosition(void)
return position;
}
// Mouse movement per frame XY
RLAPI Vector2 GetDeltaMouse(void)
{
return CORE.Input.Mouse.delta;
}
// Set mouse position XY
void SetMousePosition(int x, int y)
{
@ -4856,6 +4865,10 @@ static void PollInputEvents(void)
// NOTE: Mouse input events polling is done asynchronously in another pthread - EventThread()
// NOTE: Gamepad (Joystick) input events polling is done asynchonously in another pthread - GamepadThread()
#endif
CORE.Input.Mouse.delta.x = CORE.Input.Mouse.position.x - CORE.Input.Mouse.previousPosition.x;
CORE.Input.Mouse.delta.y = CORE.Input.Mouse.position.y - CORE.Input.Mouse.previousPosition.y;
CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.position;
}
// Copy back buffer to front buffers

View File

@ -1102,6 +1102,7 @@ RLAPI bool IsMouseButtonUp(int button); // Detect if a mou
RLAPI int GetMouseX(void); // Returns mouse position X
RLAPI int GetMouseY(void); // Returns mouse position Y
RLAPI Vector2 GetMousePosition(void); // Returns mouse position XY
RLAPI Vector2 GetDeltaMouse(void); // Mouse movement per frame XY
RLAPI void SetMousePosition(int x, int y); // Set mouse position XY
RLAPI void SetMouseOffset(int offsetX, int offsetY); // Set mouse offset
RLAPI void SetMouseScale(float scaleX, float scaleY); // Set mouse scaling