cancel
Showing results for 
Search instead for 
Did you mean: 

How to get Touch X and Y data ?

ihsanoglu
Senior

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Martin KJELDSEN
Chief III

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;
};

View solution in original post

2 REPLIES 2
Martin KJELDSEN
Chief III

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;
};

Thank You!