Screen Handling for GUI

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
codwarrior
Posts: 7
Joined: Tue Feb 10, 2004 10:00 am

Screen Handling for GUI

Post by codwarrior »

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.
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

Post by Robomaniac »

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.
The Robomaniac
Project Head / Lead Programmer
Centaur Force
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

Also, if you want to look at a more elegant way to load the GUI's, there is a GUI Handling class in the Project Announcements section.

It allows you to use XML to define your GUI layout.
Crud, how do I do this again?
codwarrior
Posts: 7
Joined: Tue Feb 10, 2004 10:00 am

Screen Handling for GUI

Post by codwarrior »

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...
Guest
Posts: 35
Joined: Mon Feb 02, 2004 7:17 pm
Location: Russia, Saint-Petersburg

Post by Guest »

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:

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();
}
hope this can help you :)
there is another guest...
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

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.
Crud, how do I do this again?
Post Reply