Implement own Wait function with own code in View.cpp
TouchGFX 4.16.1, Win10 (I promise I will update to 4.17)
I'm working on a project where I create an array of custom elements purely with code, such as an array of scrollable containers filled with the array of boxes and textAreas with wildcards, custom buttons (these still in work). It took a while to figure it out, but I added my own callback function to my button (for now just one), etc. (mainly by creating element in TouchGFX designer, generating code and then copy-paste-understand-modifying).
The one thing I'm failing to implement on my own at this point is wait function. Like I want to click a button, wait and then do whatever (or any other use for wait).
I've created a button and a box in TouchGFX Designer, added interactions with Wait (box changes color after 1000ms), so that I have a working code of wait that I can break down. The code for wait turned out to be pretty simple: it calls ViewBase::handleTickEvent on every tick and simply does a countdown. You set the number of ms, it's converted into number of frames.
Auto-generated wait in ViewBase.cpp looks like this:
void ScreenMeasurementsViewBase::handleTickEvent()
{
if(interaction1Counter > 0)
{
interaction1Counter--;
if(interaction1Counter == 0)
{
//Interaction2
//When Interaction1 completed change color of box1
//Set RGB color R:255, G:72, B:72 on box1
box1.setColor(touchgfx::Color::getColorFrom24BitRGB(255,72,72));
box1.invalidate();
}
}
}The problem is that the interaction counter is actually private, so I can't set it to anything on my own.
So, I figure, I'll have my own handleTickEvent function in View.cpp with blackjack my own interaction counter. Just as I created my own callback for my buttons. Piece of cake.
So, in View.cpp, I've created my own interaction counter variable and handleTickEvent function in View.cpp. So ViewBase and View cpp of the screen each have their own handleTickEvent.
Turned out, when they both exist at the same time, wait simply doesn't work. The interaction doesn't start and the chain of interactions is basically frozen. I'm actually not sure if my function gets called on every tick at all, but it seems to destroy the work of auto-generated Wait, so I guess something is happening, except that none of the waits works as intended then.
Here is my function in View.cpp, not very inventive:
void ScreenMeasurementsView::handleTickEvent() {
if (WAIT_TIMER_TICKS > 0) {
WAIT_TIMER_TICKS--;
if (WAIT_TIMER_TICKS == 0) {
}
}
}Maybe I should find some global tick handler independent of the screen and be like "hey on every tick if you're also on screen ScreenWithCustomWait (how do I check it?) then do THIS (this = my own tick handler for the screen with my custom wait). Or maybe there is a simpler way, I actually don't know, which exactly why I'm asking.
