2021-05-19 03:31 AM
Thank you for helping.
At the event of pressing the button of the view class
Is there a way to find out the touched X, Y coordinates?
Thank you.
Solved! Go to Solution.
2021-05-19 09:53 PM
Hi Ebun.1,
You cannot do that simply like this.
I would highly recommend you to use handleClickEvent() function and do something like :
void Screen1View::handleClickEvent(const ClickEvent& evt)
{
if(button1.getAbsoluteRect().intersect(evt.getX(), evt.getY()))
{
if(evt.getType() == ClickEvent::PRESSED)
{
//retrieve x, y with evt.getX()/evt.getY()
//Do whatever you want, you can even call other functions
}
}
Screen1ViewBase::handleClickEvent(evt);
}
/Alexandre
2021-05-19 08:00 PM
Hello Ebun.1,
You simply need to implement the handleClickEvent() function in your view to receive the click events.
void Screen1View::handleClickEvent(const ClickEvent& evt)
{
touchgfx_printf("Cooordinates of the click event : x = %d/ y = %d\n", evt.getX(), evt.getY());
Screen1ViewBase::handleClickEvent(evt);
}
When your question is answered, please close this topic by choosing Select as Best.
/Alexandre
2021-05-19 09:18 PM
Hi Alexandre RENOUX
Thank you for helping.
I have an interaction when the button is pressed.
How can I get x and y in this?
Screen1View :: pushedButton ()
{
// get x, y
}
2021-05-19 09:53 PM
Hi Ebun.1,
You cannot do that simply like this.
I would highly recommend you to use handleClickEvent() function and do something like :
void Screen1View::handleClickEvent(const ClickEvent& evt)
{
if(button1.getAbsoluteRect().intersect(evt.getX(), evt.getY()))
{
if(evt.getType() == ClickEvent::PRESSED)
{
//retrieve x, y with evt.getX()/evt.getY()
//Do whatever you want, you can even call other functions
}
}
Screen1ViewBase::handleClickEvent(evt);
}
/Alexandre
2021-05-19 10:23 PM
Hi Alexandre RENOUX
I am always grateful for your help.
It's not easy, isn't it?
Thank you for your answer.
2021-09-08 04:47 AM
Could you please explain your solution a little more clearly? I am having the same problem.
2021-09-08 03:33 PM
Hello.
I wanted to know the raw value before the coordinate transformation, so
I decided to save the coordinates in a global variable in BSP_TS_GetState () and use it.
2021-09-08 04:19 PM
The example looks to be pulling the X and Y coordinates at the event, then determining if those are within the boundaries of the button image on the screen, and then allowing you to take a specific action. If you want to remember the X,Y coordinates save them in a variable or class where you can get at them later, or pass them to a processing function.
2021-09-08 08:17 PM
Hey,
you can try this one too, hope it may works for you.
OnTouchListener mOnTouch = new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
final int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN: {
final int x = (int) ev.getX();
final int y = (int) ev.getY();
break;
}
};
And if its works and you already got one please mention it too. Thanks.