Skip to content

Commit

Permalink
add in support for passing down the "natural" (or flipped) scrolling …
Browse files Browse the repository at this point in the history
…direction in the MouseWheelEvent event
  • Loading branch information
urkle committed Nov 24, 2014
1 parent 70438be commit 5b5823e
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 15 deletions.
1 change: 1 addition & 0 deletions include/SDL_events.h
Expand Up @@ -260,6 +260,7 @@ typedef struct SDL_MouseWheelEvent
Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
Sint32 x; /**< The amount scrolled horizontally, positive to the right and negative to the left */
Sint32 y; /**< The amount scrolled vertically, positive away from the user and negative toward the user */
Uint32 direction; /**< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back */
} SDL_MouseWheelEvent;

/**
Expand Down
9 changes: 9 additions & 0 deletions include/SDL_mouse.h
Expand Up @@ -60,6 +60,15 @@ typedef enum
SDL_NUM_SYSTEM_CURSORS
} SDL_SystemCursor;

/**
* \brief Scroll direction types for the Scroll event
*/
typedef enum
{
SDL_MOUSEWHEEL_NORMAL, /**< The scroll direction is normal */
SDL_MOUSEWHEEL_FLIPPED /**< The scroll direction is flipped / natural */
} SDL_MouseWheelDirection;

/* Function prototypes */

/**
Expand Down
4 changes: 2 additions & 2 deletions src/core/linux/SDL_evdev.c
Expand Up @@ -681,10 +681,10 @@ SDL_EVDEV_Poll(void)
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_TRUE, 0, events[i].value);
break;
case REL_WHEEL:
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, 0, events[i].value);
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, 0, events[i].value, SDL_MOUSEWHEEL_NORMAL);
break;
case REL_HWHEEL:
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, events[i].value, 0);
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, events[i].value, 0, SDL_MOUSEWHEEL_NORMAL);
break;
default:
break;
Expand Down
3 changes: 2 additions & 1 deletion src/events/SDL_mouse.c
Expand Up @@ -397,7 +397,7 @@ SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8
}

int
SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y)
SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction)
{
SDL_Mouse *mouse = SDL_GetMouse();
int posted;
Expand All @@ -419,6 +419,7 @@ SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y)
event.wheel.which = mouseID;
event.wheel.x = x;
event.wheel.y = y;
event.wheel.direction = (Uint32)direction;
posted = (SDL_PushEvent(&event) > 0);
}
return posted;
Expand Down
2 changes: 1 addition & 1 deletion src/events/SDL_mouse_c.h
Expand Up @@ -120,7 +120,7 @@ extern int SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int rel
extern int SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button);

/* Send a mouse wheel event */
extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y);
extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction);

/* Shutdown the mouse subsystem */
extern void SDL_MouseQuit(void);
Expand Down
2 changes: 1 addition & 1 deletion src/main/haiku/SDL_BApp.h
Expand Up @@ -254,7 +254,7 @@ class SDL_BApp : public BApplication {
return;
}
win = GetSDLWindow(winID);
SDL_SendMouseWheel(win, 0, xTicks, yTicks);
SDL_SendMouseWheel(win, 0, xTicks, yTicks, SDL_MOUSEWHEEL_NORMAL);
}

