On 10/30/21 8:13 PM Rob McDonald wrote:
> Thanks for the tips Albrecht, I will check those things out.
>
> Right now, I am having trouble doing a for-loop across all tabs in a
> particular GUI. Despite calling show(), I get repeated images of the
> default tab rather than of each one....
Looking at your code below I believe that my proposals would fix your
issues and I strongly recommend to change your code before you waste
time pursuing your current strategy. I'll explain the details below.
> How can I programmatically cycle through displaying tabs?
Independent of your code below, if 'tabs' is the Fl_Tabs widget, you
would show() all individual children as you probably tried with your
m_TabGroupVec (whose contents I don't know).
A simple loop would be like:
int nc = tabs->children();
for (int i = 0; i< nc; i++) {
tabs->child(i)->show();
}
But that alone doesn't solve your problem ...
> My code does this -- I realize there are parts relating to my larger
> application, but hopefully it should make enough sense that someone
> can help me.
>
[some code removed]
> for ( int itab = 0; itab < ( int )m_TabGroupVec.size(); itab++ )
> {
> Fl_Group* tab = m_TabGroupVec[itab];
>
> tab->show();
> Fl::wait();
Calling Fl:.wait() once does not guarantee that drawing occurs and that
the window contents gets updated ...
> uchar *p = fl_read_image( NULL, 0, 0, w, h, alpha );
... and therefore this fl_read_image() call will very likely read the
"old" contents from the window.
If you *really* wanted to follow this route you'd better do something
like ending your callback and trigger a timeout (which would occur after
drawing the window) and then ... But I don't recommend this, it makes
things only complicated.
I think it's easier to do it like test/device.cxx which uses a direct
draw() call to draw the window to an offline image and then you can use
that image. This can supposedly be done in a loop w/o any side effects
(other than taking some time and making the user interface unresponsive).
My demo does a similar thing with Fl_Copy_Surface as an example but
Fl_Image_Surface works very similar and would give you what you need.
Instead of calling fl_read_image() you should use Fl_Image_Surface to
draw onto and then use Fl_Image_Surface::image() to get the RGB image as
in the test/device demo.
Whether your tabs logic does the right thing I can't tell, but see above.