Skip to main content
Breeze1
Associate III
August 12, 2019
Solved

Events, how to figure out a gesture is a ClickEvent or a GesturEvent?

  • August 12, 2019
  • 2 replies
  • 1655 views

I am using touchGFX to develop a screen. Now there is a problem .When I add a ClickListener and ClickAction Callback to a box, a click on the box will be identified as a click. But if I want to use a gesture on the box , I found it will be identified as a click too. It is not what I want. I found a article in TouchGFX Knowledge base , but I was told I'm not authorized to access this page. Can anyone help me solve this problem? Or can anyone access this page? The address is https://touchgfx.zendesk.com/hc/en-us/articles/205983261

Thanks a lot!

This topic has been closed for replies.
Best answer by Martin KJELDSEN

Hi @Breeze​,

What do you mean by "Want to use a gesture", exactly? What kind of gesture? TouchGFX does not support "gestures", in the classic sense, except swipe. You have some handlers available to you:

/**
 * @fn virtual void Drawable::handleDragEvent(const DragEvent& evt)
 *
 * @brief Defines the event handler interface for DragEvents.
 *
 * Defines the event handler interface for DragEvents. The event is only received if
 * the drawable is touchable.
 *
 * @param evt The DragEvent received from the HAL.
 */
 virtual void handleDragEvent(const DragEvent& evt) { }
 
 /**
 * @fn virtual void Drawable::handleClickEvent(const ClickEvent& evt)
 *
 * @brief Defines the event handler interface for ClickEvents.
 *
 * Defines the event handler interface for ClickEvents. The default implementation
 * ignores the event. The event is only received if the drawable is touchable.
 *
 * @param evt The ClickEvent received from the HAL.
 */
 virtual void handleClickEvent(const ClickEvent& evt) { }
 
 /**
 * @fn virtual void Drawable::handleGestureEvent(const GestureEvent& evt)
 *
 * @brief Defines the event handler interface for GestureEvents.
 *
 * Defines the event handler interface for GestureEvents. The default implementation
 * ignores the event. The event is only received if the drawable is touchable.
 *
 * @param evt The GestureEvent received from the HAL.
 */
 virtual void handleGestureEvent(const GestureEvent& evt) { }
  • handleClickEvent() - event type can be either CLICKED or RELEASED. This method will be called if the touch controller samples a coordinate. It will also be called if you're starting a drag event (CLICKED), and when you finish your dragevent (RELEASED).
  • handleDragEvent() - allows you to get the movement delta for x and y between ticks and also the old and new value.
  • handleGestureEvent() - TouchGFX HAL uses this when it evaluates touch input to determine if a gesture was performed. The GestureEvent holds the gesturetype.
typedef enum
{
 SWIPE_HORIZONTAL, ///< An enum constant representing a horizontal swipe
 SWIPE_VERTICAL ///< An enum constant representing a vertical swipe
} GestureType;

In conclusion:

Implement these handlers in your view or in your widgets to see how TouchGFX interprets the touch events you produce. For a simple touch you'll get two calls to handleClickEvent() (screen press/release). For a drag you'll receive at least 3 calls.

  1. handleClickEvent() - Pressed
  2. handleDragEvent() - Investigate your newx, newy or even deltas to see what happened.
  3. handleClickEvent() - Released

The ScrollableContainer and the SwipeContainer (touchgfx\containers\) both use handleGestureEvent() to properly react to swipes.

/Martin

2 replies

Martin KJELDSEN
Martin KJELDSENBest answer
Principal III
August 13, 2019

Hi @Breeze​,

What do you mean by "Want to use a gesture", exactly? What kind of gesture? TouchGFX does not support "gestures", in the classic sense, except swipe. You have some handlers available to you:

/**
 * @fn virtual void Drawable::handleDragEvent(const DragEvent& evt)
 *
 * @brief Defines the event handler interface for DragEvents.
 *
 * Defines the event handler interface for DragEvents. The event is only received if
 * the drawable is touchable.
 *
 * @param evt The DragEvent received from the HAL.
 */
 virtual void handleDragEvent(const DragEvent& evt) { }
 
 /**
 * @fn virtual void Drawable::handleClickEvent(const ClickEvent& evt)
 *
 * @brief Defines the event handler interface for ClickEvents.
 *
 * Defines the event handler interface for ClickEvents. The default implementation
 * ignores the event. The event is only received if the drawable is touchable.
 *
 * @param evt The ClickEvent received from the HAL.
 */
 virtual void handleClickEvent(const ClickEvent& evt) { }
 
 /**
 * @fn virtual void Drawable::handleGestureEvent(const GestureEvent& evt)
 *
 * @brief Defines the event handler interface for GestureEvents.
 *
 * Defines the event handler interface for GestureEvents. The default implementation
 * ignores the event. The event is only received if the drawable is touchable.
 *
 * @param evt The GestureEvent received from the HAL.
 */
 virtual void handleGestureEvent(const GestureEvent& evt) { }
  • handleClickEvent() - event type can be either CLICKED or RELEASED. This method will be called if the touch controller samples a coordinate. It will also be called if you're starting a drag event (CLICKED), and when you finish your dragevent (RELEASED).
  • handleDragEvent() - allows you to get the movement delta for x and y between ticks and also the old and new value.
  • handleGestureEvent() - TouchGFX HAL uses this when it evaluates touch input to determine if a gesture was performed. The GestureEvent holds the gesturetype.
typedef enum
{
 SWIPE_HORIZONTAL, ///< An enum constant representing a horizontal swipe
 SWIPE_VERTICAL ///< An enum constant representing a vertical swipe
} GestureType;

In conclusion:

Implement these handlers in your view or in your widgets to see how TouchGFX interprets the touch events you produce. For a simple touch you'll get two calls to handleClickEvent() (screen press/release). For a drag you'll receive at least 3 calls.

  1. handleClickEvent() - Pressed
  2. handleDragEvent() - Investigate your newx, newy or even deltas to see what happened.
  3. handleClickEvent() - Released

The ScrollableContainer and the SwipeContainer (touchgfx\containers\) both use handleGestureEvent() to properly react to swipes.

/Martin

Breeze1
Breeze1Author
Associate III
August 16, 2019

Thanks for your answer.

My "Gesture" also means swipe. I found in Screen , there are two virtual function, virtual void handleClickEvent(const ClickEvent& evt) and virtual void handleGestureEvent(const GestureEvent& evt). If I am using these two functions in my Screen. It always easy to response handleClickEvent, but hard to response handleGestureEvent . So I want to konw waht can I do to make it work properly.

Breeze1
Breeze1Author
Associate III
August 16, 2019

Thanks for your answer.

My "Gesture" also means swipe. I found in Screen , there are two virtual function, virtual void handleClickEvent(const ClickEvent& evt) and virtual void handleGestureEvent(const GestureEvent& evt). If I am using these two functions in my Screen. It always easy to response handleClickEvent, but hard to response handleGestureEvent . So I want to konw waht can I do to make it work properly.