Here's nearly the same code, but this time with global events:
Code: Select all
CEGUI::GlobalEventSet::getSingleton().subscribeEvent(CEGUI::Window::EventNamespace + "/" + CEGUI::PushButton::EventMouseEnters, CEGUI::Event::Subscriber(&DemoSample::onMouseEnters, this));
CEGUI::GlobalEventSet::getSingleton().subscribeEvent(CEGUI::Window::EventNamespace + "/" + CEGUI::PushButton::EventMouseLeaves, CEGUI::Event::Subscriber(&DemoSample::onMouseLeaves, this));
Code: Select all
bool onMouseEnters(const CEGUI::EventArgs& e)
{
const CEGUI::WindowEventArgs& we = static_cast<const CEGUI::WindowEventArgs&>(e);
if(we.window->testClassName( CEGUI::PushButton::EventNamespace )
&& !we.window->isAutoWindow() )
{
// It's a push button (and not an auto window, from scrollbars)
CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
CEGUI::PushButton* btnClose = static_cast<CEGUI::PushButton*>(winMgr.getWindow("btnClose"));
CEGUI::Window* frameWindow = static_cast<CEGUI::Window*>(winMgr.getWindow("StaticText"));
btnClose->setText("Enters");
frameWindow->setText( we.window->getName() );
}
return true;
}
bool onMouseLeaves(const CEGUI::EventArgs& e)
{
const CEGUI::WindowEventArgs& we = static_cast<const CEGUI::WindowEventArgs&>(e);
if(we.window->testClassName( CEGUI::PushButton::EventNamespace )
&& !we.window->isAutoWindow() )
{
// It's a push button (and not an auto window, from scrollbars)
CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
CEGUI::PushButton* btnClose = static_cast<CEGUI::PushButton*>(winMgr.getWindow("btnClose"));
CEGUI::Window* frameWindow = static_cast<CEGUI::Window*>(winMgr.getWindow("StaticText"));
btnClose->setText("Leaves");
frameWindow->setText( we.window->getName() );
}
return true;
}
The trick was to use
CEGUI::Window::EventNamespace + "/" + CEGUI::PushButton::EventMouseEnters rather than
CEGUI::PushButton::EventNamespace + "/" + CEGUI::PushButton::EventMouseEnters.
I used
CEGUI::PushButton::EventNamespace as an attempt to use a pre-defined "PushButton" string, rather than using a litteral string. It feels like a hack, but
PushButton::WidgetTypeName is not adequate; it contains "CEGUI/PushButton", with the "CEGUI/" prefix preventing it from working with the call to testClassName().
These global events are nifty; I didn't even know they existed. But now I see so many ways in which they can be useful...