public final class MouseGestureRecognizer extends Object implements AutoCloseable
High level events are subclasses of IInputEvent
such as MouseClickEvent
. Low levels are used to create those high level events and are dropped afterwards.
For example, a mouse pressed + (possibly multiple) mouse moved + a mouse released sequence is recognized as a drag gesture. A mouse pressed + a mouse released sequence is recognized as a click 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 MouseGestureRecognizer
is optional. Events containing MouseButton#unknown()
as the mouse button are not processed. 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 IInputEvent
instances.
The events passed to this class are expected to be defined in device independent pixels.
Constructor and Description |
---|
MouseGestureRecognizer(IInputEventCallback callback)
Creates a
MouseGestureRecognizer that passes the generated high level IInputEvent s to the given callback. |
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected void |
finalize() |
double |
getDisplayScale() |
double |
getDpi() |
ScreenDistance |
getDragThreshold() |
long |
getMultiClickInterval()
Returns the interval used to detect multiple clicks (default is 400 ms).
|
void |
onKeyEvent(KeyEvent keyEvent)
Entry point for the key events of the gesture recognizer.
|
void |
onMouseMoveEvent(MouseMoveEvent mouseMoveEvent)
Entry point for the mouse move events of the gesture recognizer.
|
void |
onMousePressedEvent(MousePressedEvent mousePressedEvent)
Entry point for the mouse pressed events of the gesture recognizer.
|
void |
onMouseReleasedEvent(MouseReleasedEvent mouseReleasedEvent)
Entry point for the mouse released events of the gesture recognizer.
|
void |
onScrollEvent(ScrollEvent scrollEvent)
Entry point for the scroll events of the gesture recognizer.
|
void |
setDisplayScale(double scale)
Set the display scale factor.
|
void |
setDpi(double dpi)
Set the display pixel density in dots per inch.
|
void |
setDragThreshold(ScreenDistance threshold)
Sets the screen distance that is used as threshold to detect if a drag is performed.
|
void |
setMultiClickInterval(long interval)
Set the interval used to detect multiple clicks (default is 400 ms).
|
public MouseGestureRecognizer(@NotNull IInputEventCallback callback) throws NullPointerException
MouseGestureRecognizer
that passes the generated high level IInputEvent
s to the given callback.callback
- the callback that receive generated IInputEvent
s. Can not be null
.NullPointerException
- If callback is null
.public void close()
close
in interface AutoCloseable
public void onMousePressedEvent(@NotNull MousePressedEvent mousePressedEvent)
mousePressedEvent
- the low level mouse press event.public void onMouseReleasedEvent(@NotNull MouseReleasedEvent mouseReleasedEvent)
mouseReleasedEvent
- the low level mouse released event.public void onMouseMoveEvent(@NotNull MouseMoveEvent mouseMoveEvent)
mouseMoveEvent
- the low level mouse move event.public void onScrollEvent(@NotNull ScrollEvent scrollEvent)
scrollEvent
- the low level mouse scroll event.public void onKeyEvent(@NotNull KeyEvent keyEvent)
keyEvent
- the low level key event.public void setMultiClickInterval(long interval)
interval
- the maximum time (in milliseconds) between multiple clicks. If the interval is set to 0, no multiple clicks will be detected.public long getMultiClickInterval()
public void setDragThreshold(@NotNull ScreenDistance threshold)
It means that the mouse cursor has to move at least that amount of pixels before it can be detected as a drag gesture.
The default value in device independent pixels is 2 pixels.
threshold
- the threshold@NotNull public ScreenDistance getDragThreshold()
public void setDpi(double dpi)
If no value is provided, the platform standard pixel density is assumed.
dpi
- the pixel density in dots per inchpublic double getDpi()
public void setDisplayScale(double scale)
If no value is provided, a scale factor of 1.0 is assumed.
scale
- the display scale factor (adimensional scale value)public double getDisplayScale()