Browse Source

mouse: Return float movement for precise scrolling where possible (#1397)

Doyle 4 years ago
parent
commit
b29311c7ca

+ 1 - 1
projects/Geany/raylib.c.tags

@@ -103,7 +103,7 @@ GetMousePosition|Vector2|(void);|
 SetMousePosition|void|(int x, int y);|
 SetMousePosition|void|(int x, int y);|
 SetMouseOffset|void|(int offsetX, int offsetY);|
 SetMouseOffset|void|(int offsetX, int offsetY);|
 SetMouseScale|void|(float scaleX, float scaleY);|
 SetMouseScale|void|(float scaleX, float scaleY);|
-GetMouseWheelMove|int|(void);|
+GetMouseWheelMove|float|(void);|
 GetTouchX|int|(void);|
 GetTouchX|int|(void);|
 GetTouchY|int|(void);|
 GetTouchY|int|(void);|
 GetTouchPosition|Vector2|(int index);|
 GetTouchPosition|Vector2|(int index);|

+ 1 - 1
projects/Notepad++/c_raylib.xml

@@ -436,7 +436,7 @@
             </Overload>
             </Overload>
         </KeyWord>
         </KeyWord>
         <KeyWord name="GetMouseWheelMove" func="yes">
         <KeyWord name="GetMouseWheelMove" func="yes">
-            <Overload retVal="int" descr="Returns mouse wheel movement Y"></Overload>
+            <Overload retVal="float" descr="Returns mouse wheel movement Y"></Overload>
         </KeyWord>
         </KeyWord>
 
 
         <!-- Input-related functions: touch -->
         <!-- Input-related functions: touch -->

+ 1 - 1
projects/Notepad++/raylib_npp_parser/raylib_npp.xml

@@ -571,7 +571,7 @@
             </Overload>
             </Overload>
         </KeyWord>
         </KeyWord>
         <KeyWord name="GetMouseWheelMove" func="yes">
         <KeyWord name="GetMouseWheelMove" func="yes">
-            <Overload retVal="int" descr="Returns mouse wheel movement Y"></Overload>
+            <Overload retVal="float" descr="Returns mouse wheel movement Y"></Overload>
         </KeyWord>
         </KeyWord>
 
 
         <!-- Input-related functions: touch -->
         <!-- Input-related functions: touch -->

+ 1 - 1
projects/Notepad++/raylib_npp_parser/raylib_to_parse.h

@@ -147,7 +147,7 @@ RLAPI Vector2 GetMousePosition(void);                         // Returns mouse p
 RLAPI void SetMousePosition(int x, int y);                    // Set mouse position XY
 RLAPI void SetMousePosition(int x, int y);                    // Set mouse position XY
 RLAPI void SetMouseOffset(int offsetX, int offsetY);          // Set mouse offset
 RLAPI void SetMouseOffset(int offsetX, int offsetY);          // Set mouse offset
 RLAPI void SetMouseScale(float scaleX, float scaleY);         // Set mouse scaling
 RLAPI void SetMouseScale(float scaleX, float scaleY);         // Set mouse scaling
-RLAPI int GetMouseWheelMove(void);                            // Returns mouse wheel movement Y
+RLAPI float GetMouseWheelMove(void);                          // Returns mouse wheel movement Y
 
 
 // Input-related functions: touch
 // Input-related functions: touch
 RLAPI int GetTouchX(void);                                    // Returns touch position X for touch point 0 (relative to screen size)
 RLAPI int GetTouchX(void);                                    // Returns touch position X for touch point 0 (relative to screen size)

+ 2 - 2
projects/VS2017.UWP/raylib.App.UWP/App.cpp

@@ -213,7 +213,7 @@ void App::GameLoop()
         DisableCursor();
         DisableCursor();
     }
     }
 
 
-    static int pos = 0;
+    static float pos = 0;
     pos -= GetMouseWheelMove();
     pos -= GetMouseWheelMove();
     //----------------------------------------------------------------------------------
     //----------------------------------------------------------------------------------
 
 
@@ -235,7 +235,7 @@ void App::GameLoop()
 		if (IsKeyDown(KEY_BACKSPACE)) DrawRectangle(280, 250, 20, 20, BLACK);
 		if (IsKeyDown(KEY_BACKSPACE)) DrawRectangle(280, 250, 20, 20, BLACK);
 		if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) DrawRectangle(280, 250, 20, 20, BLACK);
 		if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) DrawRectangle(280, 250, 20, 20, BLACK);
 
 
