ButtonClick event always fired no matter where mouse clicked

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

unclepauly
Just popping in
Just popping in
Posts: 7
Joined: Sun Jan 21, 2007 17:43

ButtonClick event always fired no matter where mouse clicked

Postby unclepauly » Sat May 03, 2008 20:24

hello,

im having what i assume is a pretty simple problem to solve, hope someone can help...

im using ogre, and ois to inject my input into cegui.

in my CreateScene function i do:

Code: Select all

   CEGUI::WindowManager *win = CEGUI::WindowManager::getSingletonPtr();
    CEGUI::Window *sheet = win->createWindow("DefaultGUISheet", "Game3/Sheet");
   CEGUI::Window *myButton = win->createWindow("TaharezLook/Button", "Game3/MyButton");
    quit->setText("MyButton");
CEGUI::UVector2 pos(CEGUI::UDim(0.0, 0), CEGUI::UDim(0.0, 0));
   quit->setPosition(pos);
   quit->setSize(CEGUI::UVector2(CEGUI::UDim(0.15, 0), CEGUI::UDim(0.025, 0)));   
   quit->subscribeEvent(CEGUI::PushButton::EventMouseButtonDown, CEGUI::Event::Subscriber(&Application::MyFunction, this));

   sheet->addChildWindow(myButton);
   mSystem->setGUISheet(sheet);


so as you can see, i just create quite a small button, place it top-left, and set its EventMouseButtonDown to a function called MyFunction in my Application class:

The mousePressed function (from OIS) is what injects the mouse pressed into CEGUI, like this:

Code: Select all

   CEGUI::MouseButton mb = ConvertOIStoCEGUI(id);
   CEGUI::System *sys = CEGUI::System::getSingletonPtr();
   sys->injectMousePosition(arg.state.X.rel, arg.state.Y.rel);
   sys->injectMouseButtonDown(mb);


now, when i click on the button for the first time, the MyFunction function is called, and all is good. but the problem is that from that point on, the MyFunction function is called EVERY time the mouse button is clicked, no matter where the mouse is. so as you can see from my code, the button is placed at (0,0), ie top left. i can click the mouse button anywhere on the window, even bottom right, and the MyFunction function is called.

i use:

Code: Select all

CEGUI::Window* pWindow = CEGUI::System::getSingleton().getWindowContainingMouse();
   CEGUI::String name = pWindow->getName();


at the time the mouse is clicked and it always returns the name of the button !

i must be doing something daft. any help appreciated.

unclepauly
Just popping in
Just popping in
Posts: 7
Joined: Sun Jan 21, 2007 17:43

Postby unclepauly » Sat May 03, 2008 22:30

actually this might be an OIS issue, because the X and Y values of args, passed to

Code: Select all

bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)


has X=50 and Y=50, even though my render window is 800 x 600.

so i dont think this is CEGUI after all, sorry.

unclepauly
Just popping in
Just popping in
Posts: 7
Joined: Sun Jan 21, 2007 17:43

Postby unclepauly » Sun May 04, 2008 12:30

ok, i have sorted out the OIS side of things. i hadnt set it up correctly, and the default width/height is 50x50. so now i output the position of the mouse on an overlay, and i can see that it is correct (width = 800, height = 600).

however, i am still having my original problem ! please look at my first post.

if i subscribe an EventClicked event to the button, i get nothing, the callback is never fired.

if i subscribe a EventMouseButtonDown event to the button, the callback DOES fire - but every time, no matter where the mouse is ! in other words, the mouse does not have to be over the button for the event to fire, i can click anywhere on the window.

this is bizare - can someone help ? thank you.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Mon May 05, 2008 08:16

Hi,

Are you also injecting mouse button 'up' events? This is generally what causes the issues when the events are not fired.

This would also cause the button to 'capture' inputs to itself, which is why all subsequent events get sent directly to the button regardless of the mouse position.

HTH

CE.

unclepauly
Just popping in
Just popping in
Posts: 7
Joined: Sun Jan 21, 2007 17:43

Postby unclepauly » Mon May 05, 2008 10:54

hi CE,

thanks for the reply.

you were right, i was not injecting mouse up events, because i was not doing anything with them. ive done that now and all is good.

thanks again !


Return to “Help”

Who is online

Users browsing this forum: No registered users and 10 guests