Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sokol_app.h: Scroll event amounts are inconsistent between browsers #339

Closed
bqqbarbhg opened this issue Jul 20, 2020 · 5 comments
Closed
Assignees
Labels

Comments

@bqqbarbhg
Copy link
Contributor

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.

@floooh
Copy link
Owner

floooh commented Jul 21, 2020

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).

@floooh
Copy link
Owner

floooh commented Jul 31, 2020

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.

@floooh
Copy link
Owner

floooh commented Jul 31, 2020

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).

@bqqbarbhg
Copy link
Contributor Author

Cool thanks! Seems consistent to me now!

@floooh floooh closed this as completed Aug 2, 2020
@floooh
Copy link
Owner

floooh commented Aug 2, 2020

...and this has just been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants