GUI Parent/Child visibility

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Pan
Posts: 24
Joined: Tue Jan 20, 2009 9:36 am
Location: Bavaria, Germany

GUI Parent/Child visibility

Post by Pan »

Hi,
this is just a quick question about a problem I'm having.

I'd like to have a GUI element (an IGUIImage to be specific) as a parent for several buttons, in order to switch them on and off via only a single setVisibility() call to the parent image.

Now the parent image switches on/off just fine, however the child buttons are never to be seen, regardles of the parent's visibility state.
(They are seen when the parent is just set to NULL, so it's not the children's fault.)

Is there any way to make this work via parent-child relationships between GUI elements? (It works for windows. Calling setVisibility() for an IGUIWindow also disables all child elements.. or is this a special case for GUI elements?)
Wanted: Schrödingers Cat. Dead or alive.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

It should already work by setting the parent visibility. Windows and images work the same in this regard (as does every other gui-element). I suppose there is some other problem in your code. If you post it we might be able to help.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Pan
Posts: 24
Joined: Tue Jan 20, 2009 9:36 am
Location: Bavaria, Germany

Post by Pan »

Here goes:

Code: Select all

// parent element
IGUIImage* parent = gui->addImage( rect<s32>(..),0,-1, .. );
parent->setVisible( false );
parent->setUseAlphaChannel( true  );

// child element
IGUIButton* child = gui->addButton( rect<s32>(..), parent, .. );
child->setImage( .. );
child->setPressedImage( .. );
child->setDrawBorder( false );
child->setUseAlphaChannel( true  );

Code: Select all

// event receiver part to toggle parent
if( <visible> )
    parent->setVisible( false );
else
    parent->setVisible( true );
All ommitted parameters are just constants which should be fine since all is displayed correctly, only the two elements don't seem to be linked.

(If this doesn't help, I can post the actual code as well.)
Wanted: Schrödingers Cat. Dead or alive.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Well, we can't test the code until it runs. So yes, actual code would be better. But maybe it's clipping. If the rect of your image is too small then the child-buttons might simply get clipped away.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Pan
Posts: 24
Joined: Tue Jan 20, 2009 9:36 am
Location: Bavaria, Germany

Post by Pan »

Ok, I simplified my example to a case that still doesn't work:

Code: Select all

// parent element 
IGUIImage* parent = gui->addImage( rect<s32>(10,10,50,50),0 ); 
parent->setVisible( true ); 
parent->setUseAlphaChannel( true ); 

// child element 
IGUIButton* child = gui->addButton( rect<s32>(50,50,90,90), parent); 
child->setImage( driver->getTexture("textures/buttons/box_std.png") ); 
child->setPressedImage( driver->getTexture("textures/buttons/box_mc.png") ); 
child->setDrawBorder( false ); 
child->setUseAlphaChannel( true );
This should be correct, however only the parent rectangle is actually drawn.
When I change the following line:

Code: Select all

IGUIButton* child = gui->addButton( rect<s32>(50,50,90,90), parent); 
to

Code: Select all

IGUIButton* child = gui->addButton( rect<s32>(50,50,90,90), 0); 
Then both rectangles are drawn, and the only difference should be the parent-child link?
Wanted: Schrödingers Cat. Dead or alive.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Check the rect's. They are always relative to the parent so in this case the button is outside the parent area. So it will get clipped. Increase the image size and it should work.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

CuteAlien is right !!!
your image size is 40x40 and the button starts at position (50, 50) !!! :lol:
even if it was not relative to the parent your image ends at (50, 50) and the button starts at (50, 50) so the button could never be seen... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Pan
Posts: 24
Joined: Tue Jan 20, 2009 9:36 am
Location: Bavaria, Germany

Post by Pan »

Ah, now that makes sense :idea:

Thanks alot!
Wanted: Schrödingers Cat. Dead or alive.
RoBaTte
Posts: 10
Joined: Thu Jun 07, 2007 2:34 pm

Post by RoBaTte »

ah nice, I had to figure out the same thing and now I read the solution.
But, is there any way to have the same parent-child behaviour like ISceneNodes have? Means, that I can have an IGUIElemtent as a child of another one but outside of the parents rect? So that the child-element moves along with the parent. Because I have some IGUIImages with captions and I dont want to calculate the coordinates of the text all the time I move the images.

greetings. Rob
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Childs should already move with the parents. To have them drawn outside the parents rect you have to set childElemnt->setNotClipped(true).

I usually use another solution - I use a parent with a sufficiently large rect, but which is not drawing anything (like a statictext element without text, background and border).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
RoBaTte
Posts: 10
Joined: Thu Jun 07, 2007 2:34 pm

Post by RoBaTte »

that's it :)
thank you.
Post Reply