controlP5
Class Button

java.lang.Object
  extended by controlP5.Controller
      extended by controlP5.Button
All Implemented Interfaces:
CDrawable, ControllerInterface, ControlP5Constants
Direct Known Subclasses:
MultiListButton

public class Button
extends Controller

A button triggers an event after it has been release. Events can be linked to functions and fields inside your program/sketch. for a full documentation of this controller see the Controller class.

+Example
/**
 * ControlP5 button.
 * this example shows how to create buttons with controlP5.
 * 
 * by andreas schlegel, 2009
 */
import controlP5.*;

ControlP5 controlP5;

// this is only a note.
// we will not use variable b in the code below.
// we have to use controlP5.Button here since there
// would be a conflict if we only use Button to declare button b.
Button b;

// a button-controller with name buttonValue will change the
// value of this variable when pressed.
int buttonValue = 0;

int myColor = color(0,255,180);


void setup() {
  size(640,480);
  smooth();
  frameRate(30);
  controlP5 = new ControlP5(this);
  controlP5.addButton("buttonA",0,100,100,80,19);
  controlP5.addButton("buttonB",255,100,120,80,19);
  controlP5.addButton("buttonValue",128,100,140,80,19);

}

void draw() {
  background(myColor);
  fill(buttonValue);
  rect(20,20,width-40,height-40);
}

public void controlEvent(ControlEvent theEvent) {
  println(theEvent.controller().name());
  
}

// function buttonA will receive changes from 
// controller with name buttonA
public void buttonA(int theValue) {
  println("a button event from buttonA: "+theValue);
  myColor = theValue;
}

// function buttonB will receive changes from 
// controller with name buttonB
public void buttonB(int theValue) {
  println("a button event from buttonB: "+theValue);
  myColor = theValue;
}





Field Summary
 
Fields inherited from interface controlP5.ControlP5Constants
acceptClassList, ACTIVE, ALT, ARC, ARRAY, BACKSPACE, BOOLEAN, BOTTOM, CENTER, CONTROL, controlEventClass, CUSTOM, DECREASE, DEFAULT, DELETE, DOWN, ELLIPSE, ENTER, ESCAPE, EVENT, eventMethod, FIELD, FLOAT, HALF_PI, HIDE, HIGHLIGHT, HORIZONTAL, IMAGE, INCREASE, INTEGER, INVALID, KEYCONTROL, LEFT, LINE, LOAD, MENU, METHOD, MOVE, OVER, PI, PRESSED, PRINT, RELEASE, RESET, RIGHT, SAVE, SHIFT, SPRITE, STRING, SWITCH, SWITCH_BACK, SWITCH_FORE, TAB, TOP, TWO_PI, UP, VERBOSE, VERTICAL
 
Constructor Summary
Button()
           
Button(ControlP5 theControlP5, java.lang.String theName)
           
 
Method Summary
 Button activateBy(int theValue)
          A button can be activated by a mouse PRESSED or mouse RELEASE.
 void addToXMLElement(ControlP5XMLElement theElement)
          
 boolean booleanValue()
          Returns true or false and indicates the switch state of the button.
 void mousePressed()
          
 void mouseReleased()
          
 void mouseReleasedOutside()
          
 Button setOff()
          If the button acts as a switch, setOff will turn off the switch.
 Button setOn()
          If the button acts as a switch, setOn will turn on the switch.
 Button setSwitch(boolean theFlag)
          turn a button into a switch, or use toggle instead.
 void setValue(float theValue)
          set the value of the button controller.
 java.lang.String toString()
           
 void update()
          updates the value of the controller without having to set the value explicitly.
 void updateDisplayMode(int theMode)
          }
 
Methods inherited from class controlP5.Controller
absolutePosition, add, addListener, arrayValue, behavior, captionLabel, changeValue, color, continuousUpdateEvents, controlWindow, defaultValue, disableSprite, draw, enableSprite, getAsXML, getColor, getHeight, getPickingColor, getSprite, getTab, getWidth, getWindow, hide, id, init, isBroadcast, isInside, isLock, isMousePressed, isMoveable, isUpdate, isUserInteraction, isVisible, isXMLsavable, keyEvent, label, linebreak, listenerSize, lock, max, min, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, name, parent, plugTo, plugTo, position, remove, remove, removeBehavior, removeListener, setArrayValue, setBehavior, setBroadcast, setCaptionLabel, setColor, setColorActive, setColorBackground, setColorCaptionLabel, setColorForeground, setColorLabel, setColorValue, setColorValueLabel, setDecimalPrecision, setDefaultValue, setDisplay, setDisplay, setGroup, setGroup, setHeight, setId, setImage, setImage, setImages, setImages, setLabel, setLabelVisible, setLock, setMax, setMin, setMousePressed, setMoveable, setParent, setPosition, setSize, setSize, setSprite, setTab, setTab, setUpdate, setUserInteraction, setValueLabel, setVisible, setWidth, setWindow, setWindow, show, stringValue, trigger, unlock, unplugFrom, unplugFrom, updateAbsolutePosition, updateEvents, updateInternalEvents, updateSize, value, valueLabel
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Button

public Button()

Button

public Button(ControlP5 theControlP5,
              java.lang.String theName)
Method Detail

mousePressed

public void mousePressed()


mouseReleased

public void mouseReleased()


activateBy

public Button activateBy(int theValue)
A button can be activated by a mouse PRESSED or mouse RELEASE. Default value is RELEASE.

Parameters:
theValue - use ControlP5.PRESSED or ControlP5.RELEASE as parameter
Returns:
Button

mouseReleasedOutside

public void mouseReleasedOutside()


setValue

public void setValue(float theValue)
set the value of the button controller.

Specified by:
setValue in class Controller
Parameters:
theValue - float

update

public void update()
updates the value of the controller without having to set the value explicitly. update does not visually update the controller. the updating status can be set with setUpdate(true/false) and checked with isUpdate(). setUpdate ( )

Specified by:
update in interface ControllerInterface
Overrides:
update in class Controller

addToXMLElement

public void addToXMLElement(ControlP5XMLElement theElement)

Parameters:
theElement - ControlP5XMLElement

setSwitch

public Button setSwitch(boolean theFlag)
turn a button into a switch, or use toggle instead.

Parameters:
theFlag - turns the button into a switch when true
Returns:
Button
See Also:
Toggle

setOn

public Button setOn()
If the button acts as a switch, setOn will turn on the switch. Use setSwitch to turn a button into a switch.

Returns:
Button

setOff

public Button setOff()
If the button acts as a switch, setOff will turn off the switch. Use setSwitch to turn a button into a switch.

Returns:
Button

booleanValue

public boolean booleanValue()
Returns true or false and indicates the switch state of the button. setSwitch should have been set before.

Returns:
boolean
See Also:
setSwitch(boolean)

updateDisplayMode

public void updateDisplayMode(int theMode)
}

See Also:
Controller.updateDisplayMode(int)

toString

public java.lang.String toString()
Overrides:
toString in class Controller


processing library controlP5 by Andreas Schlegel. (c) 2010