Page 1 of 1

Catch mouse click after all GUI handled

Posted: Tue Sep 08, 2009 8:47 pm
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?

Posted: Wed Sep 09, 2009 4:43 am
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

Posted: Wed Sep 09, 2009 6:15 am
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. :)