more than one active IEventReceiver ?

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
zenoid
Posts: 40
Joined: Wed Jul 20, 2005 1:16 pm
Location: france
Contact:

more than one active IEventReceiver ?

Post by zenoid »

Is irrlicht able to pass input event to more than one event receiver at the same time ?

thx.
strale
Posts: 119
Joined: Wed Nov 23, 2005 1:58 pm
Location: Lambrugo Italy
Contact:

Post by strale »

hi zenoid

i m not an expert of Irrlicht ,

but i belive not as you pass the event receiver to the Device that is the main window of your program.


Device->setEventReceiver(objEventGui);


may be you can istanziate 2 devices in the same program having 2 windows but separate events

bye
Guest

Post by Guest »

I faced this problem too.....

So, I developed an adaptator that you can register as the main device event receiver. Then, you can register as many event receiver as you want using adaptor's methods (add, remove, clear).

Code: Select all

#ifndef _ERM_HPP
#define _ERM_HPP

////////////////////////////////////////////////////////////////////////////////
//
// HELP ERM
//
////////////////////////////////////////////////////////////////////////////////

#include <irrlicht.h>
#include <list>
#include <algorithm>
#include <functional>

/*
    Event Receiver Manager
    SUM : ERM regroups multiple event receivers
*/
struct t_event_receiver_manager : irr::IEventReceiver
{
    // add an event receiver into manager
    inline void add( IEventReceiver * const er ) { _event_receivers.push_back( er ); }
    // remove an event receiver from manager
    inline void remove( IEventReceiver * const er ) { _event_receivers.remove( er ); }
    // clear event receivers from manager
    inline void clear() { _event_receivers.clear(); }
    // callback
    inline bool OnEvent( irr::SEvent ev )
    {
        for_each( _event_receivers.begin(),
                  _event_receivers.end(),
                  std::bind2nd( std::mem_fun(&irr::IEventReceiver::OnEvent) ,ev ) );
        return true; // who cares ?
	}
private:
    // list of registered event receiver
    std::list< IEventReceiver * const > _event_receivers;
};

#endif
Hope it may help.... or maybe I failed to see better solution.
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

Forgot to log in again... let me know if that solves your pb !

Xterm-in'Hate.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
Guest

Post by Guest »

generally you have the "first" receiver... if you want more, simple call the others in your "first" receiver with the passed arguments (just like the code above does..)
Guest

Post by Guest »

you can probably just use device->setEventReceiver(name);
zenoid
Posts: 40
Joined: Wed Jul 20, 2005 1:16 pm
Location: france
Contact:

Post by zenoid »

thx all for the advices and code, I'll check that soon.
Post Reply