Skip to main content
ihsanoglu
Senior
November 28, 2019
Solved

How to get Touch X and Y data ?

  • November 28, 2019
  • 2 replies
  • 983 views

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.
Best answer by Martin KJELDSEN

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
November 28, 2019

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
November 28, 2019

Thank You!