Page 1 of 1

gui draw order

Posted: Wed Jun 30, 2010 12:11 pm
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

Posted: Wed Jun 30, 2010 12:58 pm
by BlindSide

Code: Select all

button->getParent()->bringToFront(button)

Posted: Wed Jun 30, 2010 1:01 pm
by dehseth
actually I need SendToBack function than BringToFront..... I want to send my image to back of z-order...

Posted: Wed Jun 30, 2010 1:46 pm
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).

Posted: Wed Jun 30, 2010 2:28 pm
by dehseth
yeap that's what I did but I just don't like it :)

Posted: Wed Jun 30, 2010 10:15 pm
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

Posted: Thu Jul 01, 2010 4:57 am
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..

Posted: Thu Jul 01, 2010 6:10 am
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

Posted: Thu Jul 01, 2010 8:01 am
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.

Posted: Sat Jul 17, 2010 6:31 pm
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!

Posted: Mon Jul 19, 2010 3:23 am
by DtD
Just saw on the SVN RSS feed :D Cool!