From 893329886451706033d8af4901cf7c251903a136 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Wed, 2 Jan 2019 10:14:55 +0000 Subject: [PATCH 1/3] Added SetMouseOffset - Changed mouseScale to Vector2. - Added SetMouseOffset to change XY of mouseScale. --- src/core.c | 23 ++++++++++++++++------- src/raylib.h | 1 + 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/core.c b/src/core.c index 6c2713e1..c4f410e4 100644 --- a/src/core.c +++ b/src/core.c @@ -333,7 +333,7 @@ static int defaultKeyboardMode; // Used to store default keyboar // Mouse states static Vector2 mousePosition; // Mouse position on screen -static float mouseScale = 1.0f; // Mouse default scale +static Vector2 mouseScale = { 1.0f }; // Mouse default scale static bool cursorHidden = false; // Track if cursor is hidden static bool cursorOnScreen = false; // Tracks if cursor is inside client area static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen @@ -2075,7 +2075,7 @@ int GetMouseX(void) #if defined(PLATFORM_ANDROID) return (int)touchPosition[0].x; #else - return (int)(mousePosition.x*mouseScale); + return (int)(mousePosition.x*mouseScale.x); #endif } @@ -2085,7 +2085,7 @@ int GetMouseY(void) #if defined(PLATFORM_ANDROID) return (int)touchPosition[0].x; #else - return (int)(mousePosition.y*mouseScale); + return (int)(mousePosition.y*mouseScale.y); #endif } @@ -2095,7 +2095,7 @@ Vector2 GetMousePosition(void) #if defined(PLATFORM_ANDROID) return GetTouchPosition(0); #else - return (Vector2){ mousePosition.x*mouseScale, mousePosition.y*mouseScale }; + return (Vector2){ mousePosition.x*mouseScale.x, mousePosition.y*mouseScale.y }; #endif } @@ -2114,7 +2114,16 @@ void SetMousePosition(Vector2 position) void SetMouseScale(float scale) { #if !defined(PLATFORM_ANDROID) - mouseScale = scale; + mouseScale = (Vector2){ scale }; +#endif +} + +// Set mouse scaling +// NOTE: Useful when rendering to different size targets +void SetMouseOffset(Vector2 offset) +{ +#if !defined(PLATFORM_ANDROID) + mouseScale = offset; #endif } @@ -4225,10 +4234,10 @@ static void *EventThread(void *arg) // Screen confinement if (mousePosition.x < 0) mousePosition.x = 0; - if (mousePosition.x > screenWidth/mouseScale) mousePosition.x = screenWidth/mouseScale; + if (mousePosition.x > screenWidth/mouseScale.x) mousePosition.x = screenWidth/mouseScale.x; if (mousePosition.y < 0) mousePosition.y = 0; - if (mousePosition.y > screenHeight/mouseScale) mousePosition.y = screenHeight/mouseScale; + if (mousePosition.y > screenHeight/mouseScale) mousePosition.y = screenHeight/mouseScale.y; // Gesture update if (GestureNeedsUpdate) diff --git a/src/raylib.h b/src/raylib.h index 0e9e0155..9deb8f42 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -942,6 +942,7 @@ RLAPI int GetMouseY(void); // Returns mouse p RLAPI Vector2 GetMousePosition(void); // Returns mouse position XY RLAPI void SetMousePosition(Vector2 position); // Set mouse position XY RLAPI void SetMouseScale(float scale); // Set mouse scaling +RLAPI void SetMouseOffset(Vector2 scale); // Set mouse scaling XY RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y // Input-related functions: touch From a707574f33467f81e8e300e09db23269bf2c1b98 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Wed, 2 Jan 2019 10:46:19 +0000 Subject: [PATCH 2/3] Default mouseScale fixed - Didn't set X and Y values correctly. --- src/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core.c b/src/core.c index c4f410e4..6c886024 100644 --- a/src/core.c +++ b/src/core.c @@ -333,7 +333,7 @@ static int defaultKeyboardMode; // Used to store default keyboar // Mouse states static Vector2 mousePosition; // Mouse position on screen -static Vector2 mouseScale = { 1.0f }; // Mouse default scale +static Vector2 mouseScale = { 1.0f, 1.0f }; // Mouse default scale static bool cursorHidden = false; // Track if cursor is hidden static bool cursorOnScreen = false; // Tracks if cursor is inside client area static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen @@ -2114,7 +2114,7 @@ void SetMousePosition(Vector2 position) void SetMouseScale(float scale) { #if !defined(PLATFORM_ANDROID) - mouseScale = (Vector2){ scale }; + mouseScale = (Vector2){ scale, scale }; #endif } From f9c43dc379165927e847981ec9e14eb5d3b14534 Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Wed, 2 Jan 2019 19:09:34 +0000 Subject: [PATCH 3/3] Mouse functions changed - SetMouseScale changed to take in a Vector2. - Added mouseOffset global which is used in mouse read functions. --- src/core.c | 15 ++++++++------- src/raylib.h | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/core.c b/src/core.c index 6c886024..c013a288 100644 --- a/src/core.c +++ b/src/core.c @@ -334,6 +334,7 @@ static int defaultKeyboardMode; // Used to store default keyboar // Mouse states static Vector2 mousePosition; // Mouse position on screen static Vector2 mouseScale = { 1.0f, 1.0f }; // Mouse default scale +static Vector2 mouseOffset = { 0.0f, 0.0f }; // Mouse default scale static bool cursorHidden = false; // Track if cursor is hidden static bool cursorOnScreen = false; // Tracks if cursor is inside client area static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen @@ -2075,7 +2076,7 @@ int GetMouseX(void) #if defined(PLATFORM_ANDROID) return (int)touchPosition[0].x; #else - return (int)(mousePosition.x*mouseScale.x); + return (int)((mousePosition.x+mouseOffset.x)*mouseScale.x); #endif } @@ -2085,7 +2086,7 @@ int GetMouseY(void) #if defined(PLATFORM_ANDROID) return (int)touchPosition[0].x; #else - return (int)(mousePosition.y*mouseScale.y); + return (int)((mousePosition.y+mouseOffset.y)*mouseScale.y); #endif } @@ -2095,7 +2096,7 @@ Vector2 GetMousePosition(void) #if defined(PLATFORM_ANDROID) return GetTouchPosition(0); #else - return (Vector2){ mousePosition.x*mouseScale.x, mousePosition.y*mouseScale.y }; + return (Vector2){ (mousePosition.x+mouseOffset.x)*mouseScale.x, (mousePosition.y+mouseOffset.y)*mouseScale.y }; #endif } @@ -2111,14 +2112,14 @@ void SetMousePosition(Vector2 position) // Set mouse scaling // NOTE: Useful when rendering to different size targets -void SetMouseScale(float scale) +void SetMouseScale(Vector2 scale) { #if !defined(PLATFORM_ANDROID) - mouseScale = (Vector2){ scale, scale }; + mouseScale = scale; #endif } -// Set mouse scaling +// Set mouse offset // NOTE: Useful when rendering to different size targets void SetMouseOffset(Vector2 offset) { @@ -4237,7 +4238,7 @@ static void *EventThread(void *arg) if (mousePosition.x > screenWidth/mouseScale.x) mousePosition.x = screenWidth/mouseScale.x; if (mousePosition.y < 0) mousePosition.y = 0; - if (mousePosition.y > screenHeight/mouseScale) mousePosition.y = screenHeight/mouseScale.y; + if (mousePosition.y > screenHeight/mouseScale.y) mousePosition.y = screenHeight/mouseScale.y; // Gesture update if (GestureNeedsUpdate) diff --git a/src/raylib.h b/src/raylib.h index 9deb8f42..2fef4fc8 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -941,8 +941,8 @@ RLAPI int GetMouseX(void); // Returns mouse p RLAPI int GetMouseY(void); // Returns mouse position Y RLAPI Vector2 GetMousePosition(void); // Returns mouse position XY RLAPI void SetMousePosition(Vector2 position); // Set mouse position XY -RLAPI void SetMouseScale(float scale); // Set mouse scaling -RLAPI void SetMouseOffset(Vector2 scale); // Set mouse scaling XY +RLAPI void SetMouseScale(Vector2 scale); // Set mouse scaling +RLAPI void SetMouseOffset(Vector2 scale); // Set mouse offset RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y // Input-related functions: touch