Skip to content

Commit

Permalink
touch: make the touchscreen's DPI available to gesture detectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Montellese committed Mar 5, 2013
1 parent 75f5c1e commit 6ff7e86
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 19 deletions.
4 changes: 4 additions & 0 deletions xbmc/android/activity/AndroidTouch.cpp
Expand Up @@ -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);
}
}
12 changes: 11 additions & 1 deletion xbmc/input/touch/ITouchInputHandler.h
Expand Up @@ -46,7 +46,9 @@ typedef enum {
class ITouchInputHandler : public ITouchInputHandling
{
public:
ITouchInputHandler() { }
ITouchInputHandler()
: m_dpi(160.0f)
{ }
virtual ~ITouchInputHandler() { }

/*!
Expand Down Expand Up @@ -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;
};
7 changes: 4 additions & 3 deletions xbmc/input/touch/generic/GenericTouchInputHandler.cpp
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions xbmc/input/touch/generic/GenericTouchPinchDetector.h
Expand Up @@ -31,8 +31,8 @@
class CGenericTouchPinchDetector : public IGenericTouchGestureDetector
{
public:
CGenericTouchPinchDetector(ITouchActionHandler *handler)
: IGenericTouchGestureDetector(handler)
CGenericTouchPinchDetector(ITouchActionHandler *handler, float dpi)
: IGenericTouchGestureDetector(handler, dpi)
{ }
virtual ~CGenericTouchPinchDetector() { }

Expand Down
4 changes: 2 additions & 2 deletions xbmc/input/touch/generic/GenericTouchRotateDetector.cpp
Expand Up @@ -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)
{ }

Expand Down
2 changes: 1 addition & 1 deletion xbmc/input/touch/generic/GenericTouchRotateDetector.h
Expand Up @@ -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);
Expand Down
18 changes: 11 additions & 7 deletions xbmc/input/touch/generic/GenericTouchSwipeDetector.cpp
Expand Up @@ -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)
{ }
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion xbmc/input/touch/generic/GenericTouchSwipeDetector.h
Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions xbmc/input/touch/generic/IGenericTouchGestureDetector.h
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 6ff7e86

Please sign in to comment.