2020-12-09 01:29 PM
Hello!
I want to put on screen box, iamge or other rectangular object.
I want to catch event when this object is clicked and read coordinates of click.
How to do it?
At first i tried read coordinates after clicking button. I added iteraction to button, which start c++ function GET_TOUCH()
#include <STM32TouchController.hpp>
void GET_TOUCH()
{
uint32_t x,y;
// Override and implement this function in OPTIONS_SCREEN
STM32TouchController::sampleTouch(x,y);
}
I got error
"../touchgfx/gui/src/options_screen_screen/options_screenview.cpp(115): error: #245: a nonstatic member reference must be relative to a specific object@"
How to call sampleTouch(x,y) correctly?
Solved! Go to Solution.
2020-12-09 07:37 PM
The reason you can't call it like that is just as the error describes: the sampleTouch function isn't static (independent of an object instance). Because there are no references to sampleTouch() anywhere in a TouchGFX created project other than the method in STM32TouchController itself, it's safe to assume that function is called only by the TouchGFX library.
TouchGFX provides a way to get the coordinates of a touch however. You are looking for ClickEvents. A callback with a ClickEvent parameter is generated by any Drawable with the ClickListener mixin.
Example Implementation:
if(evt.getType() == ClickEvent::PRESSED){
int x = evt.getX();
int y = evt.getY();
// Do something with x and y, such as...
presenter->touchRegistered(x, y); // you write this function in the presenter
}
2020-12-09 07:37 PM
The reason you can't call it like that is just as the error describes: the sampleTouch function isn't static (independent of an object instance). Because there are no references to sampleTouch() anywhere in a TouchGFX created project other than the method in STM32TouchController itself, it's safe to assume that function is called only by the TouchGFX library.
TouchGFX provides a way to get the coordinates of a touch however. You are looking for ClickEvents. A callback with a ClickEvent parameter is generated by any Drawable with the ClickListener mixin.
Example Implementation:
if(evt.getType() == ClickEvent::PRESSED){
int x = evt.getX();
int y = evt.getY();
// Do something with x and y, such as...
presenter->touchRegistered(x, y); // you write this function in the presenter
}
2020-12-09 08:21 PM
Hello,
To be able to click an image or a box, add a clickListener to your object (image or box) and write some code callback for the click event.
I enclosed a simple example. If you run simulator, and click on the red box, the green box will change to blue.
When your question is answered, please close this topic by choosing Select as Best.
/Alexandre
2020-12-12 01:03 AM
Sorry, I can't understand something
I get new coordinates each time when I press Box1. But I want to get coordinates each time, when my fingers moves, without releasing and new pressing. Like Slider widget gives new position while sliding.
How?
2020-12-12 06:52 AM
Does it work if you remove the if(evt.getType() == ClickEvent::PRESSED) condition?
2020-12-12 08:23 AM
No. If I remove this condition, I get coordinates twice - after press and after release.
2020-12-14 10:27 AM
I've never used these so I can't comment on it as a solution to your problem necessarily but you might want to look into DragEvents. Good luck, and let me know if it works!