Page 1 of 1

How to un-subscribe Event?

Posted: Thu Apr 16, 2009 09:49
by westpointer
I use the following code to subscribeEvent:

Code: Select all

CEGUI::GlobalEventSet::getSingleton().subscribeEvent(CEGUI::Window::EventNamespace+'/'+CEGUI::Window::EventMouseEnters,
      CEGUI::Event::Subscriber(&SceneSheet::handleMouseEnters, this));


After this, I want to un-subscribe the "EventMouseEnters" event for specific windows, but I don't know how.

Posted: Thu Apr 16, 2009 10:46
by CrazyEddie
Hi,

If you're subscribing via the global event set you can't exclude some items from causing the global event to fire, since it doesn't work that way.

Maybe the best solution would be to maintain a list of 'excluded' windows and check those yourself at the top of the event hander?

CE.

Posted: Thu Apr 16, 2009 13:08
by westpointer
I get it, thanks. :)

Another question. Suppose I subscrib a normal event to a window, and later if I want to cancel the event I subscribed to the window, how to achieve this?

Posted: Thu Apr 16, 2009 13:57
by CrazyEddie
Hi,

I should have answered this bit before, so sorry about that.

When you call the subscribeEvent function you are returned a CEGUI::Event::connection object. If you want to 'unsubscribe' you can use this object and call the 'disconnect' function.

Code: Select all

using namespace CEGUI;

Event::connection con = window->subscribeEvent("AnEvent", myHandler);
...
con->disconnect();


You can also use a ScopedConnection, this will auto-disconnect when the ScopedConnection object goes out of scope.

HTH

CE.

Posted: Thu Apr 16, 2009 15:24
by westpointer
Thanks, it helps :D