Page 1 of 1
How to set a button state?
Posted: Tue Jun 19, 2007 09:14
by vr
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?
Posted: Wed Jun 20, 2007 12:32
by Rackle
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.
Posted: Wed Jun 20, 2007 20:14
by vr
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.
Posted: Thu Jun 21, 2007 01:12
by Rackle
In C++ code the EventCheckStateChanged event is the one that is called when the checkbox is checked/unchecked. Is that renamed SelectStateChange in Lua?
Posted: Mon Jun 25, 2007 07:39
by vr
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).
Posted: Mon Jun 25, 2007 23:13
by Rackle
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.