Fixed bug 2293 - Precise scrolling events

Martijn Courteaux

I implemented precise scrolling events. I have been through all the folders in /src/video/[platform] to implement where possible. This works on OS X, but I can't speak for others. Build farm will figure that out, I guess. I think this patch should introduce precise scrolling on OS X, Wayland, Mir, Windows, Android, Nacl, Windows RT.

The way I provide precise scrolling events is by adding two float fields to the SDL_MouseWheelScrollEvent datastructure, called "preciseX" and "preciseY". The old integer fields "x" and "y" are still present. The idea is that every platform specific code normalises the scroll amounts and forwards them to the SDL_SendMouseWheel function. It is this function that will now accumulate these (using a static variable, as I have seen how it was implemented in the Windows specific code) and once we hit a unit size, set the traditional integer "x" and "y" fields.

I believe this is pretty solid way of doing it, although I'm not the expert here.

There is also a fix in the patch for a typo recently introduced, that might need to be taken away by the time anybody merges this in. There is also a file in Nacl which I have stripped a horrible amount of trailing whitespaces. (Leave that part out if you want).
This commit is contained in:
Sam Lantinga
2017-08-14 21:28:04 -07:00
parent 72b195d27c
commit a4cfa93670
10 changed files with 80 additions and 90 deletions

View File

@@ -298,7 +298,7 @@ static Uint8 SDL_NACL_translate_mouse_button(int32_t button) {
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 @@ SDL_NACL_translate_keycode(int keycode)
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 @@ void NACL_PumpEvents(_THIS) {
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 @@ void NACL_PumpEvents(_THIS) {
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 @@ 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_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 @@ void NACL_PumpEvents(_THIS) {
}
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 @@ void NACL_PumpEvents(_THIS) {
/* 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 @@ void NACL_PumpEvents(_THIS) {
default:
break;
}
PSEventRelease(ps_event);
}
}