Page 1 of 1

[solved] Event originator identification

Posted: Fri Feb 02, 2007 03:38
by maglos
Is it possible to know where an event came from other then by where it ends up?
I'm translating events to python so making a function for each event is kinda annoying.

er

Posted: Thu Feb 08, 2007 21:55
by maglos
so no not possible? I guess it makes sence it seems to have a referance to a rectangle which would be way up the inheritance tree..would that share the same name as what would have created it?

Posted: Thu Feb 08, 2007 23:22
by mba
hi maglos

I'm not entirely sure what your question is, but do you mean "is it possible to use the same eventhandler for more than one event source"?

If so, yes it is, I'm doing that all the time. I have a layout with multiple event sources like buttons and such, and in my implementation I only have one eventhandler for all the events that I subscribe to.

Subscribe to multiple events with the same eventhandler callback-function:

Code: Select all

    CEGUI::Window *wnd = CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)"button1");
wnd->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&MainMenu::GUICallBack, this));

    CEGUI::Window *wnd = CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)"button2");
wnd->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&MainMenu::GUICallBack, this));



And in callback-function differentiate between the events by their names:

Code: Select all

bool MainMenu::GUICallBack(const CEGUI::EventArgs& e)
{
  const CEGUI::WindowEventArgs& we = (const CEGUI::WindowEventArgs&)e;
  std::string win_name = we.window->getName().c_str();
 
  if(win_name.compare("button1") == 0) {
    //handle button 1
  }
  else if(win_name.compare("button2") == 0) {
    //handle button 2
  }
}




kind regards
Martin Bang Andersen

great

Posted: Sat Feb 10, 2007 21:44
by maglos
hey perfect thats exactly what I wanted thx, I knew this belonged in the beginner forum. I guess I assumed that if an event knew its originator it would be up in the core interfaces, I never thought to look at the WindowEventArgs implementation.

very helpful!

Posted: Sun Apr 08, 2007 08:05
by ldb
this is extremely helpful to know! i had been searching all over for a way to do exactly this. i knew it had to be possible.

i wiki'ed it here:

http://www.cegui.org.uk/wiki/index.php/ ... e_Callback