# HG changeset patch # User Martijn Courteaux # Date 1464788959 -7200 # Wed Jun 01 15:49:19 2016 +0200 # Branch precisescrolling # Node ID d9d595ad27921d6394e8ee3455ebf3c21fb5b6ff # Parent 7cbfd97f143075520b8ada03bce451639da02a42 Precise scrolling. diff -r 7cbfd97f1430 -r d9d595ad2792 src/events/SDL_mouse.c --- a/src/events/SDL_mouse.c Mon May 23 15:29:25 2016 -0300 +++ b/src/events/SDL_mouse.c Wed Jun 01 15:49:19 2016 +0200 @@ -403,7 +403,7 @@ } int -SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction) +SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction) { SDL_Mouse *mouse = SDL_GetMouse(); int posted; @@ -419,13 +419,24 @@ /* Post the event, if desired */ posted = 0; if (SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE) { + static float s_Accumulated_x = 0.0f; + static float s_Accumulated_y = 0.0f; + s_Accumulated_x += x; + s_Accumulated_y += y; + SDL_Event event; event.type = SDL_MOUSEWHEEL; event.wheel.windowID = mouse->focus ? mouse->focus->id : 0; event.wheel.which = mouseID; - event.wheel.x = x; - event.wheel.y = y; + event.wheel.preciseX = x; + event.wheel.preciseY = y; + event.wheel.x = (int) s_Accumulated_x; + event.wheel.y = (int) s_Accumulated_y; event.wheel.direction = (Uint32)direction; + + s_Accumulated_x -= event.wheel.x; + s_Accumulated_y -= event.wheel.y; + posted = (SDL_PushEvent(&event) > 0); } return posted; diff -r 7cbfd97f1430 -r d9d595ad2792 src/events/SDL_mouse_c.h --- a/src/events/SDL_mouse_c.h Mon May 23 15:29:25 2016 -0300 +++ b/src/events/SDL_mouse_c.h Wed Jun 01 15:49:19 2016 +0200 @@ -120,7 +120,7 @@ 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, SDL_MouseWheelDirection direction); +extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction); /* Shutdown the mouse subsystem */ extern void SDL_MouseQuit(void); diff -r 7cbfd97f1430 -r d9d595ad2792 src/video/cocoa/SDL_cocoamouse.m --- a/src/video/cocoa/SDL_cocoamouse.m Mon May 23 15:29:25 2016 -0300 +++ b/src/video/cocoa/SDL_cocoamouse.m Wed Jun 01 15:49:19 2016 +0200 @@ -431,17 +431,7 @@ } } - if (x > 0) { - x += 0.9f; - } else if (x < 0) { - x -= 0.9f; - } - if (y > 0) { - y += 0.9f; - } else if (y < 0) { - y -= 0.9f; - } - SDL_SendMouseWheel(window, mouse->mouseID, (int)x, (int)y, direction); + SDL_SendMouseWheel(window, mouse->mouseID, x, y, direction); } void diff -r 7cbfd97f1430 -r d9d595ad2792 src/video/emscripten/SDL_emscriptenevents.c --- a/src/video/emscripten/SDL_emscriptenevents.c Mon May 23 15:29:25 2016 -0300 +++ b/src/video/emscripten/SDL_emscriptenevents.c Wed Jun 01 15:49:19 2016 +0200 @@ -357,7 +357,7 @@ Emscripten_HandleWheel(int eventType, const EmscriptenWheelEvent *wheelEvent, void *userData) { SDL_WindowData *window_data = userData; - SDL_SendMouseWheel(window_data->window, 0, wheelEvent->deltaX, -wheelEvent->deltaY, SDL_MOUSEWHEEL_NORMAL); + SDL_SendMouseWheel(window_data->window, 0, (float) wheelEvent->deltaX, (float) -wheelEvent->deltaY, SDL_MOUSEWHEEL_NORMAL); return 1; } diff -r 7cbfd97f1430 -r d9d595ad2792 src/video/mir/SDL_mirevents.c --- a/src/video/mir/SDL_mirevents.c Mon May 23 15:29:25 2016 -0300 +++ b/src/video/mir/SDL_mirevents.c Wed Jun 01 15:49:19 2016 +0200 @@ -152,7 +152,7 @@ } static void -HandleMouseScroll(SDL_Window* sdl_window, int hscroll, int vscroll) +HandleMouseScroll(SDL_Window* sdl_window, float hscroll, float vscroll) { SDL_SendMouseWheel(sdl_window, 0, hscroll, vscroll, SDL_MOUSEWHEEL_NORMAL); } @@ -214,7 +214,7 @@ break; case mir_pointer_action_motion: { int x, y; - int hscroll, vscroll; + float hscroll, vscroll; SDL_Mouse* mouse = SDL_GetMouse(); x = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_x); y = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_y); diff -r 7cbfd97f1430 -r d9d595ad2792 src/video/nacl/SDL_naclevents.c --- a/src/video/nacl/SDL_naclevents.c Mon May 23 15:29:25 2016 -0300 +++ b/src/video/nacl/SDL_naclevents.c Wed Jun 01 15:49:19 2016 +0200 @@ -298,7 +298,7 @@ return SDL_BUTTON_MIDDLE; case PP_INPUTEVENT_MOUSEBUTTON_RIGHT: return SDL_BUTTON_RIGHT; - + case PP_INPUTEVENT_MOUSEBUTTON_NONE: default: return 0; @@ -321,7 +321,7 @@ void NACL_PumpEvents(_THIS) { PSEvent* ps_event; - PP_Resource event; + PP_Resource event; PP_InputEvent_Type type; PP_InputEvent_Modifier modifiers; struct PP_Rect rect; @@ -333,7 +333,7 @@ Uint32 str_len; SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata; SDL_Mouse *mouse = SDL_GetMouse(); - + if (driverdata->window) { while ((ps_event = PSEventTryAcquire()) != NULL) { event = ps_event->as_resource; @@ -344,9 +344,9 @@ NACL_SetScreenResolution(rect.size.width, rect.size.height, SDL_PIXELFORMAT_UNKNOWN); // FIXME: Rebuild context? See life.c UpdateContext break; - + /* From HandleInputEvent, contains an input resource. */ - case PSE_INSTANCE_HANDLEINPUT: + case PSE_INSTANCE_HANDLEINPUT: type = driverdata->ppb_input_event->GetType(event); modifiers = driverdata->ppb_input_event->GetModifiers(event); switch(type) { @@ -359,35 +359,35 @@ 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_MOUSEWHEEL_NORMAL); + SDL_SendMouseWheel(mouse->focus, mouse->mouseID, fp.x, fp.y, SDL_MOUSEWHEEL_NORMAL); break; - + case PP_INPUTEVENT_TYPE_MOUSEENTER: case PP_INPUTEVENT_TYPE_MOUSELEAVE: /* FIXME: Mouse Focus */ break; - - - case PP_INPUTEVENT_TYPE_MOUSEMOVE: + + + case PP_INPUTEVENT_TYPE_MOUSEMOVE: location = driverdata->ppb_mouse_input_event->GetPosition(event); SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, location.x, location.y); break; - + case PP_INPUTEVENT_TYPE_TOUCHSTART: case PP_INPUTEVENT_TYPE_TOUCHMOVE: case PP_INPUTEVENT_TYPE_TOUCHEND: case PP_INPUTEVENT_TYPE_TOUCHCANCEL: /* FIXME: Touch events */ break; - + case PP_INPUTEVENT_TYPE_KEYDOWN: SDL_SendKeyboardKey(SDL_PRESSED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event))); break; - + case PP_INPUTEVENT_TYPE_KEYUP: SDL_SendKeyboardKey(SDL_RELEASED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event))); break; - + case PP_INPUTEVENT_TYPE_CHAR: var = driverdata->ppb_keyboard_input_event->GetCharacterText(event); str = driverdata->ppb_var->VarToUtf8(var, &str_len); @@ -397,17 +397,17 @@ } SDL_strlcpy(text, str, str_len ); text[str_len] = '\0'; - + SDL_SendKeyboardText(text); /* FIXME: Do we have to handle ref counting? driverdata->ppb_var->Release(var);*/ break; - + default: break; } break; - - + + /* From HandleMessage, contains a PP_Var. */ case PSE_INSTANCE_HANDLEMESSAGE: break; @@ -419,7 +419,7 @@ /* When the 3D context is lost, no resource. */ case PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST: break; - + /* When the mouse lock is lost. */ case PSE_MOUSELOCK_MOUSELOCKLOST: break; @@ -427,7 +427,7 @@ default: break; } - + PSEventRelease(ps_event); } } diff -r 7cbfd97f1430 -r d9d595ad2792 src/video/wayland/SDL_waylandevents.c --- a/src/video/wayland/SDL_waylandevents.c Mon May 23 15:29:25 2016 -0300 +++ b/src/video/wayland/SDL_waylandevents.c Wed Jun 01 15:49:19 2016 +0200 @@ -54,7 +54,7 @@ /* Last motion location */ wl_fixed_t sx_w; wl_fixed_t sy_w; - + struct { struct xkb_keymap *keymap; struct xkb_state *state; @@ -89,7 +89,7 @@ /* enter event for a window we've just destroyed */ return; } - + /* This handler will be called twice in Wayland 1.4 * Once for the window surface which has valid user data * and again for the mouse cursor surface which does not have valid user data @@ -97,7 +97,7 @@ */ window = (SDL_WindowData *)wl_surface_get_user_data(surface); - + if (window) { input->pointer_focus = window; SDL_SetMouseFocus(window->sdlwindow); @@ -177,7 +177,7 @@ SDL_WindowData *window = input->pointer_focus; enum wl_pointer_button_state state = state_w; uint32_t sdl_button; - + if (input->pointer_focus) { switch (button) { case BTN_LEFT: @@ -214,16 +214,16 @@ struct SDL_WaylandInput *input = data; SDL_WindowData *window = input->pointer_focus; enum wl_pointer_axis a = axis; - int x, y; + float x, y; if (input->pointer_focus) { switch (a) { case WL_POINTER_AXIS_VERTICAL_SCROLL: x = 0; - y = wl_fixed_to_int(value); + y = wl_fixed_to_float(value); break; case WL_POINTER_AXIS_HORIZONTAL_SCROLL: - x = wl_fixed_to_int(value); + x = wl_fixed_to_float(value); y = 0; break; default: @@ -298,7 +298,7 @@ /* enter event for a window we've just destroyed */ return; } - + window = wl_surface_get_user_data(surface); if (window) { diff -r 7cbfd97f1430 -r d9d595ad2792 src/video/windows/SDL_windowsevents.c --- a/src/video/windows/SDL_windowsevents.c Mon May 23 15:29:25 2016 -0300 +++ b/src/video/windows/SDL_windowsevents.c Wed Jun 01 15:49:19 2016 +0200 @@ -296,7 +296,7 @@ data->mouse_button_flags = 0; } -BOOL +BOOL WIN_ConvertUTF32toUTF8(UINT32 codepoint, char * text) { if (codepoint <= 0x7F) { @@ -327,7 +327,7 @@ ShouldGenerateWindowCloseOnAltF4(void) { const char *hint; - + hint = SDL_GetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4); if (hint) { if (*hint == '0') { @@ -404,11 +404,11 @@ if (SDL_GetKeyboardFocus() != data->window) { SDL_SetKeyboardFocus(data->window); } - + GetCursorPos(&cursorPos); ScreenToClient(hwnd, &cursorPos); SDL_SendMouseMotion(data->window, 0, 0, cursorPos.x, cursorPos.y); - + WIN_CheckAsyncMouseRelease(data); /* @@ -522,40 +522,14 @@ break; case WM_MOUSEWHEEL: - { - static short s_AccumulatedMotion; - - s_AccumulatedMotion += GET_WHEEL_DELTA_WPARAM(wParam); - if (s_AccumulatedMotion > 0) { - while (s_AccumulatedMotion >= WHEEL_DELTA) { - 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_MOUSEWHEEL_NORMAL); - s_AccumulatedMotion += WHEEL_DELTA; - } - } - } - break; - case WM_MOUSEHWHEEL: { - static short s_AccumulatedMotion; - - s_AccumulatedMotion += GET_WHEEL_DELTA_WPARAM(wParam); - if (s_AccumulatedMotion > 0) { - while (s_AccumulatedMotion >= WHEEL_DELTA) { - 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_MOUSEWHEEL_NORMAL); - s_AccumulatedMotion += WHEEL_DELTA; - } - } + short amount = GET_WHEEL_DELTA_WPARAM(wParam); + float fAmount = (float) amount / WHEEL_DELTA; + if (msg == WM_MOUSEWHEEL) + SDL_SendMouseWheel(data->window, 0, 0.0f, fAmount, SDL_MOUSEWHEEL_NORMAL); + else + SDL_SendMouseWheel(data->window, 0, fAmount, 0.0f, SDL_MOUSEWHEEL_NORMAL); } break; @@ -592,7 +566,7 @@ SDL_SendKeyboardKey(SDL_PRESSED, code); } } - + returnCode = 0; break; @@ -742,7 +716,7 @@ RECT rect; int x, y; int w, h; - + if (data->initializing || data->in_border_change) { break; } diff -r 7cbfd97f1430 -r d9d595ad2792 src/video/winrt/SDL_winrtpointerinput.cpp --- a/src/video/winrt/SDL_winrtpointerinput.cpp Mon May 23 15:29:25 2016 -0300 +++ b/src/video/winrt/SDL_winrtpointerinput.cpp Wed Jun 01 15:49:19 2016 +0200 @@ -295,7 +295,7 @@ } WINRT_LeftFingerDown = 0; } - + SDL_SendTouch( WINRT_TouchID, (SDL_FingerID) pointerPoint->PointerId, @@ -335,9 +335,8 @@ return; } - // 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_MOUSEWHEEL_NORMAL); + float motion = (float) pointerPoint->Properties->MouseWheelDelta / WHEEL_DELTA; + SDL_SendMouseWheel(window, 0, 0, (float) motion, SDL_MOUSEWHEEL_NORMAL); } void @@ -369,7 +368,7 @@ // http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.input.mouseeventargs.mousedelta ), // does not seem to indicate (to me) that its values should be so large. It // says that its values should be a "change in screen location". I could - // be misinterpreting this, however a post on MSDN from a Microsoft engineer (see: + // be misinterpreting this, however a post on MSDN from a Microsoft engineer (see: // http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/09a9868e-95bb-4858-ba1a-cb4d2c298d62 ), // indicates that these values are in DIPs, which is the same unit used // by CoreWindow's PointerMoved events (via the Position field in its CurrentPoint diff -r 7cbfd97f1430 -r d9d595ad2792 src/video/x11/SDL_x11events.c --- a/src/video/x11/SDL_x11events.c Mon May 23 15:29:25 2016 -0300 +++ b/src/video/x11/SDL_x11events.c Wed Jun 01 15:49:19 2016 +0200 @@ -876,7 +876,7 @@ printf("Protocol version to use : %d\n", xdnd_version); printf("More then 3 data types : %d\n", (int) use_list); #endif - + if (use_list) { /* fetch conversion targets */ SDL_x11Prop p; @@ -890,7 +890,7 @@ } } else if (xevent.xclient.message_type == videodata->XdndPosition) { - + #ifdef DEBUG_XEVENTS Atom act= videodata->XdndActionCopy; if(xdnd_version >= 2) { @@ -898,7 +898,7 @@ } printf("Action requested by user is : %s\n", X11_XGetAtomName(display , act)); #endif - + /* reply with status */ memset(&m, 0, sizeof(XClientMessageEvent)); @@ -998,7 +998,7 @@ case ButtonPress:{ int xticks = 0, yticks = 0; if (X11_IsWheelEvent(display,&xevent,&xticks, &yticks)) { - SDL_SendMouseWheel(data->window, 0, xticks, yticks, SDL_MOUSEWHEEL_NORMAL); + SDL_SendMouseWheel(data->window, 0, (float) xticks, (float) yticks, SDL_MOUSEWHEEL_NORMAL); } else { int button = xevent.xbutton.button; if(button == Button1) { # HG changeset patch # User Martijn Courteaux # Date 1464789191 -7200 # Wed Jun 01 15:53:11 2016 +0200 # Branch precisescrolling # Node ID 17578615d2cfbcd2c9f8bb66c0f5db9ab3a8b505 # Parent d9d595ad27921d6394e8ee3455ebf3c21fb5b6ff Precise scrolling; fix 0. diff -r d9d595ad2792 -r 17578615d2cf include/SDL_events.h --- a/include/SDL_events.h Wed Jun 01 15:49:19 2016 +0200 +++ b/include/SDL_events.h Wed Jun 01 15:53:11 2016 +0200 @@ -270,8 +270,8 @@ 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 */ - Sint32 preciseX; /**< The amount scrolled horizontally, precise */ - Sint32 preciseY; /**< The amount scrolled vertically, precise */ + float preciseX; /**< The amount scrolled horizontally, precise */ + float preciseY; /**< The amount scrolled vertically, precise */ 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; diff -r d9d595ad2792 -r 17578615d2cf include/SDL_revision.h --- a/include/SDL_revision.h Wed Jun 01 15:49:19 2016 +0200 +++ b/include/SDL_revision.h Wed Jun 01 15:53:11 2016 +0200 @@ -1,2 +1,2 @@ -#define SDL_REVISION "hg-10171:5b61e12c0a30" -#define SDL_REVISION_NUMBER 10171 +#define SDL_REVISION "hg-10180:d9d595ad2792" +#define SDL_REVISION_NUMBER 10180