GUIEvent and node from screen coordinates

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
goutbouyo
Posts: 47
Joined: Thu Mar 24, 2005 6:55 pm

GUIEvent and node from screen coordinates

Post 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 ???
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post 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
goutbouyo
Posts: 47
Joined: Thu Mar 24, 2005 6:55 pm

Post by goutbouyo »

Thanks it works fine now !!!
KG
Posts: 35
Joined: Wed Jun 07, 2006 12:00 am

Post 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?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post 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
KG
Posts: 35
Joined: Wed Jun 07, 2006 12:00 am

Post 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;
maverickbu
Posts: 17
Joined: Tue Dec 05, 2006 5:07 pm

Post 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!).
maverickbu
Posts: 17
Joined: Tue Dec 05, 2006 5:07 pm

Post 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
maverickbu
Posts: 17
Joined: Tue Dec 05, 2006 5:07 pm

Post by maverickbu »

no help?
Post Reply