[solved] Event originator identification

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

maglos
Just popping in
Just popping in
Posts: 3
Joined: Fri Feb 02, 2007 02:51

[solved] Event originator identification

Postby maglos » Fri Feb 02, 2007 03:38

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.
Last edited by maglos on Sat Feb 10, 2007 21:44, edited 1 time in total.

maglos
Just popping in
Just popping in
Posts: 3
Joined: Fri Feb 02, 2007 02:51

er

Postby maglos » Thu Feb 08, 2007 21:55

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?

User avatar
mba
Not too shy to talk
Not too shy to talk
Posts: 41
Joined: Tue Oct 11, 2005 11:54
Location: Denmark

Postby mba » Thu Feb 08, 2007 23:22

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

maglos
Just popping in
Just popping in
Posts: 3
Joined: Fri Feb 02, 2007 02:51

great

Postby maglos » Sat Feb 10, 2007 21:44

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.

User avatar
ldb
Quite a regular
Quite a regular
Posts: 54
Joined: Sat Mar 24, 2007 13:39
Location: Bloomington, IL
Contact:

very helpful!

Postby ldb » Sun Apr 08, 2007 08:05

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


Return to “Help”

Who is online

Users browsing this forum: No registered users and 28 guests