Page 1 of 1

How can I manually change states of buttons (hovered, pushed

Posted: Wed Nov 30, 2005 16:50
by b-s-a
May be this is very simple to do, but I currently noob in CEGUI and didn't found needed methods in the API Reference... I try to do it with activate, but no result.
P.S.: Mouse is disabled in my project. Only keyboard currently (in the future it also will be disabled) may be used. As result I need to use manual (by programm) methods to control visual state of all objects.

Re: How can I manually change states of buttons (hovered, pu

Posted: Wed Nov 30, 2005 17:05
by vinnythetrue
You can just fire events manually with the well-named "fireevent" method.

For exemple :

mpbutton->fireEvent( PushButton::EventMouseButtonDown, EventArgs() );

This should set the button in pushed state, and then some

mpbutton->fireEvent( PushButton::EventMouseButtonUp, EventArgs() );

... to go back to normal state.

Try play with different events to see what they do, and if you're not satisfied with'em, you still can bind your own methods to your own events ;)

Re: How can I manually change states of buttons (hovered, pu

Posted: Wed Nov 30, 2005 17:35
by lindquist
Calling fireEvent will only trigger user callbacks.

The concept given by vinny is good enough, but you have to use the input injection methods provided by 'System'.

injectMousePosition <-- inject this with a proper coordinate over the button you want to hover.

injectMouseDown <-- inject this with a LeftButton to enable pushed.

injectMouseUp <-- inject this to go back to hover.

and then make sure you inject a new mouse position somewhere not over the button to go back to normal.
It's a little cumbersome, but it's currently the only way.

Doing it like this will trigger usercallbacks you may have assigned to the actions as usual. and remember that you'll need to redraw the GUI for any visual change.

Re: How can I manually change states of buttons (hovered, pu

Posted: Thu Dec 01, 2005 14:28
by b-s-a
I try to do it. But I cannot determine position of the window in mouse units. I try to use getAbsolutePosition.But result for window (size 0.34x0.4) placed in center of the screen ( 1024x768 ) is 17.0,46.0.
Why? In the documentation for this metod written: "Return the window position in absolute metrics". In description of MetricMode: "Absolute Metrics are specified as whole pixels".

Re: How can I manually change states of buttons (hovered, pu

Posted: Thu Dec 01, 2005 15:04
by lindquist
Use getPixelRect instead. It gives you that info in screen space. getAbsolutePosition is a pixel position yes. But relative to the parent of the window in question. Not the screen.

Code: Select all

Rect r = window->getPixelRect();
System::getSingleton().injectMousePosition(r.d_left, r.d_top);


look here for the details...

Re: How can I manually change states of buttons (hovered, pu

Posted: Thu Dec 01, 2005 18:35
by b-s-a
Thank you. It's working!