-		DrawRectangle(280, pos + 50, 20, 20, BLACK);
+		DrawRectangle(280, (int)pos + 50, 20, 20, BLACK);
 		DrawRectangle(250, 280 + (gTime++ % 60), 10, 10, PURPLE);
 		DrawRectangle(250, 280 + (gTime++ % 60), 10, 10, PURPLE);
 
 
 	EndDrawing();
 	EndDrawing();

+ 2 - 2
src/camera.h

@@ -236,7 +236,7 @@ static void DisableCursor() {}      // Lock cursor
 static int IsKeyDown(int key) { return 0; }
 static int IsKeyDown(int key) { return 0; }
 
 
 static int IsMouseButtonDown(int button) { return 0;}
 static int IsMouseButtonDown(int button) { return 0;}
-static int GetMouseWheelMove() { return 0; }
+static float GetMouseWheelMove() { return 0.f; }
 static Vector2 GetMousePosition() { return (Vector2){ 0.0f, 0.0f }; }
 static Vector2 GetMousePosition() { return (Vector2){ 0.0f, 0.0f }; }
 #endif
 #endif
 
 
@@ -285,7 +285,7 @@ void UpdateCamera(Camera *camera)
     // Mouse movement detection
     // Mouse movement detection
     Vector2 mousePositionDelta = { 0.0f, 0.0f };
     Vector2 mousePositionDelta = { 0.0f, 0.0f };
     Vector2 mousePosition = GetMousePosition();
     Vector2 mousePosition = GetMousePosition();
-    int mouseWheelMove = GetMouseWheelMove();
+    float mouseWheelMove = GetMouseWheelMove();
 
 
     // Keys input detection
     // Keys input detection
     // TODO: Input detection is raylib-dependant, it could be moved outside the module
     // TODO: Input detection is raylib-dependant, it could be moved outside the module

+ 10 - 10
src/core.c

@@ -428,8 +428,8 @@ typedef struct CoreData {
 
 
             char currentButtonState[3];     // Registers current mouse button state
             char currentButtonState[3];     // Registers current mouse button state
             char previousButtonState[3];    // Registers previous mouse button state
             char previousButtonState[3];    // Registers previous mouse button state
-            int currentWheelMove;           // Registers current mouse wheel variation
-            int previousWheelMove;          // Registers previous mouse wheel variation
+            float currentWheelMove;         // Registers current mouse wheel variation
+            float previousWheelMove;        // Registers previous mouse wheel variation
 #if defined(PLATFORM_RPI) || defined(PLATFORM_DRM)
 #if defined(PLATFORM_RPI) || defined(PLATFORM_DRM)
             char currentButtonStateEvdev[3];    // Holds the new mouse state for the next polling event to grab (Can't be written directly due to multithreading, app could miss the update)
             char currentButtonStateEvdev[3];    // Holds the new mouse state for the next polling event to grab (Can't be written directly due to multithreading, app could miss the update)
 #endif
 #endif
@@ -2722,12 +2722,12 @@ void SetMouseScale(float scaleX, float scaleY)
 }
 }
 
 
 // Returns mouse wheel movement Y
 // Returns mouse wheel movement Y
