handle several buttons with only one event subscriber

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

User avatar
rogerdv
Quite a regular
Quite a regular
Posts: 62
Joined: Thu Mar 31, 2005 23:21
Contact:

handle several buttons with only one event subscriber

Postby rogerdv » Sat Sep 01, 2007 18:37

I have a toolbar with 10 buttons. I would like to have a single event function to handle all of them, but I cant find how to tell o the subscriber which button generated the event. Is this possible?

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Wed Sep 05, 2007 13:41

Hi,
a click handler receives an EventArgs which can be casted to a WindowsEventArgs, which has a window member pointing to the clicked window. You can for example use its name to identify it.

Sampe code:

Code: Select all

bool MyApp::handleToolbarClick(const CEGUI::EventArgs& e) {
  String* buttonName = static_cast<const WindowEventArgs&>(e).window)->getName();
  // Do anything
  return true;
}

HTH.

DarioFrodo
Just popping in
Just popping in
Posts: 4
Joined: Fri May 30, 2008 17:56

Postby DarioFrodo » Mon Jun 02, 2008 10:38

By me it didn't work, the name is always invalid.

DarioFrodo
Just popping in
Just popping in
Posts: 4
Joined: Fri May 30, 2008 17:56

Postby DarioFrodo » Tue Jun 03, 2008 08:51

Ok, I find the mistake and fix it, now it work.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 13 guests