GUI questions

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.
UncleBob
Posts: 106
Joined: Fri May 01, 2009 8:46 am

Post by UncleBob »

CGUIEmptyElement is a sub-class of IGUIElement,
Ah, it's a sub-class. Somehow I mistook it for a derived class...

thanks for the code examples, and for the help in general. I think I should get it rolling now.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

CGUIElement is dervived from IGUIElement. I guess sub-class meant the same in that context.

And you will most likely want to work with heap-memory and not with stack-memory. Which means to use new, like:

Code: Select all

CGUIEmptyElement * myRootElement = new CGUIEmptyElement(environment, environment->getRootGUIElement() );
And you can certainly put myRootElement in another class which might for example be your dialog class. I have usually one class per dialog (or per screen - it's often the same) in my code and that turned out to be rather useful. Which means I have for example a class DlgMainMenu and one class DlgHighscores and another class DlgHUD (for ingame). Each class has one CGUIEmptyElement * pointer which is always the root-element (the parent of all others elements in that class). But those Dlg classe also often have additional pointers to other gui-elements which I need to access and offer general functions useful for that screen, etc.

Also you don't _need_ the CGUIEmptyElement object, there are also other solutions to do the same. For example you can save a pointer to _every_ gui-element which you use in one screen and then call setVisible for all of them. When you keep all gui-elements in a class you can have one function doing that. Or you can also drop all pointers and re-create them which means the gui-elements wouldn't just be hidden but really destroyed when they are not needed. Using 1 parent like the CGUIEmptyElement is just a little easier sometimes, so I can recommend it.
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
UncleBob
Posts: 106
Joined: Fri May 01, 2009 8:46 am

Post by UncleBob »

Wow, moderators are somewhat fast here... :)
Also you don't _need_ the CGUIEmptyElement object, there are also other solutions to do the same. For example you can save a pointer to _every_ gui-element which you use in one screen and then call setVisible for all of them.
I actually started doing something along those lines this morning, until I understood what your empty element actually does. As It seems a much more convenient way I abandoned that undertaking.

However, I still have a problem I seem unable to solve. I have no more build errors and can execute the program without any trouble whatsoever. There's just nothing of the GUI showing on screen... :/

Here's what I did:

Code: Select all

//first, creating the element and the pointer and setting the size of the element to the whole screen as per your advice:

	CGUIEmptyElement SystemMapGUI(mGUI, 0); 
	IGUIElement* SystemMapGUIPtr = (IGUIElement*)(&SystemMapGUI);

	SystemMapGUI.setRelativePosition( core::rect<s32>(0,0,ScreenRes.X,ScreenRes.Y));

//then I add a table to it

	gui::IGUITable *SolarTable = mGUI->addTable(core::rect<s32>(ScreenRes.X * 0.03, 300, ScreenRes.X - ScreenRes.X * 0.03,502), SystemMapGUIPtr);	

	
	SolarTable->addColumn(L"", 0);
	SolarTable->addColumn(L"", 1);
	
	SolarTable->setColumnWidth(0, SolarTable->getAbsoluteClippingRect().getWidth() / 2);
	SolarTable->setColumnWidth(1, SolarTable->getAbsoluteClippingRect().getWidth() / 2);

	SolarTable->addRow(0);
	SolarTable->addRow(1);
	SolarTable->addRow(2);
	SolarTable->addRow(3);
	SolarTable->addRow(4);
	SolarTable->addRow(5);
	SolarTable->addRow(6);
	SolarTable->addRow(7);
	SolarTable->addRow(8);


//Finally I call bringToFront and draw the environment, I do this last in the draw loop:

		SystemMapGUI.bringToFront(SystemMapGUIPtr);
		device->getGUIEnvironment()->drawAll(); 
As I said, this results in no GUI on screen. I tried to additionaly call SystemMapGUI.addchild(SolarTable), but the result is the same. What do I miss?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

UncleBob wrote:Wow, moderators are somewhat fast here... :)
Yes, we have a lot of such Spam posts lately, so they are immediately removed.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Use environment->getRootGUIElement() instead of 0 as second parameter. Otherwise it's not added to the guienvironment and it doesn't know about the elements on drawing. Also as mentioned above - you should use heap memory instead of stack memory. Which means - allocate with "new". The reason for that is that gui-elements will internally grab/drop the pointers and you should never do that for stack-allocated memory. And then you do that you can even pass it directly to your SystemMapGUIPtr like:

Code: Select all

IGUIElement* SystemMapGUIPtr = new CGUIEmptyElement( mGUI, mGUI->getRootGUIElement() );
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
UncleBob
Posts: 106
Joined: Fri May 01, 2009 8:46 am

Post by UncleBob »

Haha, it works!!

Great. at least some result at the end of the day, thanks a lot. I'm still fighting to get the eventhandling right, seems to be a bit stuborn with the MastEventReceiver...

Edit: Never mind. I got the eventreceiver working too yeeeeha! :D

thanks for all the help!! Until next time!
UncleBob
Posts: 106
Joined: Fri May 01, 2009 8:46 am

Post by UncleBob »

Hmmm, another (hopefully small) problem has popped up. I'm passing the GUI element on to a class that will edit it (dynamic tables and stuff like that).

Now I'm trying to access the children of the empty element. For doing this I found some code on the forum here which I adapted, goes like this:

Code: Select all

			core::list<gui::IGUIElement*> myTables;
			myTables = myGUI->getChildren();
			for(core::list<gui::IGUIElement*>::Iterator it = myTables.begin(); it != myTables.end(); ++it)
			{

				(*it)->setCellText(0,1, std::wstring(Sun.Name.begin(), Sun.Name.end()).c_str());
			}
It all actualy works properly, the problem is that what I'm getting here is an IGUIElement, which doesn't have a "setcelltext" function, meaning I can't set another text in my tables. Is there a way to get a pointer of type IGUITable so I can edit my tables?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

UncleBob wrote:Is there a way to get a pointer of type IGUITable so I can edit my tables?
yes, do a cast... ;)

Code: Select all

(IGUITable*(*it))->setCellText(0,1, std::wstring(Sun.Name.begin(), Sun.Name.end()).c_str()); 
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
UncleBob
Posts: 106
Joined: Fri May 01, 2009 8:46 am

Post by UncleBob »

man, I'm going to cast the devil out of hell accidentaly of things go on like this... :lol:

it doesn't work yet, though... compiler claims there's a missing ) before "it". Here's my line now:

(gui::IGUITable*(*it))->setCellText(0,1, std::wstring(Sun.Name.begin(), Sun.Name.end()).c_str());

With everything casted somewhere in that statement I really lost every bit of oversight...
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

oh, yeah, I also lost a bit overview... :lol:
I missed 2 braces :oops: :

Code: Select all

((IGUITable*)(*it))->setCellText(0,1, std::wstring(Sun.Name.begin(), Sun.Name.end()).c_str()); 
or to get more insight:

Code: Select all

IGUITable* tbl = (IGUITable*)*it;
tbl->setCellText(0,1, std::wstring(Sun.Name.begin(), Sun.Name.end()).c_str()); 
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
UncleBob
Posts: 106
Joined: Fri May 01, 2009 8:46 am

Post by UncleBob »

works great now, thanks a lot!
Post Reply