Browse Source

chore: rename integer mode field names

(cherry picked from commit f52f982b1e9ce2f510f2c26c6119e79dbb5b20a0)
expikr 1 month ago
parent
commit
e5f8043037
2 changed files with 16 additions and 14 deletions
  1. 9 9
      src/events/SDL_mouse.c
  2. 7 5
      src/events/SDL_mouse_c.h

+ 9 - 9
src/events/SDL_mouse.c

@@ -239,9 +239,9 @@ static void SDLCALL SDL_MouseIntegerModeChanged(void *userdata, const char *name
     SDL_Mouse *mouse = (SDL_Mouse *)userdata;
 
     if (hint && *hint) {
-        mouse->integer_mode = (Uint8)SDL_atoi(hint);
+        mouse->integer_mode_flags = (Uint8)SDL_atoi(hint);
     } else {
-        mouse->integer_mode = 0;
+        mouse->integer_mode_flags = 0;
     }
 }
 
@@ -734,10 +734,10 @@ static void SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL
                 y *= mouse->normal_speed_scale;
             }
         }
-        if (mouse->integer_mode >= 1) {
+        if (mouse->integer_mode_flags & 1) {
             // Accumulate the fractional relative motion and only process the integer portion
-            mouse->xrel_frac = SDL_modff(mouse->xrel_frac + x, &x);
-            mouse->yrel_frac = SDL_modff(mouse->yrel_frac + y, &y);
+            mouse->integer_mode_residual_motion_x = SDL_modff(mouse->integer_mode_residual_motion_x + x, &x);
+            mouse->integer_mode_residual_motion_y = SDL_modff(mouse->integer_mode_residual_motion_y + y, &y);
         }
         xrel = x;
         yrel = y;
@@ -745,7 +745,7 @@ static void SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL
         y = (mouse->last_y + yrel);
         ConstrainMousePosition(mouse, window, &x, &y);
     } else {
-        if (mouse->integer_mode >= 1) {
+        if (mouse->integer_mode_flags & 1) {
             // Discard the fractional component from absolute coordinates
             x = SDL_truncf(x);
             y = SDL_truncf(y);
@@ -1023,9 +1023,9 @@ void SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseI
     }
 
     // Accumulate fractional wheel motion if integer mode is enabled
-    if (mouse->integer_mode >= 2) {
-        mouse->wheel_x_frac = SDL_modff(mouse->wheel_x_frac + x, &x);
-        mouse->wheel_y_frac = SDL_modff(mouse->wheel_y_frac + y, &y);
+    if (mouse->integer_mode_flags & 2) {
+        mouse->integer_mode_residual_scroll_x = SDL_modff(mouse->integer_mode_residual_scroll_x + x, &x);
+        mouse->integer_mode_residual_scroll_y = SDL_modff(mouse->integer_mode_residual_scroll_y + y, &y);
     }
 
     if (x == 0.0f && y == 0.0f) {

+ 7 - 5
src/events/SDL_mouse_c.h

@@ -91,6 +91,13 @@ typedef struct
     void (*ApplySystemScale)(void *internal, Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float *x, float *y);
     void *system_scale_data;
 
+    // integer mode data
+    Uint8 integer_mode_flags; // 1 to enable mouse quantization, 2 to enable wheel quantization
+    float integer_mode_residual_motion_x;
+    float integer_mode_residual_motion_y;
+    float integer_mode_residual_scroll_x;
+    float integer_mode_residual_scroll_y;
+
     // Data common to all mice
     SDL_Window *focus;
     float x;
@@ -98,13 +105,8 @@ typedef struct
     float x_accu;
     float y_accu;
     float last_x, last_y; // the last reported x and y coordinates
-    float xrel_frac;
-    float yrel_frac;
-    float wheel_x_frac;
-    float wheel_y_frac;
     double click_motion_x;
     double click_motion_y;
-    Uint8 integer_mode;
     bool has_position;
     bool relative_mode;
     bool relative_mode_warp_motion;