Skip to content

Commit

Permalink
Input|libgui: Improved accuracy of swipe gestures
Browse files Browse the repository at this point in the history
Swipe gestures are used for touchpad scrolling, so it should be as accurate as possible. Now the sensitivity can be scaled without losing data.
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 54c0629 commit deaa3e0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions doomsday/libs/gui/src/windoweventhandler.cpp
Expand Up @@ -145,7 +145,7 @@ DE_PIMPL(WindowEventHandler)

struct InertiaScrollState {
bool active = false;
float sensitivity = 1000;
float sensitivity = 750;
Flywheel pos[2];
Vec2f prevGesturePos;
};
Expand Down Expand Up @@ -356,6 +356,8 @@ DE_PIMPL(WindowEventHandler)
*/
}

double swipeRoundoff[2]{};

void handleGestureEvent(const SDL_MultiGestureEvent &ev)
{
if (ev.numFingers == 2)
Expand All @@ -373,7 +375,11 @@ DE_PIMPL(WindowEventHandler)

for (int axis = 0; axis < 2; ++axis)
{
const auto units = int(std::lround(delta[axis] * scr.sensitivity));
const double units_f = delta[axis] * scr.sensitivity + swipeRoundoff[axis];
const int units = int(units_f);

swipeRoundoff[axis] = units_f - units;

if (units)
{
DE_FOR_PUBLIC_AUDIENCE(MouseEvent, i)
Expand Down

0 comments on commit deaa3e0

Please sign in to comment.