Page 1 of 1
handle several buttons with only one event subscriber
Posted: Sat Sep 01, 2007 18:37
by rogerdv
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?
Posted: Wed Sep 05, 2007 13:41
by scriptkid
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.
Posted: Mon Jun 02, 2008 10:38
by DarioFrodo
By me it didn't work, the name is always invalid.
Posted: Tue Jun 03, 2008 08:51
by DarioFrodo
Ok, I find the mistake and fix it, now it work.