Saturday, January 22, 2005

Radio Buttons

In writing the new task based CAD system, I have had to create a number of extensions to Croquet. One of these is radio buttons. These are used to specify that only one button can be selected at a time. This requires that you use the two state button mode, because it switches between them to signify what button is selected. I may update this later to do something different for one state buttons with shading, but I don't have time right now. To use this, do the following:

extrudeButtons := TButtonHolder new.
extrudeButtons buttonWidth: buttonWidth.
extrudeButtons extent:1.0@1.0.
extrudeButtons radioOn.
self addChild:extrudeButtons. "add the button holder to the current frame"

bttn := self button:'extrude90.bmp' with: 'extrude90Invert.bmp'.
bttn objectName:#extrude90.
extrudeButtons addChild: bttn.

bttn := self button:'extrudePoint.bmp' with: 'extrudePointInvert.bmp'.
bttn objectName:#extrudePoint.
extrudeButtons addChild: bttn.

bttn := self button:'extrudeRound.bmp' with: 'extrudeRoundInvert.bmp'.
bttn objectName:#extrudeRound.
extrudeButtons addChild: bttn.

bttn := self button:'extrudeCurve.bmp' with: 'extrudeCurveInvert.bmp'.
bttn objectName:#extrudeCurve.
extrudeButtons addChild: bttn.

extrudeButtons extent: buttonWidth@(buttonWidth*4).

This code will create a button holder that is four buttons tall and one wide. You can query which button is currently selected by sending:

bttn := extrudeButtons radioButton.

Here I have set the name of the button to be a token, so I actually use it this way:

extrude := extrudeButtons radioButton objectName.

This code has been posted as change set 0205RadioButtons.

No comments: