Page 1 of 1

GUIEvent and node from screen coordinates

Posted: Tue Oct 10, 2006 4:00 pm
by goutbouyo
Hi,
I have a problem with making my game map editor.

I create a toolbox like in the meshviewer example.
I use the getSceneNodeFromScreenCoordinatesBB to find the position of my objects in the map.

My problem is that when I click on the toolbox, in the same time I find the position of the object behind it ... and I do want to...

For example, I selelect 2 waypoints, and then I click on the buton CONNECT in the toolbox => that doesn't work because in the same time it selects the object behind the toolbox ...

Can you help me please ???

Posted: Tue Oct 10, 2006 4:41 pm
by vitek
It sounds like you are handling the mouse input from the user event receiver.

If you are doing this, then you need to return true from your OnEvent function when you handle the mouse click. If you don't handle the mouse click then the GUI will get a chance to handle it.

If you want to give priority to the GUI system, then you need to forward events to the GUI before you attempt to process them. If the GUI handles the event, then you should not.

Code: Select all

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

  // do normal processing
}
Travis

Posted: Tue Oct 10, 2006 5:56 pm
by goutbouyo
Thanks it works fine now !!!

Posted: Wed Nov 08, 2006 4:00 pm
by KG
vitek wrote:It sounds like you are handling the mouse input from the user event receiver.

If you are doing this, then you need to return true from your OnEvent function when you handle the mouse click. If you don't handle the mouse click then the GUI will get a chance to handle it.

If you want to give priority to the GUI system, then you need to forward events to the GUI before you attempt to process them. If the GUI handles the event, then you should not.

Code: Select all

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

  // do normal processing
}
Travis
Sorry to resurrect this topic, but if I'm having problems with this solution. If I use it, it crashes if any GUI events are posted, even if I simply mouse over the GUI. Is there any specific way I need to set up my event class to make this work?

Posted: Wed Nov 08, 2006 4:55 pm
by vitek
I'll bet you're getting a stack overflow... If the gui doesn't handle an event, it passes the event to the user event receiver. The user event receiver passes the event to the gui, and so on.

You have to find a way to break the cycle. It is pretty easy to do...

Code: Select all

class MyEventReceiver : public IEventReceiver
{
private:
  SEvent* Event;
};

MyEventReceiver::MyEventReceiver()
  : Event(0)
{
}

bool MyEventReceiver::OnEvent(const SEvent& event) 
{
  // recursion prevention
  if (&event == Event)
    return false;

  SEvent* save = Event;
  Event = &event

  if (Environment->postEventFromUser(event)) 
    return true; 

  // do normal processing 

  Event = save;

  return false;
} 

Unfortunately the code written is just an easy out, and it turns into a bit of a hack. A better solution is to only handle user input in your event receiver if there is no gui to handle the events. This can be done with some state management system, but that is a little complicated to write up in a forum post.

Travis

Posted: Wed Nov 08, 2006 7:22 pm
by KG
vitek wrote: This can be done with some state management system, but that is a little complicated to write up in a forum post.
Yeah, I know what you mean. I had the GUI working like that originally. The menu was opened and closed with the Escape key, and the mouse input events were disabled while the menu was up. It worked just fine, but now I'm at a point where that is too limited for what I want to do.

I appreciate the response, though, and I will give it a shot if there are absolutely no nicer ways of doing it.

But are there really no "clean" ways to check GUI events first, and completely skip everything if it is a GUI event? Or at least a way to suppress mouse events if they're generated at the same time as a GUI event? Something like this (though it doesn't work):

Code: Select all

if (Event.EventType == EET_GUI_EVENT)
{
	blah blah

	return true;
}

if (Event.EventType == EET_MOUSE_INPUT_EVENT)
{
	blah blah

	return true;
}

return false;

Posted: Fri Feb 02, 2007 2:51 pm
by maverickbu
Just wanted to say that I am currently up against this same problem and was wondering if any more elegant solutions have been developed since? If not, I will use the suggestion vitek posted (thanks for that!).

Posted: Fri Feb 02, 2007 4:16 pm
by maverickbu
Would this other chunk of code provided by vitek (again!) be an appropriate solution, giving precedence to the GUI over other event receivers?

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=11785

Posted: Tue Feb 06, 2007 8:01 pm
by maverickbu
no help?