Jane wrote:
> hello,
> 
> this is the situation:
> main() creates an instance of my "ui" class which contains 
> a piano widget. main calls ui->startup(); which first shows 
> a window of ui and then creates instances of other objects 
> which will then feed the ui widgets with some data.
> the piano widget is one of those receivers. the data it 
> receives will be used with information with x() and y() 
> values of piano. so, piano receives the external data, 
> calculates some values based on this data and x() and y(), 
> and is happy.
> but, sometimes it happens that the piano doesnt know its 
> x() and y() in the moment the data is being received, 
> resulting in garbage data.

Why do you think that the piano widget doesn't know its x() and y()? 
This can't happen at all, because the widget knows its x() and y() 
immediately after (and even within) its constructor, regardless if it 
has been drawn already or not. However, it may or may not know its 
absolute display coordinates, if the window has not been displayed yet.

> now, the x() and y() information is available when the 
> piano widget is first being drawn, right?

Sure, that's true, but it shouldn't matter (see above). What are you 
doing with the piano widget's x() and y() coordinates that is needed to 
do this startup processing?

> why isnt piano finished drawing when i instanciate my other 
> objects AFTER calling w_main->show(); ?

You should read what Ian wrote to answer this question.

>     w_main->show();
>     ctrl = new ctrl(); // gets external data, feeds it to 
> widget...widget however has not been drawn yet.

To help you more, we would surely need to see more of your code, at 
least more of your main() program. I assume that all this happens before 
you call Fl::run(). Although calling Fl::check() can help much (as Ian 
wrote), I wouldn't try to do this, unless you know exactly, why you are 
doing it. When I once had a similar startup problem, I used an idle 
callback or a timeout with a short time to do the startup code after 
initializing the UI, something like (only short pseudo code):

main()
{
   gui *win = new gui(...);
   add more widgets here.
   win->show(...);
   Fl::add_idle(...); // or Fl::add_timeout(...)
   Fl::run();
}

The idle or timeout callback can then do more initialization, after the 
gui has been initialized.

Albrecht
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to