From 6ff7e86696a7c2ace7bf2a3fd95531de0390a94c Mon Sep 17 00:00:00 2001 From: montellese Date: Tue, 29 Jan 2013 15:57:42 +0100 Subject: [PATCH] touch: make the touchscreen's DPI available to gesture detectors --- xbmc/android/activity/AndroidTouch.cpp | 4 ++++ xbmc/input/touch/ITouchInputHandler.h | 12 +++++++++++- .../touch/generic/GenericTouchInputHandler.cpp | 7 ++++--- .../touch/generic/GenericTouchPinchDetector.h | 4 ++-- .../generic/GenericTouchRotateDetector.cpp | 4 ++-- .../touch/generic/GenericTouchRotateDetector.h | 2 +- .../generic/GenericTouchSwipeDetector.cpp | 18 +++++++++++------- .../touch/generic/GenericTouchSwipeDetector.h | 2 +- .../generic/IGenericTouchGestureDetector.h | 9 +++++++-- 9 files changed, 43 insertions(+), 19 deletions(-) diff --git a/xbmc/android/activity/AndroidTouch.cpp b/xbmc/android/activity/AndroidTouch.cpp index 9d4023f1f4d6b..1ad14309496aa 100644 --- a/xbmc/android/activity/AndroidTouch.cpp +++ b/xbmc/android/activity/AndroidTouch.cpp @@ -92,5 +92,9 @@ bool CAndroidTouch::onTouchEvent(AInputEvent* event) void CAndroidTouch::setDPI(uint32_t dpi) { if (dpi != 0) + { m_dpi = dpi; + + CGenericTouchInputHandler::Get().SetScreenDPI(m_dpi); + } } diff --git a/xbmc/input/touch/ITouchInputHandler.h b/xbmc/input/touch/ITouchInputHandler.h index 385e0b6ec8f51..58400d587306d 100644 --- a/xbmc/input/touch/ITouchInputHandler.h +++ b/xbmc/input/touch/ITouchInputHandler.h @@ -46,7 +46,9 @@ typedef enum { class ITouchInputHandler : public ITouchInputHandling { public: - ITouchInputHandler() { } + ITouchInputHandler() + : m_dpi(160.0f) + { } virtual ~ITouchInputHandler() { } /*! @@ -91,4 +93,12 @@ class ITouchInputHandler : public ITouchInputHandling * \sa Handle */ virtual bool UpdateTouchPointer(int32_t pointer, float x, float y, int64_t time, float size = 0.0f) { return false; } + + void SetScreenDPI(float dpi) { if (dpi > 0.0f) m_dpi = dpi; } + +protected: + /*! + * \brief DPI value of the touch screen + */ + float m_dpi; }; diff --git a/xbmc/input/touch/generic/GenericTouchInputHandler.cpp b/xbmc/input/touch/generic/GenericTouchInputHandler.cpp index 888609babba6a..fad609f57693b 100644 --- a/xbmc/input/touch/generic/GenericTouchInputHandler.cpp +++ b/xbmc/input/touch/generic/GenericTouchInputHandler.cpp @@ -89,9 +89,10 @@ bool CGenericTouchInputHandler::HandleTouchInput(TouchInput event, float x, floa // we start by assuming that it's a single touch if (pointer == 0) { - m_detectors.insert(new CGenericTouchSwipeDetector(this)); - m_detectors.insert(new CGenericTouchPinchDetector(this)); - m_detectors.insert(new CGenericTouchRotateDetector(this)); + // create new gesture detectors + m_detectors.insert(new CGenericTouchSwipeDetector(this, m_dpi)); + m_detectors.insert(new CGenericTouchPinchDetector(this, m_dpi)); + m_detectors.insert(new CGenericTouchRotateDetector(this, m_dpi)); triggerDetectors(event, pointer); setGestureState(TouchGestureSingleTouch); diff --git a/xbmc/input/touch/generic/GenericTouchPinchDetector.h b/xbmc/input/touch/generic/GenericTouchPinchDetector.h index e8cba07315618..35cab5f17c970 100644 --- a/xbmc/input/touch/generic/GenericTouchPinchDetector.h +++ b/xbmc/input/touch/generic/GenericTouchPinchDetector.h @@ -31,8 +31,8 @@ class CGenericTouchPinchDetector : public IGenericTouchGestureDetector { public: - CGenericTouchPinchDetector(ITouchActionHandler *handler) - : IGenericTouchGestureDetector(handler) + CGenericTouchPinchDetector(ITouchActionHandler *handler, float dpi) + : IGenericTouchGestureDetector(handler, dpi) { } virtual ~CGenericTouchPinchDetector() { } diff --git a/xbmc/input/touch/generic/GenericTouchRotateDetector.cpp b/xbmc/input/touch/generic/GenericTouchRotateDetector.cpp index 94be077a375a5..e5c04a941bab4 100644 --- a/xbmc/input/touch/generic/GenericTouchRotateDetector.cpp +++ b/xbmc/input/touch/generic/GenericTouchRotateDetector.cpp @@ -26,8 +26,8 @@ #define M_PI 3.1415926535897932384626433832795028842 #endif -CGenericTouchRotateDetector::CGenericTouchRotateDetector(ITouchActionHandler *handler) - : IGenericTouchGestureDetector(handler), +CGenericTouchRotateDetector::CGenericTouchRotateDetector(ITouchActionHandler *handler, float dpi) + : IGenericTouchGestureDetector(handler, dpi), m_angle(0.0f) { } diff --git a/xbmc/input/touch/generic/GenericTouchRotateDetector.h b/xbmc/input/touch/generic/GenericTouchRotateDetector.h index 9aa96e566d196..4cf8dbc853384 100644 --- a/xbmc/input/touch/generic/GenericTouchRotateDetector.h +++ b/xbmc/input/touch/generic/GenericTouchRotateDetector.h @@ -31,7 +31,7 @@ class CGenericTouchRotateDetector : public IGenericTouchGestureDetector { public: - CGenericTouchRotateDetector(ITouchActionHandler *handler); + CGenericTouchRotateDetector(ITouchActionHandler *handler, float dpi); virtual ~CGenericTouchRotateDetector() { } virtual bool OnTouchDown(unsigned int index, const Pointer &pointer); diff --git a/xbmc/input/touch/generic/GenericTouchSwipeDetector.cpp b/xbmc/input/touch/generic/GenericTouchSwipeDetector.cpp index 0c8d929a022dc..dfc95c708d9ae 100644 --- a/xbmc/input/touch/generic/GenericTouchSwipeDetector.cpp +++ b/xbmc/input/touch/generic/GenericTouchSwipeDetector.cpp @@ -22,12 +22,16 @@ #include "GenericTouchSwipeDetector.h" +// maximum time between touch down and up (in nanoseconds) #define SWIPE_MAX_TIME 500000000 -#define SWIPE_MIN_DISTANCE 40 +// maxmium swipe distance between touch down and up (in multiples of screen DPI) +#define SWIPE_MIN_DISTANCE 0.5 +// maximum distance the touch movement may vary in a direction transversal to +// the swipe direction #define SWIPE_MAX_VARIANCE 30.0 -CGenericTouchSwipeDetector::CGenericTouchSwipeDetector(ITouchActionHandler *handler) - : IGenericTouchGestureDetector(handler), +CGenericTouchSwipeDetector::CGenericTouchSwipeDetector(ITouchActionHandler *handler, float dpi) + : IGenericTouchGestureDetector(handler, dpi), m_directions(TouchMoveDirectionLeft | TouchMoveDirectionRight | TouchMoveDirectionUp | TouchMoveDirectionDown), m_swipeDetected(false) { } @@ -115,7 +119,7 @@ bool CGenericTouchSwipeDetector::OnTouchMove(unsigned int index, const Pointer & if (deltaYabs > SWIPE_MAX_VARIANCE) m_directions &= ~TouchMoveDirectionLeft; // check if the movement went far enough in the X direction - else if (deltaXabs > SWIPE_MIN_DISTANCE) + else if (deltaXabs > m_dpi * SWIPE_MIN_DISTANCE) m_swipeDetected = true; } @@ -125,7 +129,7 @@ bool CGenericTouchSwipeDetector::OnTouchMove(unsigned int index, const Pointer & if (deltaYabs > SWIPE_MAX_VARIANCE) m_directions &= ~TouchMoveDirectionRight; // check if the movement went far enough in the X direction - else if (deltaXabs > SWIPE_MIN_DISTANCE) + else if (deltaXabs > m_dpi * SWIPE_MIN_DISTANCE) m_swipeDetected = true; } @@ -135,7 +139,7 @@ bool CGenericTouchSwipeDetector::OnTouchMove(unsigned int index, const Pointer & if (deltaXabs > SWIPE_MAX_VARIANCE) m_directions &= ~TouchMoveDirectionUp; // check if the movement went far enough in the Y direction - else if (deltaYabs > SWIPE_MIN_DISTANCE) + else if (deltaYabs > m_dpi * SWIPE_MIN_DISTANCE) m_swipeDetected = true; } @@ -145,7 +149,7 @@ bool CGenericTouchSwipeDetector::OnTouchMove(unsigned int index, const Pointer & if (deltaXabs > SWIPE_MAX_VARIANCE) m_directions &= ~TouchMoveDirectionDown; // check if the movement went far enough in the Y direction - else if (deltaYabs > SWIPE_MIN_DISTANCE) + else if (deltaYabs > m_dpi * SWIPE_MIN_DISTANCE) m_swipeDetected = true; } diff --git a/xbmc/input/touch/generic/GenericTouchSwipeDetector.h b/xbmc/input/touch/generic/GenericTouchSwipeDetector.h index adf341420ffae..caa9e2488f621 100644 --- a/xbmc/input/touch/generic/GenericTouchSwipeDetector.h +++ b/xbmc/input/touch/generic/GenericTouchSwipeDetector.h @@ -31,7 +31,7 @@ class CGenericTouchSwipeDetector : public IGenericTouchGestureDetector { public: - CGenericTouchSwipeDetector(ITouchActionHandler *handler); + CGenericTouchSwipeDetector(ITouchActionHandler *handler, float dpi); virtual ~CGenericTouchSwipeDetector() { } virtual bool OnTouchDown(unsigned int index, const Pointer &pointer); diff --git a/xbmc/input/touch/generic/IGenericTouchGestureDetector.h b/xbmc/input/touch/generic/IGenericTouchGestureDetector.h index 83fb69572b90e..e8784c675f87f 100644 --- a/xbmc/input/touch/generic/IGenericTouchGestureDetector.h +++ b/xbmc/input/touch/generic/IGenericTouchGestureDetector.h @@ -31,8 +31,9 @@ class IGenericTouchGestureDetector : public ITouchInputHandling { public: - IGenericTouchGestureDetector(ITouchActionHandler *handler) - : m_done(false) + IGenericTouchGestureDetector(ITouchActionHandler *handler, float dpi) + : m_done(false), + m_dpi(dpi) { RegisterHandler(handler); } @@ -91,6 +92,10 @@ class IGenericTouchGestureDetector : public ITouchInputHandling * \brief Whether the gesture recognition is finished or not */ bool m_done; + /*! + * \brief DPI value of the touch screen + */ + float m_dpi; /*! * \brief Local list of all known touch pointers */