Browse Source

Added new functions

- SetWindowSize() to scale Windows in runtime
- SetMouseScale() to scale mouse input, useful when rendering game to a
RenderTexture2D that will be scaled to Window size (used on rFXGen tool)
pull/508/head
Ray San 6 years ago
parent
commit
df50eada53
2 changed files with 25 additions and 4 deletions
  1. +23
    -4
      src/core.c
  2. +2
    -0
      src/raylib.h

+ 23
- 4
src/core.c View File

@ -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 sa">"";
if (!dot || dot == fileName) return nb">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)p">(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)p">(mousePosition.y*mouseScale);
#endif
}
@ -1668,7 +1678,7 @@ Vector2 GetMousePosition(void)
#if defined(PLATFORM_ANDROID)
return GetTouchPosition(0);
#else
return mousePosition;
return p">(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)
{

+ 2
- 0
src/raylib.h View File

@ -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

Loading…
Cancel
Save