src/events/SDL_mouse.c
changeset 11300 68a80d7afec3
parent 11284 3db78361e751
child 11313 14d04f0a4914
     1.1 --- a/src/events/SDL_mouse.c	Mon Aug 14 20:45:14 2017 -0700
     1.2 +++ b/src/events/SDL_mouse.c	Mon Aug 14 21:28:04 2017 -0700
     1.3 @@ -508,10 +508,11 @@
     1.4  }
     1.5  
     1.6  int
     1.7 -SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction)
     1.8 +SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
     1.9  {
    1.10      SDL_Mouse *mouse = SDL_GetMouse();
    1.11      int posted;
    1.12 +    int integral_x, integral_y;
    1.13  
    1.14      if (window) {
    1.15          SDL_SetMouseFocus(window);
    1.16 @@ -521,6 +522,26 @@
    1.17          return 0;
    1.18      }
    1.19  
    1.20 +    mouse->accumulated_wheel_x += x;
    1.21 +    if (mouse->accumulated_wheel_x > 0) {
    1.22 +        integral_x = (int)SDL_floor(mouse->accumulated_wheel_x);
    1.23 +    } else if (mouse->accumulated_wheel_x < 0) {
    1.24 +        integral_x = (int)SDL_ceil(mouse->accumulated_wheel_x);
    1.25 +    } else {
    1.26 +        integral_x = 0;
    1.27 +    }
    1.28 +    mouse->accumulated_wheel_x -= integral_x;
    1.29 +
    1.30 +    mouse->accumulated_wheel_y += y;
    1.31 +    if (mouse->accumulated_wheel_y > 0) {
    1.32 +        integral_y = (int)SDL_floor(mouse->accumulated_wheel_y);
    1.33 +    } else if (mouse->accumulated_wheel_y < 0) {
    1.34 +        integral_y = (int)SDL_ceil(mouse->accumulated_wheel_y);
    1.35 +    } else {
    1.36 +        integral_y = 0;
    1.37 +    }
    1.38 +    mouse->accumulated_wheel_y -= integral_y;
    1.39 +
    1.40      /* Post the event, if desired */
    1.41      posted = 0;
    1.42      if (SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE) {
    1.43 @@ -528,8 +549,12 @@
    1.44          event.type = SDL_MOUSEWHEEL;
    1.45          event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
    1.46          event.wheel.which = mouseID;
    1.47 -        event.wheel.x = x;
    1.48 -        event.wheel.y = y;
    1.49 +#if 0 /* Uncomment this when it goes in for SDL 2.1 */
    1.50 +        event.wheel.preciseX = x;
    1.51 +        event.wheel.preciseY = y;
    1.52 +#endif
    1.53 +        event.wheel.x = integral_x;
    1.54 +        event.wheel.y = integral_y;
    1.55          event.wheel.direction = (Uint32)direction;
    1.56          posted = (SDL_PushEvent(&event) > 0);
    1.57      }