How to set a button state?

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

vr
Just popping in
Just popping in
Posts: 19
Joined: Thu Oct 12, 2006 20:57

How to set a button state?

Postby vr » Tue Jun 19, 2007 09:14

How can I set a button to pushed/non-pushed?
I would like to do that from lua code.

That is:

button:setPushed(true) -- which obviously wont work as the method setPushed does not exist.
So how do I do it?

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

Postby Rackle » Wed Jun 20, 2007 12:32

What is your goal?

Maybe you are trying to make a pushbutton behave like a checkbox; "on" when the pushbutton is down and "off" when it is up. In that case the best approach would be to use a checkbox with custom imagery; instead of using the traditional box with an X you'd use the images of a pushbutton in the up and down states. I say this is the best approach since the behavior you are trying to accomplish is that of a checkbox and not that of a pushbutton; only the visual look is different. Have a look at Create_ImageButtons and Create_a_CheckListboxItem or the Falagard system in general.

Maybe you are creating a tutorial and need to "activate" the UI automatically. You could bypass the regular inject functions and inject your own inputs. For example you inject multiple mouse move to place the cursor on top of the pushbutton, inject a mouse button down, wait a second or two, inject a mouse button up. This way you control the UI via the mouse and the user/student sees the actions.

vr
Just popping in
Just popping in
Posts: 19
Joined: Thu Oct 12, 2006 20:57

Postby vr » Wed Jun 20, 2007 20:14

Sure, Checkbox is what I need.
But I have problem getting any events triggered when using a checkbox.

Im doing the programming in lua and its working just fine with dozens of other buttons, but not the CheckBox...

Neither of the ones below work:

local winMgr = CEGUI.WindowManager:getSingleton()

local button = winMgr:getWindow("root/FurButton")


function processRenderFur(args)
print("callback")
end


--neither of these work:
button:subscribeEvent("Clicked", "processRenderFur")
button:subscribeEvent("SelectStateChange", "processRenderFur")


Im quite puzzled of why it wont work.

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

Postby Rackle » Thu Jun 21, 2007 01:12

In C++ code the EventCheckStateChanged event is the one that is called when the checkbox is checked/unchecked. Is that renamed SelectStateChange in Lua?

vr
Just popping in
Just popping in
Posts: 19
Joined: Thu Oct 12, 2006 20:57

Postby vr » Mon Jun 25, 2007 07:39

Thats a good question.
Tried EventCheckStateChanged with no luck (either).


The two available for a RadioButton in the api description is:

onSelectStateChanged (WindowEventArgs &e)
onMouseButtonUp (MouseEventArgs &e)

And as it is a ButtonBase is should also react to

onMouseMove (MouseEventArgs &e)
onMouseButtonDown (MouseEventArgs &e)
onMouseButtonUp (MouseEventArgs &e)
onCaptureLost (WindowEventArgs &e)
onMouseLeaves (MouseEventArgs &e)


right?
none of the above gets activated for a radiobutton (nor a Checkbox).

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

Postby Rackle » Mon Jun 25, 2007 23:13

EventCheckStateChanged is meant to be used with a checkbox, triggered when the checkbox is checked and unchecked. Please try with a tiny C++ program to make this work and then try with a tiny Lua program. Basically all you need is a checkbox and a static text; click on the checkbox and update the text of the static text to either "checked" or "unchecked", depending on the state of the checkbox.

I usually use Widget Galore for such quick tests; nearly every widget is present, making it very easy to test events for a particular widget.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 10 guests