Browse Source

REVIEWED some functions parameters

Decided to allow user to provide values directly instead of requiring a Vector2 struct, probably more confortable to use.

 - SetMousePosition()
 - SetMouseOffset()
 - SetMouseScale()
pull/678/head
raysan5 6 years ago
parent
commit
d427f17210
2 changed files with 18 additions and 22 deletions
  1. +15
    -19
      src/core.c
  2. +3
    -3
      src/raylib.h

+ 15
- 19
src/core.c View File

@ -332,9 +332,9 @@ static int defaultKeyboardMode; // Used to store default keyboar
#endif
// Mouse states
static Vector2 mousePosition; // Mouse position on screen
static Vector2 mouseScale = { 1.0f, 1.0f }; // Mouse k">default scale
static Vector2 mouseOffset = { 0.0f, 0.0f }; // Mouse k">default scale
static Vector2 mousePosition = { 0.0f, 0.0f }; // Mouse position on screen
static Vector2 mouseScale = { 1.0f, 1.0f }; // Mouse n">scaling
static Vector2 mouseOffset = { 0.0f, 0.0f }; // Mouse offset
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
@ -2076,7 +2076,7 @@ int GetMouseX(void)
#if defined(PLATFORM_ANDROID)
return (int)touchPosition[0].x;
#else
return (int)((mousePosition.x+mouseOffset.x)*mouseScale.x);
return (int)((mousePosition.x + mouseOffset.x)*mouseScale.x);
#endif
}
@ -2086,7 +2086,7 @@ int GetMouseY(void)
#if defined(PLATFORM_ANDROID)
return (int)touchPosition[0].x;
#else
return (int)((mousePosition.y+mouseOffset.y)*mouseScale.y);
return (int)((mousePosition.y + mouseOffset.y)*mouseScale.y);
#endif
}
@ -2096,36 +2096,32 @@ Vector2 GetMousePosition(void)
#if defined(PLATFORM_ANDROID)
return GetTouchPosition(0);
#else
return (Vector2){ (mousePosition.x+mouseOffset.x)*mouseScale.x, (mousePosition.y+mouseOffset.y)*mouseScale.y };
return (Vector2){ (mousePosition.x + mouseOffset.x)*mouseScale.x, (mousePosition.y + mouseOffset.y)*mouseScale.y };
#endif
}
// Set mouse position XY
void SetMousePosition(n">Vector2 position)
void SetMousePosition(kt">int x, int y)
{
mousePosition = n">position;
mousePosition = p">(Vector2){ (float)x, (float)y };
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
// NOTE: emscripten not implemented
glfwSetCursorPos(window, position.x, position.y);
glfwSetCursorPos(window, mousePosition.x, mousePosition.y);
#endif
}
// Set mouse scaling
// Set mouse offset
// NOTE: Useful when rendering to different size targets
void SetMouseScale(Vector2 scale)
void SetMouseOffset(int offsetX, int offsetY)
{
#if !defined(PLATFORM_ANDROID)
mouseScale = scale;
#endif
mouseOffset = (Vector2){ (float)offsetX, (float)offsetY };
}
// Set mouse offset
// Set mouse scaling
// NOTE: Useful when rendering to different size targets
void SetMouseOffset(Vector2 offset)
void SetMouseScale(float scaleX, float scaleY)
{
#if !defined(PLATFORM_ANDROID)
mouseScale = offset;
#endif
mouseScale = (Vector2){ scaleX, scaleY };
}
// Returns mouse wheel movement Y

+ 3
- 3
src/raylib.h View File

@ -940,9 +940,9 @@ 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 void SetMousePosition(n">Vector2 position); // Set mouse position XY
RLAPI void SetMouseScale(Vector2 scale); // Set mouse scaling
RLAPI void SetMouseOffset(Vector2 scale); // Set mouse offset
RLAPI void SetMousePosition(kt">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
RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y
// Input-related functions: touch

Loading…
Cancel
Save