Home » U++ Library support » U++ Widgets - General questions or Mixed problems » Refresh(), Paint(Draw& w), or something else nearby?
Refresh(), Paint(Draw& w), or something else nearby? [message #10381] |
Wed, 04 July 2007 20:58  |
kverko
Messages: 8 Registered: December 2005 Location: Porva, Hungary
|
Promising Member |
|
|
Hi!
I have coded a little cell automat program. When I have put the step to the next cycle into a left click event handler, it did work. Now I use the SetTimeCallback function from the AnimatedHello example and it does work.
What I can no manage is to put the cycle control into the execution flow. For example I did:
function Steps()
{
for(int i=0;i<1000;i++)
{
Step();
}
}
function Step()
{
Refresh();
}
And it does not work. The Step function is the same as in the SetTimeCallback! (Or in LeftDown.) The counting of next generation is in the Paint(Draw& w) function.
I am afraid of the counting the next generation could be longer than the timing of callback on a slower machine. Anyway I can not see, why does not work the simple code above. Or how other way can I set up the cycle control?
|
|
|
Re: Refresh(), Paint(Draw& w), or something else nearby? [message #10390 is a reply to message #10381] |
Thu, 05 July 2007 12:07   |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
The reason that this doesn't work is that Refresh doesn't call Paint immediately. Paint will only get called once and only after your code has finished.
One solution:
void Step()
{
bool quit = false;
Refresh();
ProcessEvents(&quit); // Force Refresh event to be executed
// If quit is true here then exit the app
}
Thie would draw each step as it is generated. I would advise against having the cell update code in Paint though.
And to fix the the TimerCallback problem of the step taking longer than the callback, if you change the timing from a negative to a positive number then you have to re-issue the callback every time it executes. This means you could complete the calculation of the next generation before you set the callback:
void OnTimer()
{
UpdateCells();
Refresh();
SetTimerCallback(40, THISBACK(OnTimer));
}
James
[Updated on: Thu, 05 July 2007 12:19] Report message to a moderator
|
|
|
|
|
|
Goto Forum:
Current Time: Mon Apr 28 12:07:37 CEST 2025
Total time taken to generate the page: 0.00918 seconds
|