How to dispatch windows events to Irrlicht events

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
Quibbler
Posts: 25
Joined: Tue Feb 14, 2006 5:34 pm

How to dispatch windows events to Irrlicht events

Post by Quibbler »

From the Win32 tutorial it says:
Now the only thing missing is the drawing loop using IrrlichtDevice::run(). We do this as usual. But instead of this, there is another possibility: You can also simply use your own message loop using GetMessage, DispatchMessage and whatever. Calling
Device->run() will cause Irrlicht to dispatch messages internally too. You need not call Device->run() if you want to do your own message dispatching loop, but Irrlicht will not be able to fetch user input then and you have to do it on your own using the window messages, DirectInput, or whatever.

But how do I dispatch window messages to Irrlicht so that mouse events and GUI events can be grabbed in my event receiver ???

I only want to dispatch mouse messages, because I want to use Win API functions to read the keyboard.

I also found this in CGUIEnvironment.cpp:
//! This sets a new event receiver for gui events. Usually you do not have to
//! use this method, it is used by the internal engine.
void CGUIEnvironment::setUserEventReceiver(IEventReceiver* evr)
{
UserReceiver = evr;
}

What is the user event receiver, and how does it work ??
Last edited by Quibbler on Sat Sep 22, 2007 5:15 pm, edited 1 time in total.
TomiZ
Posts: 40
Joined: Wed Aug 29, 2007 6:02 am
Location: Poland
Contact:

Post by TomiZ »

For example, when user will click in some irrlicht window, Irrlicht will translate this message. If any element on GUI has been pressed, Irrlicht will call OnEvent function in this element. If this element will do something witch this message (like buttons) it will return true. But if it don't want to do anything with this message it will return false - then message will be send to parent of this element. If this message wouldn't be used by any GUI element, it can be send to yours custom event receiver. So if you don't use any GUI elements you will receive all mouse input in OnEvent of yours event receiver and if you have one button you will receive all mouse input, that isn't related to this button.


This is sample body on OnEvent in custom event receiver

Code: Select all

bool MyEventReciver::OnEvent(irr::SEvent event) 
// in other version of Irrlicht: bool MyEventReciver::OnEvent(const irr::SEvent event)
{
	if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)
	{
		// something has happened with mouse
		if(event.MouseInput.Event == irr::EMIE_MOUSE_MOVED)
		{
			newMouseX = event.MouseInput.X;
			newMouseX = event.MouseInput.Y;
			return true;
		} 
		// else
		if(event.MouseInput.Event == irr::EMIE_LMOUSE_PRESSED_DOWN)
		{
			// left mouse button has been pressed
			return true;
		}
		// ToDo: check other possible mouse events (irr::EMOUSE_INPUT_EVENT)
	}

	return false;
}
Quibbler
Posts: 25
Joined: Tue Feb 14, 2006 5:34 pm

Post by Quibbler »

I think I've figured it out now.

I need to use this method in my window procedure:
virtual void irr::IrrlichtDevice::postEventFromUser ( SEvent event ) [pure virtual]

Sends a user created event to the engine.

Is is usually not necessary to use this. However, if you are using an own input library for example for doing joystick input, you can use this to post key or mouse input events to the engine. Internally, this method only delegates the events further to the scene manager and the GUI environment.

Then in my window procedure I just check all messages I want and create SEvent objects for each mouse message which I then send using above method.

Thanks anyway.
Post Reply