cancel
Showing results for 
Search instead for 
Did you mean: 

Stop getting two gesture events from one gesture

Pirol
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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 KLEIN
ST Software Developer | TouchGFX

View solution in original post

6 REPLIES 6
Yoann KLEIN
ST Employee

Hello @Pirol​ ,

Did you already try with setDragThreshold() method ?

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX

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.

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 KLEIN
ST Software Developer | TouchGFX
Pirol
Associate III

Hello Yoann,

thanks for your advice. It works.

I thought that such an if-structure was implemented at the place where the events are "made", i.e. where the events are given their attributes like type=SWIPE_HORIZONTAL and the coordinates etc.

Why is there no possibility for the gesture events to set a threshold for distinguishing between horizontal and vertical swipes? Maybe that would be a nice feature for a future release.

To be honest I don't know if there is a way or not to do that.

I understand that it should be already supported by TouchGFX.

I will discuss that with my colleagues.

Nice to hear that it works though.

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX
Pirol
Associate III

Okay, thanks for your help!