EventReceiver: MOUSE and GUI EVENT conflict!

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
Dukdalf
Posts: 24
Joined: Thu Jun 21, 2007 9:48 am

EventReceiver: MOUSE and GUI EVENT conflict!

Post by Dukdalf »

Hi guys,

I think I found a bug in the eventReceiver. I was wrestling with the event receiver for some time, and I posted in the above posts that something is wrong. But now I have the bug kinda singled out, and I show that their is some weird behavior when EET_GUI_EVENT is used next to EET_MOUSE_EVENT. I made a short example code with only the barely minimum of things needed to show that there is something wrong.

Code: Select all

#include <irrlicht.h>
#include <iostream>

using namespace irr;
using namespace std;
using namespace core;
using namespace video;
using namespace gui;

class MastEventReceiver : public IEventReceiver {

protected:
	virtual bool OnEvent(SEvent event) {
		bool eventprocessed = false;
		cout << event.EventType<< " ";

		switch (event.EventType) {
		case EET_KEY_INPUT_EVENT: {
			cout << "KEY Event"<< endl;
			eventprocessed = true;
			break;
		}
		case EET_MOUSE_INPUT_EVENT: {
			cout << "MOUSE Event"<< endl;
			eventprocessed = true;
			break;
		}
		case EET_GUI_EVENT: {
			cout << "GUI Event"<< endl;
			eventprocessed = true;
			break;
		}
		case EET_LOG_TEXT_EVENT: {
			cout << "LOG TEXT Event"<< endl;
			eventprocessed = true;
			break;
		}
		case EET_USER_EVENT: {
			cout << "USER Event"<< endl;
			eventprocessed = true;
			break;
		}
		}
		return eventprocessed;
	}
};

int main()
{
	IrrlichtDevice *device = createDevice(video::EDT_DIRECT3D9,core::dimension2d<s32>(640, 480));

	if (device == 0)
	return 1; // could not create selected driver.

	MastEventReceiver receiver;

	device->setEventReceiver(&receiver);
	device->setWindowCaption(L"General Event Receiver Bug");

	video::IVideoDriver* driver = device->getVideoDriver();
	IGUIEnvironment* env = device->getGUIEnvironment();

	/*
	Just a button to test if the GUI_EVENT works togather with the mouse GUI Event	
	*/	

	env->addButton(rect<s32>(10,290,110,290 + 32), 0, 103, L"TEST BUTTON", L"TEST GUI EVENT");

	while(device->run() && driver)
	if (device->isWindowActive())
	{
		driver->beginScene(true, true, SColor(0,200,200,200));

		env->drawAll();
	
		driver->endScene();
	}

	device->drop();
	return 0;
}
When this piece of code is run, you get a window with one button. The button does not do anything, but when you click on the button an GUI_EVENT is supposed to happen. I found out that this is only the case when the MOUSE_EVENTS are commented out in the switch inside the event_receiver. When the MOUSE_EVENTS are not commented, the GUI_EVENT does not happen. In this way it is impossible to use bothe GUI_EVENTS and MOUSE_EVENTS togather at one time.

Please have a look at the code and run it if you like. Comment this piece of code and see the different behaviour:

Code: Select all

		case EET_MOUSE_INPUT_EVENT: {
			cout << "MOUSE Event"<< endl;
			eventprocessed = true;
			break;
		}
I hope somebody can fix this bug in IrrLicht, or otherwise when this is not a bug, somebody is able to point out, what I do wrong.

Thanks in advance!

Dukdalf
Just fooling around abit!
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

The user reciever comes before GUIEnvironment's event reciever, so if you process mouse events in the user reciever, you'll stop them from being passed to the GUI.
If you want the user to be able to interact with the GUI, you should return false when processing mouse events in your user reciever.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

wow that was a lot of work for nothing lol
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Irrlicht's event handling causes a lot of confusion, I'll update the IEventReciever.h docs
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Dukdalf
Posts: 24
Joined: Thu Jun 21, 2007 9:48 am

Post by Dukdalf »

alot of work maybe.;-) but if the code becomes better documented that way, it is will be helpfull for new users.

It is kinda misleading to have one eventreceiver with the possibility to handle mouse, key, gui, log and user events, but that certain combinations create complications. The complications should be well documented or the eventhandler is not well coded.;-)

Documenting this possible bug was less work then the time I wasted to get the event holder to work properly.

I just hope that more people do not have to struggle with this 'feature'.;-)

Gah, I was so close to a solution, but really thanks, been struggling with this for a long time. I must say IrrLicht really helps me with understanding programming and 3d, but it sure is a big struggle to get things right.
/cheers.;-)
Just fooling around abit!
Post Reply