gui draw order

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
dehseth
Posts: 130
Joined: Wed Dec 09, 2009 11:05 am
Contact:

gui draw order

Post by dehseth »

hi irrlicht lovers,

I have a big background image and it needs to be drawn first, and other images should drawn after this big one. How can I set this (image, button, label etc) draw order in irrlicht gui?

thak you all! :D
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Code: Select all

button->getParent()->bringToFront(button)
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
dehseth
Posts: 130
Joined: Wed Dec 09, 2009 11:05 am
Contact:

Post by dehseth »

actually I need SendToBack function than BringToFront..... I want to send my image to back of z-order...
CuteAlien
Admin
Posts: 9687
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Hm, yeah - I think that's a missing function. For now - get all elements with getChildren() and call bringToFront for all except the one which you want to have in the back should do the trick. Adding some more functions to IGUIElement is on my todo (but not yet too high priority so far).
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
dehseth
Posts: 130
Joined: Wed Dec 09, 2009 11:05 am
Contact:

Post by dehseth »

yeap that's what I did but I just don't like it :)
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

You could always have an "Empty" GUI element (Like another GUI Environment) that all other GUI elements go in, then bring the whole empty one to the front. I don't remember if there is a built-in one, but it isn't to hard to make one (Basically like a custom scene node, but a GUI element and then all it does is render children.)

~Pathogen David
dehseth
Posts: 130
Joined: Wed Dec 09, 2009 11:05 am
Contact:

Post by dehseth »

thanks Dtd... but it is another some kind of workaround.. irrlicht developers, cant you just add a SendToBack function, or even a better solution "render z-order" functions, variables etc..
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

:roll: fine :P
This should work, but I didn't test it:

Code: Select all

diff -r a8a454de622a include/IGUIElement.h
--- a/include/IGUIElement.h	Fri May 28 00:38:07 2010 -0500
+++ b/include/IGUIElement.h	Thu Jul 01 01:06:27 2010 -0500
@@ -535,6 +535,25 @@
 		_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
 		return false;
 	}
+	
+	//! Sends a child to back
+	/** \return True if successful, false if not */
+	virtual bool sendToBack(IGUIElement* element)
+	{
+		core::list<IGUIElement*>::Iterator it = Children.begin();
+		for (; it != Children.end(); ++it)
+		{
+			if (element == (*it))
+			{
+				Children.erase(it);
+				Children.push_front(element);
+				return true;
+			}
+		}
+
+		_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
+		return false;
+	}
 
 
 	//! Returns list with children of this element
CuteAlien
Admin
Posts: 9687
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Hm, should be easy to change (and although it looks correct, it still needs to be tested ... everything looks correct until it breaks ^^). I would prefer calling it bringToBack (as the other function is called bringToFront, so names have some symmetry). And when adding it I also want bringToFrontOf which moves it in front of a specified other element. I try to find time on weekend (or some evening).


Edit: About dehseth proposal of allowing to set render-order in other ways than just parent-child relations. Well, nothing I'll probably manage to do by the way, but it's something I've also considered in the past sometimes. So far I always managed to work around such issues when they occurred, so I'm not sure if it is needed (could also complicate programming). Lets say - ideas on that are welcome, but should be accompanied with examples where it's necessary/useful.
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
CuteAlien
Admin
Posts: 9687
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Sorry, took a little longer as some bug-reports came in between which had to be handled first. But it's now in svn. I put the bringToBack in there using DtD's patch. Seemed to work in a quick test ;-) Thanks!
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
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

Just saw on the SVN RSS feed :D Cool!
Post Reply