Same event to all Button element. [solved]

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

Toge
Just popping in
Just popping in
Posts: 12
Joined: Thu Jan 22, 2009 21:59

Same event to all Button element. [solved]

Postby Toge » Thu Mar 05, 2009 18:27

Hello.

How can I set the same event-function for all Button? I want to play a sound when whatever button is pushed.

Thanks.



for each Button
{
button->subscribeEvent(PushButton::EventMouseClick, Event::Subscriber(&MyClass::playSound, this));

}
Last edited by Toge on Fri Mar 06, 2009 06:38, edited 2 times in total.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Thu Mar 05, 2009 19:46

Hi,

There is a global event set that you can subscribe to. Each type of object that fires events also defines an event namespace, this is used in conjunction with the event name.

So, for the PushButton, you have CEGUI::PushButton::EventNamespace and CEGUI::PushButton::EventClicked. You use those like this (contrived example):

Code: Select all

using namespace CEGUI;

String globalEventName( PushButton::EventNamespace + '/' + PushButton::EventClicked );

GlobalEventSet::getSingleton().subscribeEvent( globalEventName, myHandlerFunction );


It's important to note that the namespace comes from the originating class. This means that for events such as EventMouseClick (which is different to PushButton::EventClicked) the namespace comes from the Window base class, so Window::EventNamespace.

If you don't want to use the 'EventNamespace' constants, you can use strings also, so you could just specify "PushButton/Clicked" which is shorter, but you may have to look up the namespace and event strings in the code ;)

HTH

CE.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 11 guests