Skip to main content
ihsanoglu
Senior
Nov 28, 2019 8:09 AM UTC
Solved

How to get Touch X and Y data ?

I need to get the X and Y coordinates of the touch controller and use them in Model or a View.

Is there a simple way to do this? (something in the API)

basically I want to get the x and y values returned from the sampleTouch() in TouchController class.

This topic has been closed for replies.
Martin KJELDSEN
Martin KJELDSENBest answer
Principal III
Nov 28, 2019 8:22 AM UTC

Implement the following virtual function in your view.

 /**
 * @fn virtual void Screen::handleClickEvent(const ClickEvent& evt);
 *
 * @brief Traverse the drawables in reverse z-order and notify them of a click event.
 *
 * Traverse the drawables in reverse z-order and notify them of a click event.
 *
 * @param evt The event to handle.
 */
 virtual void handleClickEvent(const ClickEvent& evt);

The ClickEvent has the data you need.

touchgfx/events/ClickEvent.hpp
 /**
 * @typedef enum ClickEventType
 *
 * @brief The click event types.
 */
 typedef enum
 {
 PRESSED, ///< An enum constant representing the pressed option
 RELEASED, ///< An enum constant representing the released option
 CANCEL ///< An enum constant representing the cancel option
 } ClickEventType;
...
private:
 ClickEventType _type;
 int16_t _x;
 int16_t _y;
};

2 replies

Martin KJELDSEN
Martin KJELDSENBest answer
Principal III
Nov 28, 2019 8:22 AM UTC

Implement the following virtual function in your view.

 /**
 * @fn virtual void Screen::handleClickEvent(const ClickEvent& evt);
 *
 * @brief Traverse the drawables in reverse z-order and notify them of a click event.
 *
 * Traverse the drawables in reverse z-order and notify them of a click event.
 *
 * @param evt The event to handle.
 */
 virtual void handleClickEvent(const ClickEvent& evt);

The ClickEvent has the data you need.

touchgfx/events/ClickEvent.hpp
 /**
 * @typedef enum ClickEventType
 *
 * @brief The click event types.
 */
 typedef enum
 {
 PRESSED, ///< An enum constant representing the pressed option
 RELEASED, ///< An enum constant representing the released option
 CANCEL ///< An enum constant representing the cancel option
 } ClickEventType;
...
private:
 ClickEventType _type;
 int16_t _x;
 int16_t _y;
};

ihsanoglu
ihsanogluAuthor
Senior
Nov 28, 2019 8:28 AM UTC

Thank You!