ButtonWidget Class Reference

The ButtonWidget JavaScript class. A button widget. More...

Signals

void valueChanged (bool value)
 Signal notifying the user that the value was modified by the Transform Tool. More...
 
- Signals inherited from WidgetBase
void dragStarted (QScriptValue dragContext)
 signal called on mouse down when picking this widget with the Transform tool More...
 
void drag (QScriptValue dragContext)
 signal called when this widget is dragged with the Transform tool More...
 
void dragEnded ()
 signal called on mouse up after having manipulated this widget with the Transform tool More...
 

Public Member Functions

virtual void onDrag (MC_DragContext &dragContext) override
 

Additional Inherited Members

- Public Slots inherited from WidgetBase
Attributedata (int index=0)
 

Detailed Description

The ButtonWidget JavaScript class. A button widget.

This widget must be linked to a BOOL attribute. The widget manipulator is a circular area. The color for the on/off states can be specified at object creation. When the area is clicked, the BOOL attribute is set to true, the button is shown in its pressed state, and the valueChanged signal is emitted. If the "toggle" property is set to true, the button will remain in its pressed state until it is pushed again.

The following properties are supported by the widget:

Property Type Default Value Description
data String - The name of the automatically generated position attribute (if none is provided)
data Attribute - An attribute of BOOL type that can be shared with another widget or node.
size float 1.00 The size (half-extent) of the box.
screen_space bool false When set to true, the button position becomes relative to the screen rather than the scene.
position Point2d Point2d(0,0) Position of the box center in the scene, specified in fields.
outer_color ColorRGBA 0, 0, 0,255 The outer colour of the box.
on_color ColorRGBA 0,255, 0,128 The inner colour of the box, when pressed.
off_color ColorRGBA 255, 0, 0,128 The outer colour of the box, when released.
toggle bool false When set to true, the button will stay in pressed state until pressed again.
label String "text" Label text
label_color ColorRGBA 255,255,255,255 Label foreground (text) color.
label_bg_color ColorRGBA 0, 0, 0,128 Label background color. Accepts transparency values.
label_font String "Arial" Label font name.
label_size float 10.0 Label font size, in points.
label_pos Point2d Point2d(0,0) Label position, in fields.
label_justify String "Left" Horizontal label text alignment ("Left"/"Center").
label_screenspace bool true Forces the label size to remain constant relative to screen.
label_screenspace_offset Point2d Point2d(0,0) Label position offset, in screen space.

The following components constitute the widget:

Component Type
attribute BOOL
drag_manipulator BUTTON
painter BUTTON
picker MONO
local_transformation -

Create this widget to add a floating Master Controller in the camera view:

{
MessageLog.trace("\n\n\n");
MessageLog.trace(" ---------------------------------------------------------------------------");
MessageLog.trace("| Button Widget Test");
MessageLog.trace(" ---------------------------------------------------------------------------");
var valAttr = node.getAttr(Controller.node, frame.current(), "button_value");
var mcColor = node.getAttr(Controller.node, frame.current(), "widget_color").colorValueAt(frame.current());
var mcSize = node.getAttr(Controller.node, frame.current(), "button_size").doubleValue();
var screen_space = node.getAttr(Controller.node, frame.current(), "screen_space").boolValue();
var val_label_text = node.getAttr(Controller.node, frame.current(), "label").textValue();
var val_label_font = node.getAttr(Controller.node, frame.current(), "label_font").textValue();
var val_label_size = node.getAttr(Controller.node, frame.current(), "label_size").doubleValue();
var val_label_color = node.getAttr(Controller.node, frame.current(), "label_color").colorValueAt(frame.current());
var val_label_bg_color = node.getAttr(Controller.node, frame.current(), "label_bg_color").colorValueAt(frame.current());
var mcNameCapture = Controller.node;
var buttonWidget = new ButtonWidget(
{
data: valAttr,
position : Point2d(0.,0.),
screen_space : screen_space,
pressed_color : mcColor,
outer_color : ColorRGBA(0,0,0,255),
on_color : ColorRGBA(0,255,0,255),
off_color : ColorRGBA(255,0,0,255),
toggle : false,
size : mcSize,
label : val_label_text,
label_color : val_label_color,
label_bg_color : val_label_bg_color,
label_font : val_label_font,
label_size : val_label_size,
label_pos : Point2d(0,0),
label_screenspace_offset : Point2d(0,-400),
label_justify : "Center",
label_screenspace : screen_space
} );
buttonWidget.valueChanged.connect(function(toggleValue)
{
MessageLog.trace("buttonWidget.valueChanged!");
});
Controller.controls = [buttonWidget];
MessageLog.trace("Done.");
}

Make sure to setup the Master Controller node specifications properly. e.g.

<attributes>
<attr type="BOOL" name="screen_space" value="false" tooltip="Check this options for size to be defined in screen space."/>
<attr type="BOOL" name="button_value" value="false" tooltip="Button ON/OFF value."/>
<attr type="STRING" name="label" value="mc_btnText" tooltip="Master Controller label."/>
<attr type="STRING" name="label_font" value="Arial " tooltip="Label font ."/>
<attr type="DOUBLE" name="button_size" value="1.0" tooltip="Radius of the Master Controller Button."/>
<attr type="DOUBLE" name="label_size" value="18.0" tooltip="Label font size, in points ."/>
<attr type="COLOUR" name="label_color " value="255,255,255" tooltip="Label color ."/>
<attr type="COLOUR" name="label_bg_color" value="0,0,0,128" tooltip="Label background color."/>
<attr type="COLOUR" name="widget_color" value="255,0,0" tooltip="Color of the MasterController Button."/>
</attributes>

Member Function Documentation

◆ onDrag()

virtual void ButtonWidget::onDrag ( MC_DragContext &  dragContext)
overridevirtual

Reimplemented from WidgetBase.

◆ valueChanged

void ButtonWidget::valueChanged ( bool  value)
signal

Signal notifying the user that the value was modified by the Transform Tool.

Parameters
valuethe toggle value. value is of JavaScript type bool