controlP5
Class Toggle

java.lang.Object
  extended by controlP5.Controller
      extended by controlP5.Toggle
All Implemented Interfaces:
CDrawable, ControllerInterface, ControlP5Constants

public class Toggle
extends Controller

a toggle can have two states, true and false, where true has the value 1 and false is 0.

+Example
/**
 * ControlP5 Toggle
 * by andreas schlegel, 2009
 */

import controlP5.*;

ControlP5 controlP5;

int myColorBackground = color(0,0,0);

boolean toggleValue = true;

void setup() {
  size(400,400);
  smooth();
  controlP5 = new ControlP5(this);
  controlP5.addToggle("toggle",false,100,160,20,20);
  controlP5.addToggle("toggleValue",true,100,240,100,20).setMode(ControlP5.SWITCH);
}
  
void draw() {
  background(myColorBackground);
  if(toggleValue==true) {
    fill(0,255,0);
  } else {
    fill(255,0,0);
  }
  rect(0,0,width,100);
}

void toggle(boolean theFlag) {
  if(theFlag==true) {
    myColorBackground = color(100);
  } else {
    myColorBackground = color(0);
  }
  println("a toggle event.");
}

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
Toggle(ControlP5 theControlP5, Tab theParent, java.lang.String theName, float theValue, float theX, float theY, int theWidth, int theHeight)
           
 
Method Summary
 void addToXMLElement(ControlP5XMLElement theElement)
           
 void draw(processing.core.PApplet theApplet)
          the default draw function for each controller extending superclass Controller.
 boolean getState()
           
 float internalValue()
           
 Controller linebreak()
           
 void mousePressed()
           
 void setInternalValue(float theInternalValue)
          by default a toggle returns 0 (for off) and 1 (for on).
 void setMode(int theMode)
          set the visual mode of a Toggle.
 void setState(boolean theFlag)
          set the state of the toggle, which can be true or false.
 void setValue(boolean theValue)
           
 void setValue(float theValue)
          set the value of the controller.
 void toggle()
          switch the state of a toggle.
 void update()
          updates the value of the controller without having to set the value explicitly.
 void updateDisplayMode(int theState)
           
 
Methods inherited from class controlP5.Controller
absolutePosition, add, addListener, arrayValue, behavior, captionLabel, changeValue, color, continuousUpdateEvents, controlWindow, defaultValue, disableSprite, enableSprite, getAsXML, getColor, getHeight, getPickingColor, getSprite, getTab, getWidth, getWindow, hide, id, init, isBroadcast, isInside, isLock, isMousePressed, isMoveable, isUpdate, isUserInteraction, isVisible, isXMLsavable, keyEvent, label, 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, toString, 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

Toggle

public Toggle(ControlP5 theControlP5,
              Tab theParent,
              java.lang.String theName,
              float theValue,
              float theX,
              float theY,
              int theWidth,
              int theHeight)
Parameters:
theControlP5 - ControlP5
theParent - Tab
theName - String
theValue - float
theX - float
theY - float
theWidth - int
theHeight - int
Method Detail

draw

public void draw(processing.core.PApplet theApplet)
Description copied from class: Controller
the default draw function for each controller extending superclass Controller. This draw function will take care of default matrix operations and will call the display function of the current ControllerDisplay object active for this particular controller.

Specified by:
draw in interface CDrawable
Specified by:
draw in interface ControllerInterface
Overrides:
draw in class Controller
Parameters:
theApplet - PApplet
See Also:
ControllerDisplay

mousePressed

public void mousePressed()

setValue

public void setValue(float theValue)
Description copied from class: Controller
set the value of the controller.

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

setValue

public void setValue(boolean theValue)

update

public void update()
Description copied from class: Controller
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

setState

public void setState(boolean theFlag)
set the state of the toggle, which can be true or false.

Parameters:
theFlag - boolean

getState

public boolean getState()

toggle

public void toggle()
switch the state of a toggle.


setMode

public void setMode(int theMode)
set the visual mode of a Toggle. use setMode(ControlP5.DEFAULT) or setMode(ControlP5.SWITCH)

Parameters:
theMode -

addToXMLElement

public void addToXMLElement(ControlP5XMLElement theElement)
Parameters:
theElement - ControlP5XMLElement

setInternalValue

public void setInternalValue(float theInternalValue)
by default a toggle returns 0 (for off) and 1 (for on). the internal value variable can be used to store an additional value for a toggle event.

Parameters:
theInternalValue -

internalValue

public float internalValue()

linebreak

public Controller linebreak()
Overrides:
linebreak in class Controller

updateDisplayMode

public void updateDisplayMode(int theState)


processing library controlP5 by Andreas Schlegel. (c) 2010