Hi,
I am new to C++ and Irrlicht, so thanks in advance for all answers and comments!
I wondered how to create a GUI with different Screens (which should contain different GUI elements, buttons etc.) and how to switch between them (back and forth, to another screen, ...).
Is there already an elegant solution, or can someone give me a hint how to start?
Thanks.
Screen Handling for GUI
-
- Posts: 602
- Joined: Sat Aug 23, 2003 2:03 am
- Location: Pottstown, PA
- Contact:
First of all, look at ICE, but if you do not want to, just make a class for each menu, which contains its buttons and a draw() function and erase() or destroy() function, in the draw function, just draw all the buttons, and in the erase buttons, just remove them. Or if you want, you could look at how ICE makes its main and options menu, as this is a good idea of how this works. How that helps.
-
- Posts: 7
- Joined: Tue Feb 10, 2004 10:00 am
Screen Handling for GUI
Hi,
thanks for your tips. As far as I've seen, GUIHandler is intended for defining and placing GUI Elements, right? If not, I have to apologize, but I haven't found what I was looking for, so back to my original question: How can I pre-define a number of screens, each containing different GUI elements, and switch between them? E.g. go from Screen 1 to 2? Could I work with the visibility flag, or do I have to remove all elements and draw the new ones for the current screen?
Thank you again...
thanks for your tips. As far as I've seen, GUIHandler is intended for defining and placing GUI Elements, right? If not, I have to apologize, but I haven't found what I was looking for, so back to my original question: How can I pre-define a number of screens, each containing different GUI elements, and switch between them? E.g. go from Screen 1 to 2? Could I work with the visibility flag, or do I have to remove all elements and draw the new ones for the current screen?
Thank you again...
As far as you can see in draw() function implementation (e.g. in CGUIWindow class) it doesn't draw object (and all it's children!) when IsVisible flag is false.
So you can create several parent IGUIElements and set their visibility to true or false, this will be switching your screens.
Example:
hope this can help you
So you can create several parent IGUIElements and set their visibility to true or false, this will be switching your screens.
Example:
Code: Select all
const int nScreens = 10; // number fo your screen (constant to simplify example)
IGUIWindow* screens[nScreens]; // actually your screens
void SetActiveScreen(int nScreen)
{
for (int i = 0; i < nScreens; i++)
screens[i]->setVisible((i == nScreen));
}
void main()
{
device = createDevice(EDT_DIRECTX8, dimension2d<s32>(640, 480), 16, false, false);
IGUIEnvironment* guienv = device->getGUIEnvironment();
rect<s32> rtScreen(0, 0, 640, 480); // your screens size
// create screens
for (int i = 0; i < nScreens; i++)
screens[i] = guienv->addWindow(rtScreen);
IVideoDriver* video = guienv->getVideoDriver();
int nActiveScreen(0);
while (device->run())
{
// do what you want here....
// use SetActiveScreen function to switch screens :) e.g.
SetActiveScreen((nActiveScreen++ / 10) % nScreens);
video->beginScene(true, true, video::SColor(0, 0, 0, 0));
guienv->drawAll();
video->endScene();
}
// in the end just drop your device :)
device->drop();
}
there is another guest...
I created the GUIHandler for just this type of usage.
It is a way of loading a pre-defined GUI layout (XML) to one parent to allow for easy removal or hiding of a GUI Set as well as registering the elements for usage in your application. With it, loading/unloading/using whole sets of GUI elements is simple
Unfortunately, there are some GUI level design problems with Irrlicht 0.4.2 that are going to be correcting in 0.5 that will cause additional changes and more functionality for GUI Handling.
Depending on how often you use a GUI or how complex it is (mesh viewers, tons of images) you would think about hiding it to save performance, but it eats up memory.
There is about 2 pages of notes at the beginning of the header in the GUIHandler files that can explain more in depth.
It is a way of loading a pre-defined GUI layout (XML) to one parent to allow for easy removal or hiding of a GUI Set as well as registering the elements for usage in your application. With it, loading/unloading/using whole sets of GUI elements is simple
Unfortunately, there are some GUI level design problems with Irrlicht 0.4.2 that are going to be correcting in 0.5 that will cause additional changes and more functionality for GUI Handling.
Depending on how often you use a GUI or how complex it is (mesh viewers, tons of images) you would think about hiding it to save performance, but it eats up memory.
There is about 2 pages of notes at the beginning of the header in the GUIHandler files that can explain more in depth.
Crud, how do I do this again?