diff --git a/library/include/borealis/core/touch/pan_gesture.hpp b/library/include/borealis/core/touch/pan_gesture.hpp index bbb2de627..7715b2d52 100644 --- a/library/include/borealis/core/touch/pan_gesture.hpp +++ b/library/include/borealis/core/touch/pan_gesture.hpp @@ -77,6 +77,8 @@ class PanGestureRecognizer : public GestureRecognizer // Get pan gesture event PanGestureEvent getPanGestureEvent() const { return panEvent; } + static inline float panFactor{1.0f}; + private: int lastFingerId = 0; PanGestureEvent panEvent; diff --git a/library/lib/core/touch/pan_gesture.cpp b/library/lib/core/touch/pan_gesture.cpp index 054a4211d..a5894a1b4 100644 --- a/library/lib/core/touch/pan_gesture.cpp +++ b/library/lib/core/touch/pan_gesture.cpp @@ -130,6 +130,10 @@ GestureState PanGestureRecognizer::recognitionLoop(TouchState touch, MouseState float velocityX = distanceX / time; float velocityY = distanceY / time; + if (panFactor > 0.0f) { + velocityX *= panFactor; + velocityY *= panFactor; + } acceleration.time.x = -fabs(velocityX) / PAN_SCROLL_ACCELERATION; acceleration.time.y = -fabs(velocityY) / PAN_SCROLL_ACCELERATION; diff --git a/library/lib/extern/glfw b/library/lib/extern/glfw index e0dd1169c..f57bb988b 160000 --- a/library/lib/extern/glfw +++ b/library/lib/extern/glfw @@ -1 +1 @@ -Subproject commit e0dd1169cdbc80143c92bab4e97b80aa5b38cbc2 +Subproject commit f57bb988b85dbc65b102ffb47c0c9d01724219cb diff --git a/library/lib/platforms/glfw/glfw_input.cpp b/library/lib/platforms/glfw/glfw_input.cpp index dcf023e7e..2f4921a50 100644 --- a/library/lib/platforms/glfw/glfw_input.cpp +++ b/library/lib/platforms/glfw/glfw_input.cpp @@ -101,14 +101,36 @@ static void glfwJoystickCallback(int jid, int event) Application::setActiveEvent(true); } +#define GLFW_STICKY 4 static RawTouchState touchState = { 0, 0, { 0, 0 } }; +static int touchStateStatus = GLFW_RELEASE; +static bool touchUpdate = false; + +static inline int getTouchState() +{ + if (touchStateStatus == GLFW_STICKY) + { + touchStateStatus = GLFW_RELEASE; + // Try to ignore the touch end event as this can lead to a smaller calculation of scrolling acceleration + int res = touchUpdate ? GLFW_PRESS : GLFW_RELEASE; + touchUpdate = false; + return res; + } + else + { + touchUpdate = false; + return touchStateStatus; + } +} static void glfwTouchCallback(GLFWwindow* window, int touch, int action, double xpos, double ypos) { touchState.fingerId = 0; - touchState.pressed = true; + touchState.pressed = action != GLFW_RELEASE; touchState.position.x = xpos / Application::windowScale; touchState.position.y = ypos / Application::windowScale; + touchStateStatus = touchState.pressed ? GLFW_PRESS : GLFW_STICKY; + touchUpdate |= touchState.pressed; Application::setActiveEvent(true); } @@ -320,10 +342,10 @@ bool sameSign(int a, int b) void GLFWInputManager::updateTouchStates(std::vector* states) { - if (touchState.pressed) + if (getTouchState()) { + touchState.pressed = true; states->push_back(touchState); - - touchState.pressed = false; + } } void GLFWInputManager::updateMouseStates(RawMouseState* state)