How to detect IGUIWindow's close button pressed?

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
SiW
Posts: 3
Joined: Mon Sep 18, 2006 7:30 am

How to detect IGUIWindow's close button pressed?

Post by SiW »

I want to handle the event when a window is closed with the built-in close button, but can't seem to find a suitable method. Is it possible to do so without modifying Irrlicht itself?
stef_
Posts: 53
Joined: Tue Apr 18, 2006 9:39 pm
Contact:

Post by stef_ »

Regarding to me you haven't to modify Irrlicht,
but however you have to include a private header (CGUIWindow.h).

This is a bit uncomfortable if someone wants recompiling your
application and he has only irrlicht public headers.

Code: Select all

#include "CGUIWindow.h"

class MyWindow : public CGUIWindow
{
public:
   MyWindow (irr::gui::IGUIEnvironment *env, irr::gui::IGUIElement *e,
             irr::s32 id, irr::core::rect<irr::s32> rect) :
             CGUIWindow (env, e, id, rect) {}

   bool OnEvent(SEvent event)
   {
      if (event.EventType == irr::EET_GUI_EVENT &&
          event.GUIEvent.EventType == irr::gui::EGET_BUTTON_CLICKED &&
          event.GUIEvent.Caller == this -> getCloseButton ()) {
         printf ("catched!\n");
      }

      return CGUIWindow::OnEvent (event);
   }
};
then when you want to create a catchable window:

Code: Select all

   IGUIWindow *w = new MyWindow(guienv, guienv->getRootGUIElement(),
                                -1, irr::core::rect<s32> (0, 0, 320, 240));
   w->setText(L"test window");
bye
SiW
Posts: 3
Joined: Mon Sep 18, 2006 7:30 am

Post by SiW »

Thanks for the response. I instead decided that as I'll be modifying the GUI system anyway, I may as well make the change I required in the CGUIWindow implementation.
Post Reply