diff --git a/Common/Input/GestureDetector.cpp b/Common/Input/GestureDetector.cpp index 0e2643a726..bf33013c21 100644 --- a/Common/Input/GestureDetector.cpp +++ b/Common/Input/GestureDetector.cpp @@ -48,7 +48,7 @@ TouchInput GestureDetector::Update(const TouchInput &touch, const Bounds &bounds const float dragThreshold = 5.0f / g_display.dpi_scale_y; - if (p.distanceY > p.distanceX) { + if ((gestureMask_ & GESTURE_DRAG_VERTICAL) && p.distanceY > p.distanceX) { if (p.down) { double timeDown = time_now_d() - p.downTime; if (!p.active && p.distanceY > dragThreshold) { @@ -63,7 +63,7 @@ TouchInput GestureDetector::Update(const TouchInput &touch, const Bounds &bounds } } - if (p.distanceX > p.distanceY) { + if ((gestureMask_ & GESTURE_DRAG_HORIZONTAL) && p.distanceX > p.distanceY) { if (p.down) { double timeDown = time_now_d() - p.downTime; if (!p.active && p.distanceX > dragThreshold) { diff --git a/Common/Input/GestureDetector.h b/Common/Input/GestureDetector.h index 3e5754a7ab..ac072fbdd9 100644 --- a/Common/Input/GestureDetector.h +++ b/Common/Input/GestureDetector.h @@ -13,6 +13,7 @@ enum Gesture { GESTURE_DRAG_HORIZONTAL = 2, GESTURE_TWO_FINGER_ZOOM = 4, GESTURE_TWO_FINGER_ZOOM_ROTATE = 8, + GESTURE_ALL = 15, }; // May track multiple gestures at the same time. You simply call GetGestureInfo @@ -24,6 +25,7 @@ public: void UpdateFrame(); bool IsGestureActive(Gesture gesture, int touchId) const; bool GetGestureInfo(Gesture gesture, int touchId, float info[4]) const; + void SetGestureMask(Gesture gestureMask) { gestureMask_ = gestureMask; } private: enum Locals { @@ -48,4 +50,6 @@ private: }; Pointer pointers[MAX_PTRS]{}; + + Gesture gestureMask_ = GESTURE_ALL; }; diff --git a/Common/UI/ScrollView.cpp b/Common/UI/ScrollView.cpp index 448b37e6a0..e426a792b7 100644 --- a/Common/UI/ScrollView.cpp +++ b/Common/UI/ScrollView.cpp @@ -12,6 +12,15 @@ namespace UI { float ScrollView::lastScrollPosX = 0; float ScrollView::lastScrollPosY = 0; +ScrollView::ScrollView(Orientation orientation, LayoutParams *layoutParams) + : ViewGroup(layoutParams), orientation_(orientation) { + if (orientation == ORIENT_HORIZONTAL) { + gesture_.SetGestureMask(GESTURE_DRAG_HORIZONTAL); + } else { + gesture_.SetGestureMask(GESTURE_DRAG_VERTICAL); + } +} + ScrollView::~ScrollView() { lastScrollPosX = 0; lastScrollPosY = 0; diff --git a/Common/UI/ScrollView.h b/Common/UI/ScrollView.h index 0e47e28d73..73036ddb92 100644 --- a/Common/UI/ScrollView.h +++ b/Common/UI/ScrollView.h @@ -8,8 +8,7 @@ namespace UI { // A scrollview usually contains just a single child - a linear layout or similar. class ScrollView : public ViewGroup { public: - ScrollView(Orientation orientation, LayoutParams *layoutParams = 0) - : ViewGroup(layoutParams), orientation_(orientation) {} + ScrollView(Orientation orientation, LayoutParams *layoutParams = nullptr); ~ScrollView(); void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override;