From e2969c7168474132caad95779439e050d75af343 Mon Sep 17 00:00:00 2001 From: Daniel Allen Date: Mon, 25 Sep 2023 20:59:39 -0700 Subject: [PATCH] Added option of allowing multi-touch drag in combination with pinch/twist gestures. This feels more natural if you allow multi-touch-drag to be pan or drag. --- src/osgEarth/EarthManipulator | 5 +++++ src/osgEarth/EarthManipulator.cpp | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/osgEarth/EarthManipulator b/src/osgEarth/EarthManipulator index fc8d0fee5b..ee42efbd36 100644 --- a/src/osgEarth/EarthManipulator +++ b/src/osgEarth/EarthManipulator @@ -514,6 +514,10 @@ namespace osgEarth { namespace Util void setZoomToMouse(bool value) { _zoomToMouse = value; } bool getZoomToMouse() const { return _zoomToMouse; } + /** Allow multitouch drag events to be combined with pinch/twist in the same gesture */ + void setAllowTouchDragCombos(bool value) { _allowTouchDragCombos = value; } + bool getAllowTouchDragCombos() const { return _allowTouchDragCombos; } + private: friend class EarthManipulator; @@ -561,6 +565,7 @@ namespace osgEarth { namespace Util double _throwDecayRate; bool _zoomToMouse; + bool _allowTouchDragCombos; }; public: diff --git a/src/osgEarth/EarthManipulator.cpp b/src/osgEarth/EarthManipulator.cpp index 0aa6c888f6..0ea433a3fc 100644 --- a/src/osgEarth/EarthManipulator.cpp +++ b/src/osgEarth/EarthManipulator.cpp @@ -297,7 +297,8 @@ _terrainAvoidanceEnabled ( true ), _terrainAvoidanceMinDistance ( 1.0 ), _throwingEnabled ( false ), _throwDecayRate ( 0.05 ), -_zoomToMouse ( false ) +_zoomToMouse ( false ), +_allowTouchDragCombos ( false ) { //NOP } @@ -329,7 +330,8 @@ _terrainAvoidanceEnabled( rhs._terrainAvoidanceEnabled ), _terrainAvoidanceMinDistance( rhs._terrainAvoidanceMinDistance ), _throwingEnabled( rhs._throwingEnabled ), _throwDecayRate( rhs._throwDecayRate ), -_zoomToMouse( rhs._zoomToMouse ) +_zoomToMouse( rhs._zoomToMouse ), +_allowTouchDragCombos( rhs._allowTouchDragCombos ) { //NOP } @@ -2188,10 +2190,13 @@ EarthManipulator::parseTouchEvents( TouchEvents& output ) // Threshold in pixels for determining if a two finger drag happened. float dragThres = 1.0f; + bool doMultiDrag = ( osg::equivalent(vec0.x(), vec1.x(), dragThres) && + osg::equivalent(vec0.y(), vec1.y(), dragThres) ) || + _settings->getAllowTouchDragCombos(); - // now see if that corresponds to any touch events: - if (osg::equivalent(vec0.x(), vec1.x(), dragThres) && - osg::equivalent(vec0.y(), vec1.y(), dragThres)) + // First check if we should be doing the multidrag event, either because + // it was a pure drag, or because we allow it in combination with pinch/twise + if( doMultiDrag ) { // two-finger drag. output.push_back(TouchEvent()); @@ -2200,7 +2205,9 @@ EarthManipulator::parseTouchEvents( TouchEvents& output ) ev._dx = 0.5 * (dx[0] + dx[1]) * sens; ev._dy = 0.5 * (dy[0] + dy[1]) * sens; } - else + + // If it wasn't a drag event, or if we allow drag combinations, do the pinch/twist + if( !doMultiDrag || _settings->getAllowTouchDragCombos() ) { // otherwise it's a pinch and/or a zoom. You can do them together. if (fabs(deltaDistance) > (1.0 * 0.0005 / sens))