floooh / sokol

minimal cross-platform standalone C headers

Home Page:https://floooh.github.io/sokol-html5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sokol_app.h: Scroll event amounts are inconsistent between browsers

bqqbarbhg opened this issue · comments

The scroll event doesn't take the wheel event units into account resulting in Firefox scrolling a lot slower than Chrome (on Windows).

I have fudged the values to be consistent with what the Win32 backend returns on Windows, I didn't test DOM_DELTA_PAGE as I didn't happen to have a browser that emits it handy:

https://github.com/bqqbarbhg/spear/blob/ab4b57edd4cc622bd9b933cb17bb89e188fe9e43/src/ext/sokol/sokol_app_impl.h#L2110-L2124

// ... _sapp_emsc_wheel_cb()
float scale = -0.1f;
switch (emsc_event->deltaMode) {
case DOM_DELTA_PIXEL:
	scale = -0.04f;
	break;
case DOM_DELTA_LINE:
	scale = -1.3333f;
	break;
case DOM_DELTA_PAGE:
	scale = -10.0f;
	break;
}
_sapp.event.scroll_x = scale * (float)emsc_event->deltaX;
_sapp.event.scroll_y = scale * (float)emsc_event->deltaY;

This might break existing user code depending on the scroll unit behavior (especially if changing the Chrome's DOM_DELTA_PIXEL unit from -0.1f). Feel free to swipe the snippet and/or tweak the values to your liking if you're interested :D I can also do a PR for this if it's easier.

Yeah I noticed this too, but haven't investigated, so many thanks for doing that :)

It seems like mouse movement and resolution is generally quite a mess to get consistent across platforms (also when using the native APIs), but if there are hints like this (e.g. the deltaMode), then we should make use of it.

I'm currently working on a pointer-lock feature (in the branch pointer-lock-2), and since I'm dealing with mouse stuff there anyway I'll integrate your fix there (I'll also need to read up on this deltaMode thing first).

Ok, I've added your fix to sokol_app.h, it's currently in the branch pointer-lock-2 though. I'll update the sokol-samples webpage so you can check if it feels correct now.

You can test the fix here: https://floooh.github.io/sokol-html5/cgltf-sapp.html

(I should add some smoothing to the camera zoom though).

I guess this feature will close automatically when the pointer-lock-2 branch is merged (should happen in the next few days).

Cool thanks! Seems consistent to me now!

...and this has just been merged.