EventMouseEnters is not firing

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
sjcomp
Not too shy to talk
Not too shy to talk
Posts: 30
Joined: Wed Apr 27, 2005 14:59
Contact:

EventMouseEnters is not firing

Postby sjcomp » Mon Apr 23, 2007 19:53

I am trying to handle event when mouse enters a push button but it's not firing. I can handle mouse clicks just fine

Code: Select all

// This works!
CEGUI::GlobalEventSet::getSingleton().subscribeEvent(
   CEGUI::PushButton::EventNamespace + "/" + CEGUI::PushButton::EventClicked,
   CEGUI::Event::Subscriber(&CCeguiGUI::ButtonPressed,this));

// This does not work
CEGUI::GlobalEventSet::getSingleton().subscribeEvent(
   CEGUI::Window::EventMouseEnters,
   CEGUI::Event::Subscriber(&CCeguiGUI::ButtonEnter,this));


I also tried this, but with no luck:

Code: Select all

mRoot->subscribeEvent(CEGUI::Window::EventMouseEnters,
   CEGUI::Event::Subscriber(&CCeguiGUI::ButtonEnter,this));

What am I doing wrong?
Regards, Alexander. http://sjcomp.com

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Tue Apr 24, 2007 13:45

You are not prefixing the event namespace properly. You do it correctly in the example that works, but not in the one that doesn't.

e.g:

Code: Select all

// This should work
CEGUI::GlobalEventSet::getSingleton().subscribeEvent(
      CEGUI::Window::EventNamespace + "/" + CEGUI::Window::EventMouseEnters,
   CEGUI::Event::Subscriber(&CCeguiGUI::ButtonEnter,this));


note that this will fire for ALL widgets. not just buttons.

User avatar
sjcomp
Not too shy to talk
Not too shy to talk
Posts: 30
Joined: Wed Apr 27, 2005 14:59
Contact:

Postby sjcomp » Tue Apr 24, 2007 19:06

Thanks, lindquist. Now I see. I want to have only push buttons, so I've tried:

Code: Select all

CEGUI::PushButton::EventNamespace + "/" + CEGUI::PushButton::EventMouseEnters,

But this does not seem to work. (It works for all the windows as you show). Basically I want to play a sound when mouse hovers over a button (first enters it) a-la half life style.

How do I limit these events to buttons only?
Regards, Alexander. http://sjcomp.com

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 » Tue Apr 24, 2007 19:11

Hi,

i have not checked the sources for a solution, but a workaround might be a check on the window type which causes the event. And only play a sound when the event was fired from a real button.

HTH.

User avatar
sjcomp
Not too shy to talk
Not too shy to talk
Posts: 30
Joined: Wed Apr 27, 2005 14:59
Contact:

Postby sjcomp » Tue Apr 24, 2007 19:40

Thanks, scriptkid. That is what I am doing. But type of the button depends on the style, so it's given as "TaharezLook/Button". Of course, I could check if type contains "/Button" at the end, but it still looks like a hack as opposed to a proper solution.
Regards, Alexander. http://sjcomp.com

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Tue Apr 24, 2007 20:31

I modified WidgetGalore to play with this idea. Here are the two modifications, within the WidgetGalore.h file.

Just below the btnClose->setText("Exit"); line, within the initialiseSample() function:

Code: Select all

btnClose->subscribeEvent(CEGUI::PushButton::EventMouseEnters, CEGUI::Event::Subscriber(&DemoSample::onMouseEnters,   this));
btnClose->subscribeEvent(CEGUI::PushButton::EventMouseLeaves, CEGUI::Event::Subscriber(&DemoSample::onMouseLeaves,   this));


After the void cleanupSample(void) function, two new functions:

Code: Select all

bool onMouseEnters(const CEGUI::EventArgs& e)
{
   const CEGUI::WindowEventArgs& we = static_cast<const CEGUI::WindowEventArgs&>(e);
   CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
   if(we.window)
   {
      we.window->setText("Enters");
   }
   return true;
}

bool onMouseLeaves(const CEGUI::EventArgs& e)
{
   const CEGUI::WindowEventArgs& we = static_cast<const CEGUI::WindowEventArgs&>(e);
   CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
   if(we.window)
   {
      we.window->setText("Leaves");
   }
   return true;
}


This code is "aware" of the mouse starting to hover over the pushbutton and when it leaves the pubshbutton. That code is also generic; multiple pushbuttons can use it, as long as each calls subscribeEvent().

Maybe you need to replace CEGUI::Window with CEGUI::PushButton.

Hope this helps.

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Tue Apr 24, 2007 22:52

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...

User avatar
sjcomp
Not too shy to talk
Not too shy to talk
Posts: 30
Joined: Wed Apr 27, 2005 14:59
Contact:

Postby sjcomp » Wed Apr 25, 2007 13:43

Rackle wrote:The trick was to use CEGUI::Window::EventNamespace + "/" + CEGUI::PushButton::EventMouseEnters rather than CEGUI::PushButton::EventNamespace + "/" + CEGUI::PushButton::EventMouseEnters.

It does work :) Though there is still a need to check if it is a button that fired this event. So I might as well use Window in both parts. On the other hand I liked the way you tested if it is a button or no. It looks like an appropriate way to do so. Thanks a lot.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 11 guests