GUI window closed?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Mike
Posts: 17
Joined: Wed Dec 14, 2005 6:42 pm

GUI window closed?

Post by Mike »

I have a GUI window and I want to detect when it is being closed with the X button. I can't find any event for this. I tried checking if the window is visible but it seems it is always visible even when it is closed :( .
AlexL
Posts: 184
Joined: Tue Mar 02, 2004 6:06 pm
Location: Washington State

Post by AlexL »

This thread here might helps you abit - http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=10962 - Also might try searching around abits so you don't have to worry abouts possibly getting flamed.
nomad
Posts: 53
Joined: Thu Jan 05, 2006 12:35 pm
Location: Wales

Post by nomad »

Here's what I did to get the close message - this involves a few small additions to the engine source code :shock:, I've marked these (5 lines) with //ADD

in CGUIWindow.cpp:

Code: Select all

bool CGUIWindow::OnEvent(SEvent event)
{
	/*
	Some small inclusions from CGUIMessageBox.cpp, so an event is
	 generated when the close button is pressed
	 */
	SEvent outevent;  //ADD
	outevent.EventType = EET_GUI_EVENT;  //ADD
	outevent.GUIEvent.Caller = this;   //ADD

	switch(event.EventType)
	{
	case EET_GUI_EVENT:
		if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST)
		{
			Dragging = false;
			return true;
		}
		else
		if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
		{
			if (event.GUIEvent.Caller == CloseButton)
			{
				outevent.GUIEvent.EventType = EGET_MESSAGEBOX_CANCEL; 				//ADD
				Parent->OnEvent(outevent);	//ADD
				remove();
				return true;
			}
		}
		break;
So your event handler should now get a EGET_MESSAGEBOX_CANCEL message, i.e.

Code: Select all

 if ((event.EventType == EET_GUI_EVENT) && (event.GUIEvent.EventType ==  EGET_MESSAGEBOX_CANCEL)) {
//do something
}
I don't know if there's an easier way, but this seems to work fine for me.
Mike
Posts: 17
Joined: Wed Dec 14, 2005 6:42 pm

Post by Mike »

OK thanks. I searched the forums but I hoped there is nicer way to do this.
Post Reply