Skip to main content
Pirol
Associate III
September 19, 2022
Solved

Stop getting two gesture events from one gesture

  • September 19, 2022
  • 6 replies
  • 1595 views

On a screen, I use the function handleGestureEvent. Inside this function, I have an if-else to differentiate between horizontal and vertical swipes:

void handleGestureEvent(const GestureEvent& event)
{
 if (event.getType() == GestureEvent::SWIPE_HORIZONTAL) 
 {
 /* ... */
 }
 else if (event.getType() == GestureEvent::SWIPE_VERTICAL) 
 {
 /* ... */
 }
}

(Could be else instead of else if, but for clarity...)

The problem is that from many swipes I get two gesture events: one horizontal and one vertical, both with the same x- and y-coordinates. I.e. handleGestureEvent is called, the if-branch is activated, then the function is called again and the else-branch is activated. event.getX() and event.getY() yield the same value in both calls.

I have neither found a possibility to set the thresholds for detecting a gesture as vertical or horizontal nor have I found the implementation oft registerDragEvent.

I use TouchGFX Designer 4.20.0.

This topic has been closed for replies.
Best answer by Yoann KLEIN

Indeed, the setDragThreshold() method purpose is to differentiate simple clicks from drags.

To be honest, I'm not sure how to achieve what you want to with the GestureEvents.

But, if you use DragEvents, there are methods like getDeltaX(), getDeltaY(), getOldX(), getNewX(),... That can help determine the starting coordinates, arrival coordinates, and deltas of your drag. Then, if you use some if statements (or switch cases) with manually set thresholds, you will be able to know if your drag was vertical or horizontal.

What do you think of it ?

/Yoann

6 replies

Yoann KLEIN
ST Employee
September 20, 2022

Hello @Pirol​ ,

Did you already try with setDragThreshold() method ?

/Yoann

Yoann KLEINST Software Developer | TouchGFX
Pirol
PirolAuthor
Associate III
September 20, 2022

Hello @Yoann KLEIN​ ,

yes, I have that in the constructor of HAL class:

HAL(...)
: ...
{
 instance = this;
 FRAME_BUFFER_WIDTH = DISPLAY_WIDTH = width;
 FRAME_BUFFER_HEIGHT = DISPLAY_HEIGHT = height;
 DISPLAY_ROTATION = rotate0;
 nativeDisplayOrientation = ((width >= height) ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT);
 setDragThreshold(50);
}

Is that the right place? It has indeed an effect: Clicks and swipes are distinguished from each other. But the swipes are not.

I don't know why it does not help with the swipes: The coordinates that are send to TS_State in STM32TouchController.cpp are, for example, (184, 157), (115, 161), (77, 163). They triggered a horizontal and a vertical swipe although the vertical delta is only 6 and not 50.

It is possible to trigger only one of the swipes. E.g. coordinates (239, 255), (239, 255), (239, 255), (188, 258), (112, 257), (24, 259), (24, 259). This triggered a horizontal but no vertical swipe.

The board is a custom board.

Yoann KLEIN
Yoann KLEINBest answer
ST Employee
September 21, 2022

Indeed, the setDragThreshold() method purpose is to differentiate simple clicks from drags.

To be honest, I'm not sure how to achieve what you want to with the GestureEvents.

But, if you use DragEvents, there are methods like getDeltaX(), getDeltaY(), getOldX(), getNewX(),... That can help determine the starting coordinates, arrival coordinates, and deltas of your drag. Then, if you use some if statements (or switch cases) with manually set thresholds, you will be able to know if your drag was vertical or horizontal.

What do you think of it ?

/Yoann

Yoann KLEINST Software Developer | TouchGFX