-int GetMouseWheelMove(void)
+float GetMouseWheelMove(void)
 {
 {
 #if defined(PLATFORM_ANDROID)
 #if defined(PLATFORM_ANDROID)
-    return 0;
+    return 0.f;
 #elif defined(PLATFORM_WEB)
 #elif defined(PLATFORM_WEB)
-    return CORE.Input.Mouse.previousWheelMove/100;
+    return CORE.Input.Mouse.previousWheelMove/100.f;
 #else
 #else
     return CORE.Input.Mouse.previousWheelMove;
     return CORE.Input.Mouse.previousWheelMove;
 #endif
 #endif
@@ -3896,7 +3896,7 @@ static void PollInputEvents(void)
 
 
     // Register previous mouse states
     // Register previous mouse states
     CORE.Input.Mouse.previousWheelMove = CORE.Input.Mouse.currentWheelMove;
     CORE.Input.Mouse.previousWheelMove = CORE.Input.Mouse.currentWheelMove;
-    CORE.Input.Mouse.currentWheelMove = 0;
+    CORE.Input.Mouse.currentWheelMove = 0.f;
     for (int i = 0; i < 3; i++)
     for (int i = 0; i < 3; i++)
     {
     {
         CORE.Input.Mouse.previousButtonState[i] = CORE.Input.Mouse.currentButtonState[i];
         CORE.Input.Mouse.previousButtonState[i] = CORE.Input.Mouse.currentButtonState[i];
@@ -3918,7 +3918,7 @@ static void PollInputEvents(void)
 
 
     // Register previous mouse states
     // Register previous mouse states
     CORE.Input.Mouse.previousWheelMove = CORE.Input.Mouse.currentWheelMove;
     CORE.Input.Mouse.previousWheelMove = CORE.Input.Mouse.currentWheelMove;
-    CORE.Input.Mouse.currentWheelMove = 0;
+    CORE.Input.Mouse.currentWheelMove = 0.f;
 
 
     for (int i = 0; i < 3; i++) CORE.Input.Mouse.previousButtonState[i] = CORE.Input.Mouse.currentButtonState[i];
     for (int i = 0; i < 3; i++) CORE.Input.Mouse.previousButtonState[i] = CORE.Input.Mouse.currentButtonState[i];
 #endif  // PLATFORM_UWP
 #endif  // PLATFORM_UWP
@@ -3934,7 +3934,7 @@ static void PollInputEvents(void)
 
 
     // Register previous mouse wheel state
     // Register previous mouse wheel state
     CORE.Input.Mouse.previousWheelMove = CORE.Input.Mouse.currentWheelMove;
     CORE.Input.Mouse.previousWheelMove = CORE.Input.Mouse.currentWheelMove;
-    CORE.Input.Mouse.currentWheelMove = 0;
+    CORE.Input.Mouse.currentWheelMove = 0.f;
 #endif
 #endif
 
 
     // Register previous touch states
     // Register previous touch states
@@ -4151,7 +4151,7 @@ static void ErrorCallback(int error, const char *description)
 // GLFW3 Srolling Callback, runs on mouse wheel
 // GLFW3 Srolling Callback, runs on mouse wheel
 static void ScrollCallback(GLFWwindow *window, double xoffset, double yoffset)
 static void ScrollCallback(GLFWwindow *window, double xoffset, double yoffset)
 {
 {
-    CORE.Input.Mouse.currentWheelMove = (int)yoffset;
+    CORE.Input.Mouse.currentWheelMove = (float)yoffset;
 }
 }
 
 
 // GLFW3 Keyboard Callback, runs on key pressed
 // GLFW3 Keyboard Callback, runs on key pressed
@@ -5520,7 +5520,7 @@ void UWPSetMouseSetPosFunc(UWPMouseSetPosFunc func) { uwpMouseSetPosFunc = func;
 
 
 void *UWPGetCoreWindowPtr() { return uwpCoreWindow; }
 void *UWPGetCoreWindowPtr() { return uwpCoreWindow; }
 void UWPSetCoreWindowPtr(void* ptr) { uwpCoreWindow = ptr; }
 void UWPSetCoreWindowPtr(void* ptr) { uwpCoreWindow = ptr; }
-void UWPMouseWheelEvent(int deltaY) { CORE.Input.Mouse.currentWheelMove = (int)deltaY; }
+void UWPMouseWheelEvent(int deltaY) { CORE.Input.Mouse.currentWheelMove = (float)deltaY; }
 
 
 void UWPKeyDownEvent(int key, bool down, bool controlKey)
 void UWPKeyDownEvent(int key, bool down, bool controlKey)
 {
 {

+ 1 - 1
src/raylib.h

@@ -1015,7 +1015,7 @@ RLAPI Vector2 GetMousePosition(void);                         // Returns mouse p
 RLAPI void SetMousePosition(int x, int y);                    // Set mouse position XY
 RLAPI void SetMousePosition(int x, int y);                    // Set mouse position XY
 RLAPI void SetMouseOffset(int offsetX, int offsetY);          // Set mouse offset
 RLAPI void SetMouseOffset(int offsetX, int offsetY);          // Set mouse offset
 RLAPI void SetMouseScale(float scaleX, float scaleY);         // Set mouse scaling
 RLAPI void SetMouseScale(float scaleX, float scaleY);         // Set mouse scaling
-RLAPI int GetMouseWheelMove(void);                            // Returns mouse wheel movement Y
+RLAPI float GetMouseWheelMove(void);                          // Returns mouse wheel movement Y
 
 
 // Input-related functions: touch
 // Input-related functions: touch
 RLAPI int GetTouchX(void);                                    // Returns touch position X for touch point 0 (relative to screen size)
 RLAPI int GetTouchX(void);                                    // Returns touch position X for touch point 0 (relative to screen size)