Catch mouse click after all GUI handled

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
U238
Posts: 14
Joined: Mon Aug 17, 2009 1:01 pm
Location: Taganrog, Russia

Catch mouse click after all GUI handled

Post by U238 »

Hello again from my newbie questions.
Help me to think how to easier catch mouse click event after GUI handled, i.e. unless any GUI event respond click.
The only thing came in mind to include some variable, turn it on, when lmb clicked and turn off on any GUI event. Then it can be catched in (1)

Code: Select all

bool terrainClicked = false;

main.cpp:
...
	while( device->run() )
	if ( device->isWindowActive() )
	{
		driver->beginScene( true, true, SColor( 255, 100, 100, 150 ) );
		scMgr->drawAll();
		guiEnv->drawAll();

		driver->endScene();
		if( terrainClicked )
			onTerrainClick();  /*** (1) ***/
		terrainClicked = false;
	}

...
CMyEventReceiver
{
	bool OnEvent( SEvent& _event)
	{
		switch( _event.EventType )
		{
		case EET_GUI_EVENT:
			terrainClicked = false;
			...
		case EET_MOUSE_INPUT_EVENT:
			switch( _event.MouseInput.Event )
			{
				case EMIE_LMOUSE_PRESSED_DOWN:
					terrainClicked = true;
			}
		}
	}
};
May be it can be done some easier approach?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Why not try forwarding the event to the gui in your event receiver. If the gui handles it, then you're done, otherwise you try to process it yourself.

Code: Select all

MyEventReceiver::MyEventReceiver(gui::IGUIEnvironment* env)
  : Environment(env)
{
}

bool MyEventReceiver::OnEvent (const SEvent& event)
{
  if (Environment && Environment->OnEvent(event))
    return true;

  // do any other special handling here

  return false;
}
This has the disadvantage that the GUI may process some events twice, but it is a simple solution. There are lots of other things that you could do, but this is the simplest.

Travis
U238
Posts: 14
Joined: Mon Aug 17, 2009 1:01 pm
Location: Taganrog, Russia

Post by U238 »

Oh thanks to you, but disadvantage you your method seems harmful to me. I'll try my own idea, because the varialbe need to be make false only one time in the EET_GUI_EVENT case. :)
Post Reply