diff --git a/src/core.c b/src/core.c index 24364775..f4fdf78b 100644 --- a/src/core.c +++ b/src/core.c @@ -326,6 +326,7 @@ static int lastGamepadButtonPressed = -1; // Register last gamepad button pres static int gamepadAxisCount = 0; // Register number of available gamepad axis static Vector2 mousePosition; // Mouse position on screen +static float mouseScale = 1.0f; // Mouse default scale #if defined(PLATFORM_WEB) static bool toggleCursorLock = false; // Ask for cursor pointer lock on next click @@ -736,6 +737,15 @@ void SetWindowMinSize(int width, int height) #endif } +// Set window dimensions +void SetWindowSize(int width, int height) +{ +#if defined(PLATFORM_DESKTOP) + glfwSetWindowSize(window, width, height); +#endif +} + + // Get current screen width int GetScreenWidth(void) { @@ -1253,7 +1263,7 @@ const char *GetExtension(const char *fileName) { const char *dot = strrchr(fileName, '.'); - if (!dot || dot == fileName) return ""; + if (!dot || dot == fileName) return NULL; return (dot + 1); } @@ -1648,7 +1658,7 @@ int GetMouseX(void) #if defined(PLATFORM_ANDROID) return (int)touchPosition[0].x; #else - return (int)mousePosition.x; + return (int)(mousePosition.x*mouseScale); #endif } @@ -1658,7 +1668,7 @@ int GetMouseY(void) #if defined(PLATFORM_ANDROID) return (int)touchPosition[0].x; #else - return (int)mousePosition.y; + return (int)(mousePosition.y*mouseScale); #endif } @@ -1668,7 +1678,7 @@ Vector2 GetMousePosition(void) #if defined(PLATFORM_ANDROID) return GetTouchPosition(0); #else - return mousePosition; + return (Vector2){ mousePosition.x*mouseScale, mousePosition.y*mouseScale }; #endif } @@ -1682,6 +1692,15 @@ void SetMousePosition(Vector2 position) #endif } +// Set mouse scaling +// NOTE: Useful when rendering to different size targets +void SetMouseScale(float scale) +{ +#if !defined(PLATFORM_ANDROID) + mouseScale = scale; +#endif +} + // Returns mouse wheel movement Y int GetMouseWheelMove(void) { diff --git a/src/raylib.h b/src/raylib.h index c1d383fd..253f73fb 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -703,6 +703,7 @@ RLAPI void SetWindowTitle(const char *title); // Set title f RLAPI void SetWindowPosition(int x, int y); // Set window position on screen (only PLATFORM_DESKTOP) RLAPI void SetWindowMonitor(int monitor); // Set monitor for the current window (fullscreen mode) RLAPI void SetWindowMinSize(int width, int height); // Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE) +RLAPI void SetWindowSize(int width, int height); // Set window dimensions RLAPI int GetScreenWidth(void); // Get current screen width RLAPI int GetScreenHeight(void); // Get current screen height @@ -805,6 +806,7 @@ 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 int GetMouseWheelMove(void); // Returns mouse wheel movement Y // Input-related functions: touch