LuciadCPillar 2023.1.03
luciad::TouchGestureRecognizer Class Referencefinal

This class generates high-level touch gesture events from low-level input events. More...

#include <luciad/input/touch/TouchGestureRecognizer.h>

Public Member Functions

 TouchGestureRecognizer (std::shared_ptr< IInputEventCallback > callback, std::shared_ptr< ITaskScheduler > taskScheduler)
 Creates a TouchGestureRecognizer The generated high level luciad::IInputEvents are passed to the given callback on the UI thread. More...
 
 ~TouchGestureRecognizer ()
 
double getDisplayScale () const
 
double getDpi () const
 
ScreenDistance getDragThreshold () const
 
size_t getLongPressThreshold () const
 
size_t getMultiTapInterval () const noexcept
 
ScreenDistance getMultiTapThreshold () const
 
void onTouchEvent (const TouchPointEvent &touchPointEvent)
 Entry point for the touch events of the gesture recognizer. More...
 
void setDisplayScale (double scale)
 Set the display scale factor. More...
 
void setDpi (double dpi)
 Set the display pixel density in dots per inch. More...
 
void setDragThreshold (ScreenDistance threshold)
 Sets the screen distance that is used as threshold to detect if a drag is performed while using touch inputs. More...
 
void setLongPressThreshold (size_t longPressThreshold)
 Set the threshold, in milliseconds, to reach before a long press event is sent. More...
 
void setMultiTapInterval (size_t interval)
 Set the interval used to detect multiple taps (default is 400 ms). More...
 
void setMultiTapThreshold (ScreenDistance threshold)
 Set the screen distance threshold to detect multiple taps. More...
 

Detailed Description

This class generates high-level touch gesture events from low-level input events.

High level events are subclasses of luciad::IInputEvent such as luciad::TouchTapEvent. Sequences of low level events are used to create those high level events.

For example, a touch press + movement of the touch point (possibly multiple times) sequence is recognized as a touch drag gesture. A touch press + a touch release sequence is recognized as a touch tap gesture. This class is useful when adding integration with a platform that does not provide these more high-level events.

A typical use of such a class is to wire it to a UI framework specific class (such as Qt , see QQuickMapObject in the sample code) and make the controller react to the high level event instead of every low level event the framework can fire.

The use of the TouchGestureRecognizer is optional. A controller implementation can use custom conversion code if needed, for example if you want to manage the low level events yourself and create other high level luciad::IInputEvent instances.

The events passed to this class are expected to be defined in device independent pixels.

Since
2022.0

Constructor & Destructor Documentation

◆ TouchGestureRecognizer()

luciad::TouchGestureRecognizer::TouchGestureRecognizer ( std::shared_ptr< IInputEventCallback callback,
std::shared_ptr< ITaskScheduler taskScheduler 
)

Creates a TouchGestureRecognizer The generated high level luciad::IInputEvents are passed to the given callback on the UI thread.

For certain events, like for example a long press, an internal timer is used to determine when an IInputEvent needs to be sent. Due to the use of a timer, it is possible that some work is done on a different thread than the UI thread. The task scheduler can be used to apply the result of the timer on the UI thread.

Parameters
callbackthe callback that receive generated luciad::IInputEvents. Can not be nullptr.
taskSchedulera scheduler allowing the caller to receive some luciad::IInputEvents on another thread and resolve them on the UI thread. Can be nullptr. If nullptr, some events won't be emitted.
Exceptions
luciad::NullArgumentExceptionIf callback is nullptr.

◆ ~TouchGestureRecognizer()

luciad::TouchGestureRecognizer::~TouchGestureRecognizer ( )

Member Function Documentation

◆ getDisplayScale()

double luciad::TouchGestureRecognizer::getDisplayScale ( ) const
Returns
the display scale factor.

◆ getDpi()

double luciad::TouchGestureRecognizer::getDpi ( ) const
Returns
the display pixel density, expressed in dots per inch.

◆ getDragThreshold()

ScreenDistance luciad::TouchGestureRecognizer::getDragThreshold ( ) const
Returns
the screen distance that is used as threshold to detect if a drag is performed while using touch inputs. It means that the input device has to move at least that amount of pixels before it can be detected as a drag gesture.

◆ getLongPressThreshold()

size_t luciad::TouchGestureRecognizer::getLongPressThreshold ( ) const
Returns
the threshold, in milliseconds, to reach before a long press event is sent.

◆ getMultiTapInterval()

size_t luciad::TouchGestureRecognizer::getMultiTapInterval ( ) const
noexcept
Returns
the time interval used to detect multiple taps, expressed in milliseconds (default is 400 ms).

◆ getMultiTapThreshold()

ScreenDistance luciad::TouchGestureRecognizer::getMultiTapThreshold ( ) const
Returns
the screen distance threshold for multiple taps detection.

◆ onTouchEvent()

void luciad::TouchGestureRecognizer::onTouchEvent ( const TouchPointEvent touchPointEvent)

Entry point for the touch events of the gesture recognizer.

Parameters
touchPointEventthe luciad::TouchPointEvent object containing a collection of luciad::TouchPoints.

◆ setDisplayScale()

void luciad::TouchGestureRecognizer::setDisplayScale ( double  scale)

Set the display scale factor.

If no value is provided, a scale factor of 1.0 is assumed.

Parameters
scalethe display scale factor (adimensional scale value)

◆ setDpi()

void luciad::TouchGestureRecognizer::setDpi ( double  dpi)

Set the display pixel density in dots per inch.

If no value is provided, the platform standard pixel density is assumed.

Parameters
dpithe pixel density in dots per inch

◆ setDragThreshold()

void luciad::TouchGestureRecognizer::setDragThreshold ( ScreenDistance  threshold)

Sets the screen distance that is used as threshold to detect if a drag is performed while using touch inputs.

It means that the input device has to move at least that distance before it can be detected as a drag gesture. The default drag threshold is a screen distance of 5 mm.

Parameters
thresholdthe screen distance threshold

◆ setLongPressThreshold()

void luciad::TouchGestureRecognizer::setLongPressThreshold ( size_t  longPressThreshold)

Set the threshold, in milliseconds, to reach before a long press event is sent.

The default is 700 ms.

Parameters
longPressThresholdthe threshold in milliseconds.

◆ setMultiTapInterval()

void luciad::TouchGestureRecognizer::setMultiTapInterval ( size_t  interval)

Set the interval used to detect multiple taps (default is 400 ms).

Parameters
intervalthe maximum time (in milliseconds) between multiple taps. If the interval is set to 0, no multiple taps will be detected.

◆ setMultiTapThreshold()

void luciad::TouchGestureRecognizer::setMultiTapThreshold ( ScreenDistance  threshold)

Set the screen distance threshold to detect multiple taps.

It means that consecutive taps need to be as close as that distance in order to generate an event for a multiple tap.

Parameters
thresholdthe distance threshold