Focus GUIElement even though there is a modal window

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Focus GUIElement even though there is a modal window

Post by randomMesh »

I have several IGUIEditboxes in my gui.
The user can enter something, press a button and the input gets validated.

If there is an invalid input, a message box pops up (modal) and tells the user what's going on.

After the user clicked the ok button, i want to refocus this IGUIEditbox.

For this task, i catch the irr::gui::EGET_MESSAGEBOX_OK event in my eventreceiver to know which messagebox has fired the event.

To cut a long story short:

Code: Select all

guienv->setFocus(editBox);
returns false, because of the modal window gets removed AFTER the event is fired.

What's the best way to deal with it?

Feature request:
A temporary 'messageBox->setModal(false);' would be nice.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

This might be a bug in the event order, or it might be a problem in your usage of the events. However, in case of the latter there could be some improvements in the usability of modal windows, just as you pointed out. I'm moving it to the bug forum to check this one.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

hybrid wrote:This might be a bug in the event order, or it might be a problem in your usage of the events.
Here's a quick test case

Code: Select all

#include <irrlicht.h>
 
 
class EventReceiver : public irr::IEventReceiver
{
 
public:
 
	EventReceiver(irr::IrrlichtDevice* device, irr::gui::IGUIEditBox* box) :
		device(device), box(box)
	{
 
	}
 
	virtual bool OnEvent(const irr::SEvent& event)
	{
		switch(event.EventType)
		{
			case irr::EET_GUI_EVENT:
				switch(event.GUIEvent.EventType )
				{
					case irr::gui::EGET_BUTTON_CLICKED:
					{
						bool modal = true; //set modal to false and it will work
						device->getGUIEnvironment()->addMessageBox(
							L"A messagebox", L"HAHA! The box lost the focus!", modal, irr::gui::EMBF_OK, 0, 12345678);
					}
					return true;
 
					case irr::gui::EGET_MESSAGEBOX_OK:
					{
						irr::gui::IGUIWindow* const messageBox = (irr::gui::IGUIWindow* const)event.GUIEvent.Caller;
						const irr::s32 id = messageBox->getID();
						switch(id)
						{
							case 12345678: //this must be our messagebox
							{
								bool b = device->getGUIEnvironment()->setFocus(box);
								if (b)
									printf("oki\n");
								else
									printf("naaa\n"); //ahh this is printed out!
 
								return true;
							}
 
							default: return false;
						}
					}
					break;
 
					default: return false;
				}
			break;
 
			default: return false;
		}
	}
 
private:
 
irr::IrrlichtDevice* device;
 
irr::gui::IGUIEditBox* box;
 
};
 
int main()
{
	irr::IrrlichtDevice* device = irr::createDevice();
	if (device == 0) return 1;
 
	irr::video::IVideoDriver* driver = device->getVideoDriver();
	irr::gui::IGUIEnvironment* guienv = device->getGUIEnvironment();
 
 
	irr::gui::IGUIEditBox* box = guienv->addEditBox(L"", irr::core::rect<irr::s32>(50, 50, 200, 70));
 
	irr::gui::IGUIButton* button = guienv->addButton(irr::core::rect<irr::s32>(50, 100, 200, 120), 0, -1, L"Click me");
 
	EventReceiver receiver(device, box);
	device->setEventReceiver(&receiver);
 
	guienv->setFocus(box); //here it works!
 
	while (device->run())
	{
		if (device->isWindowActive())
		{
			driver->beginScene(true, true, irr::video::SColor(255, 128, 128, 128));
			guienv->drawAll();
			driver->endScene();
		}
	}
 
	device->drop();
 
	return 0;
}

randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

Stumbling over the same behaviour today (latest SVN trunk), i just wanted to push that ancient thread.

Is it a bug or me doing something wrong?
"Whoops..."
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I suppose it would work now if you call setVisible(false) on the messagebox (not tested). Invisible modals should no longer block and the visibility also checks for the children.
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
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

CuteAlien wrote:I suppose it would work now if you call setVisible(false) on the messagebox (not tested). Invisible modals should no longer block and the visibility also checks for the children.
Works like a charm, thank you.
"Whoops..."
Post Reply