void _HandleKey(BMessage *msg) {
Expand Down
9 changes: 8 additions & 1 deletion src/video/cocoa/SDL_cocoamouse.m
Expand Up @@ -399,6 +399,13 @@ + (NSCursor *)invisibleCursor

float x = -[event deltaX];
float y = [event deltaY];
SDL_MouseWheelDirection direction = SDL_MOUSEWHEEL_NORMAL;

if ([event respondsToSelector:@selector(isDirectionInvertedFromDevice)]) {
if ([event isDirectionInvertedFromDevice] == YES) {
direction = SDL_MOUSEWHEEL_FLIPPED;
}
}

if (x > 0) {
x += 0.9f;
Expand All @@ -410,7 +417,7 @@ + (NSCursor *)invisibleCursor
} else if (y < 0) {
y -= 0.9f;
}
SDL_SendMouseWheel(window, mouse->mouseID, (int)x, (int)y);
SDL_SendMouseWheel(window, mouse->mouseID, (int)x, (int)y, direction);
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/video/mir/SDL_mirevents.c
Expand Up @@ -137,7 +137,7 @@ HandleTouchMotion(int device_id, int source_id, float x, float y, float pressure
static void
HandleMouseScroll(SDL_Window* sdl_window, int hscroll, int vscroll)
{
SDL_SendMouseWheel(sdl_window, 0, hscroll, vscroll);
SDL_SendMouseWheel(sdl_window, 0, hscroll, vscroll, SDL_MOUSEWHEEL_NORMAL);
}

static void
Expand Down
2 changes: 1 addition & 1 deletion src/video/nacl/SDL_naclevents.c
Expand Up @@ -357,7 +357,7 @@ void NACL_PumpEvents(_THIS) {
case PP_INPUTEVENT_TYPE_WHEEL:
/* FIXME: GetTicks provides high resolution scroll events */
fp = driverdata->ppb_wheel_input_event->GetDelta(event);
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, (int) fp.x, (int) fp.y);
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, (int) fp.x, (int) fp.y, SDL_MOUSEWHEEL_NORMAL);
break;

case PP_INPUTEVENT_TYPE_MOUSEENTER:
Expand Down
2 changes: 1 addition & 1 deletion src/video/wayland/SDL_waylandevents.c
Expand Up @@ -184,7 +184,7 @@ pointer_handle_axis(void *data, struct wl_pointer *pointer,
return;
}

SDL_SendMouseWheel(window->sdlwindow, 0, x, y);
SDL_SendMouseWheel(window->sdlwindow, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/video/windows/SDL_windowsevents.c
Expand Up @@ -498,12 +498,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
s_AccumulatedMotion += GET_WHEEL_DELTA_WPARAM(wParam);
if (s_AccumulatedMotion > 0) {
while (s_AccumulatedMotion >= WHEEL_DELTA) {
SDL_SendMouseWheel(data->window, 0, 0, 1);
SDL_SendMouseWheel(data->window, 0, 0, 1, SDL_MOUSEWHEEL_NORMAL);
s_AccumulatedMotion -= WHEEL_DELTA;
}
} else {
while (s_AccumulatedMotion <= -WHEEL_DELTA) {
SDL_SendMouseWheel(data->window, 0, 0, -1);
SDL_SendMouseWheel(data->window, 0, 0, -1, SDL_MOUSEWHEEL_NORMAL);
s_AccumulatedMotion += WHEEL_DELTA;
}
}
Expand All @@ -517,12 +517,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
s_AccumulatedMotion += GET_WHEEL_DELTA_WPARAM(wParam);
if (s_AccumulatedMotion > 0) {
while (s_AccumulatedMotion >= WHEEL_DELTA) {
SDL_SendMouseWheel(data->window, 0, 1, 0);
SDL_SendMouseWheel(data->window, 0, 1, 0, SDL_MOUSEWHEEL_NORMAL);
s_AccumulatedMotion -= WHEEL_DELTA;
}
} else {
while (s_AccumulatedMotion <= -WHEEL_DELTA) {
SDL_SendMouseWheel(data->window, 0, -1, 0);
SDL_SendMouseWheel(data->window, 0, -1, 0, SDL_MOUSEWHEEL_NORMAL);
s_AccumulatedMotion += WHEEL_DELTA;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/video/winrt/SDL_winrtpointerinput.cpp
Expand Up @@ -315,7 +315,7 @@ WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::Po

// FIXME: This may need to accumulate deltas up to WHEEL_DELTA
short motion = pointerPoint->Properties->MouseWheelDelta / WHEEL_DELTA;
SDL_SendMouseWheel(window, 0, 0, motion);
SDL_SendMouseWheel(window, 0, 0, motion, SDL_MOUSEWHEEL_NORMAL);
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/video/x11/SDL_x11events.c
Expand Up @@ -990,7 +990,7 @@ X11_DispatchEvent(_THIS)
case ButtonPress:{
int ticks = 0;
if (X11_IsWheelEvent(display,&xevent,&ticks)) {
SDL_SendMouseWheel(data->window, 0, 0, ticks);
SDL_SendMouseWheel(data->window, 0, 0, ticks, SDL_MOUSEWHEEL_NORMAL);
} else {
if(xevent.xbutton.button == Button1) {
if (ProcessHitTest(_this, data, &xevent)) {
Expand Down

0 comments on commit 5b5823e

Please sign in to comment.