|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectcontrolP5.Controller
public abstract class Controller
Controller is an abstract class that is extended by any available controller within controlP5. this is the full documentation list for all methods available for a controller. An event triggered by a controller will be forwarded to the main program. If a void controlEvent(ControlEvent theEvent) {} method is available, this method will be called. A Controller can pass a change in value to the main program in 3 different ways: (1) add method controlEvent(ControlEvent theEvent) to your sketch. ControlP5 will automatically detect this method and will used it to forward any controlEvent triggered by a controller - you can disable forwarding by using setBroadcast(false) (see setBroadcast) (2) each controller requires a unique name when being create. In case an existing name is used for a newly created Controller, the existing one will be overwritten. each unique name can be used to automatically link a controller to either a method or a field within your program.
Bang
,
Button
,
Knob
,
Matrix
,
MultiList
,
Numberbox
,
Radio
,
ScrollList
,
Slider
,
Textarea
,
Textfield
,
Textlabel
,
Toggle
,
ControlGroup
,
ControlBehavior
,
ControlEvent
/** * ControlP5basics
* The following example demonstrates the basic use of controlP5.
* After initializing controlP5 you can add controllers to controlP5. * Here we use three numberboxes, one slider and one textfield. * The numberbox with name numberboxC will trigger function numberboxC() * in the example below. Whenever controlP5 detects a function in your * sketch that corresponds to the name of a controller, it will forward * an event to that function. Any event triggered by a controller * will be forwarded to function controlEvent in your sketch.
* related examples ControlP5numberbox, ControlP5slider, ControlP5textfield
* by Andreas Schlegel 2010
* */ import controlP5.*; ControlP5 controlP5; public int myColorRect = 200; public int myColorBackground = 100; void setup() { size(400,400); frameRate(25); controlP5 = new ControlP5(this); controlP5.addNumberbox("numberboxA",myColorRect,100,140,100,14).setId(1); controlP5.addNumberbox("numberboxB",myColorBackground,100,180,100,14).setId(2); controlP5.addNumberbox("numberboxC",0,100,220,100,14).setId(3); controlP5.addSlider("sliderA",100,200,100,100,260,100,14).setId(4); controlP5.addTextfield("textA",100,290,100,20).setId(5); controlP5.controller("numberboxA").setMax(255); controlP5.controller("numberboxA").setMin(0); } void draw() { background(myColorBackground); fill(myColorRect); rect(0,0,width,100); } public void numberboxC(int theValue) { println("### got an event from numberboxC : "+theValue); } // a slider event will change the value of textfield textA public void sliderA(int theValue) { ((Textfield)controlP5.controller("textA")).setValue(""+theValue); } // for every change in textfield textA, this function will be called public void textA(String theValue) { println("### got an event from textA : "+theValue); } public void controlEvent(ControlEvent theEvent) { println("got a control event from controller with id "+theEvent.controller().id()); switch(theEvent.controller().id()) { case(1): // numberboxA myColorRect = (int)(theEvent.controller().value()); break; case(2): // numberboxB myColorBackground = (int)(theEvent.controller().value()); break; } }
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 |
Method Summary | |
---|---|
CVector3f |
absolutePosition()
get the absolute position of a controller. |
void |
add(ControllerInterface theElement)
|
void |
addListener(ControlListener theListener)
add a listener to the controller. |
float[] |
arrayValue()
|
ControlBehavior |
behavior()
get the behavior of the controller. |
Label |
captionLabel()
returns the caption label of the controller. |
void |
changeValue(float theValue)
set the value of the controller without sending the broadcast event. |
CColor |
color()
|
void |
continuousUpdateEvents()
continuousUpdateEvents is used for internal updates of a controller. |
ControlWindow |
controlWindow()
|
float |
defaultValue()
returns the default value. |
void |
disableSprite()
|
void |
draw(processing.core.PApplet theApplet)
the default draw function for each controller extending superclass Controller. |
void |
enableSprite()
|
ControlP5XMLElement |
getAsXML()
|
CColor |
getColor()
|
int |
getHeight()
|
int |
getPickingColor()
|
ControllerSprite |
getSprite()
|
Tab |
getTab()
get the instance of the tab the controller belongs to. |
int |
getWidth()
|
ControlWindow |
getWindow()
get the control window of the controller |
void |
hide()
hide the controller, make it invisible. |
int |
id()
get the id of the controller. |
void |
init()
|
boolean |
isBroadcast()
check if broadcasting is enabled or disabled for a controller. |
boolean |
isInside()
returns true or false and indicates if the mouse is inside the area of a controller. |
boolean |
isLock()
checks if a controller is locked or unlocked. |
boolean |
isMousePressed()
returns true or false if the mouse has is pressed. |
boolean |
isMoveable()
checks if a controller is moveable. |
boolean |
isUpdate()
enable the update function for a controller. |
boolean |
isUserInteraction()
|
boolean |
isVisible()
check if the controller is visible. |
boolean |
isXMLsavable()
|
void |
keyEvent(java.awt.event.KeyEvent theEvent)
|
java.lang.String |
label()
get the label of the controller. |
Controller |
linebreak()
|
int |
listenerSize()
|
void |
lock()
disables the controller to be moved, changed and controlled by the user. |
float |
max()
get the minmum value of the controller. |
float |
min()
get the maximum value of the controller. |
void |
moveTo(ControlGroup theGroup)
|
void |
moveTo(ControlGroup theGroup,
Tab theTab,
ControlWindow theControlWindow)
|
void |
moveTo(ControllerGroup theGroup)
|
void |
moveTo(ControlWindow theControlWindow)
move a controller to the default tab of a control window - other than the main window. |
void |
moveTo(ControlWindow theControlWindow,
java.lang.String theTabName)
|
void |
moveTo(processing.core.PApplet theApplet)
move a controller to the default tab inside the main window. |
void |
moveTo(processing.core.PApplet theApplet,
java.lang.String theTabName)
move a controller to a defined tab inside the main window. |
void |
moveTo(java.lang.String theTabName)
move a controller to another tab. |
void |
moveTo(Tab theTab)
move a controller to another tab indicated by parameter theTab. |
java.lang.String |
name()
returns the name of the controller. |
ControllerInterface |
parent()
get the parent of a controller. |
void |
plugTo(java.lang.Object theObject)
|
void |
plugTo(java.lang.Object[] theObjects)
|
CVector3f |
position()
get the position of a controller. |
void |
remove()
remove a controller from controlP5. |
void |
remove(ControllerInterface theElement)
|
void |
removeBehavior()
remove the behavior from the controller. |
void |
removeListener(ControlListener theListener)
remove a listener from the controller. |
void |
setArrayValue(float[] theArray)
|
void |
setBehavior(ControlBehavior theBehavior)
with setBehavior you can add a ControlBehavior to a controller. |
void |
setBroadcast(boolean theFlag)
Use setBroadcast to enable and disable the broadcasting of changes in a controller's value. |
void |
setCaptionLabel(java.lang.String theLabel)
set or change the content of the caption label of a controller. |
void |
setColor(CColor theColor)
|
void |
setColorActive(int theColor)
set the color for the controller while active. |
void |
setColorBackground(int theColor)
set the background color of the controller. |
void |
setColorCaptionLabel(int theColor)
set the color of the text label of the controller. |
void |
setColorForeground(int theColor)
set the foreground color of the controller. |
void |
setColorLabel(int theColor)
Deprecated. use setColorCaptionLabel() instead |
void |
setColorValue(int theColor)
Deprecated. use setColorValueLabel() instead |
void |
setColorValueLabel(int theColor)
|
void |
setDecimalPrecision(int theValue)
sets the decimal precision of a controller's float value displayed. |
void |
setDefaultValue(float theValue)
set the default value. |
void |
setDisplay(ControllerDisplay theDisplay)
use setDisplay to customize your controller look. |
void |
setDisplay(ControllerDisplay theDisplay,
int theMode)
|
void |
setGroup(ControllerGroup theGroup)
|
void |
setGroup(java.lang.String theName)
set the group of the controller. |
Controller |
setHeight(int theHeight)
|
void |
setId(int theId)
set the id of the controller. |
processing.core.PImage |
setImage(processing.core.PImage theImage)
Controller.DEFAULT (background) Controller.OVER (foreground) Controller.ACTIVE (active) |
processing.core.PImage |
setImage(processing.core.PImage theImage,
int theState)
|
Controller |
setImages(processing.core.PImage theImageDefault,
processing.core.PImage theImageOver,
processing.core.PImage theImageActive)
|
Controller |
setImages(processing.core.PImage theImageDefault,
processing.core.PImage theImageOver,
processing.core.PImage theImageActive,
processing.core.PImage theImageHighlight)
|
void |
setLabel(java.lang.String theLabel)
set the label of the controller. |
void |
setLabelVisible(boolean theValue)
show or hide the labels of a controller. |
void |
setLock(boolean theValue)
|
void |
setMax(float theValue)
set the maximum level of the Controller. |
void |
setMin(float theValue)
set the minimum level of the Controller. |
boolean |
setMousePressed(boolean theStatus)
|
void |
setMoveable(boolean theValue)
enable or prevent the controller to be moveable. |
void |
setParent(ControllerInterface theParent)
set the parent of a parent of a controller. |
void |
setPosition(float theX,
float theY)
set the position of a controller. |
void |
setSize(int theWidth,
int theHeight)
|
void |
setSize(processing.core.PImage theImage)
|
void |
setSprite(ControllerSprite theSprite)
|
void |
setTab(ControlWindow theWindow,
java.lang.String theName)
|
void |
setTab(java.lang.String theName)
set the tab of the controller. |
void |
setUpdate(boolean theFlag)
disable the update function for a controller. |
void |
setUserInteraction(boolean theValue)
TODO |
abstract void |
setValue(float theValue)
set the value of the controller. |
void |
setValueLabel(java.lang.String theLabel)
set or change the value of the value label of a controller. |
void |
setVisible(boolean theFlag)
set the visibility of a controller. |
Controller |
setWidth(int theWidth)
|
ControlWindow |
setWindow(ControlWindow theWindow)
Deprecated. |
void |
setWindow(processing.core.PApplet theApplet)
Deprecated. |
void |
show()
show the controller. |
java.lang.String |
stringValue()
set the current string value of a controller. |
java.lang.String |
toString()
|
void |
trigger()
Deprecated. |
void |
unlock()
enables the controller to be moved, changed and controlled by the user. |
void |
unplugFrom(java.lang.Object theObject)
|
void |
unplugFrom(java.lang.Object[] theObjects)
|
void |
update()
updates the value of the controller without having to set the value explicitly. |
void |
updateAbsolutePosition()
|
void |
updateEvents()
updateEvents is used for internal updates of a controller. |
void |
updateInternalEvents(processing.core.PApplet theApplet)
TODO |
Controller |
updateSize()
|
float |
value()
get the current value of the controller. |
Label |
valueLabel()
returns the caption label of the controller. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface controlP5.ControllerInterface |
---|
addToXMLElement |
Method Detail |
---|
public final void init()
init
in interface ControllerInterface
public void setBehavior(ControlBehavior theBehavior)
theBehavior
- ControlBehavior
/** * ControlP5behavior
* ControlBehavior is an abstract class that can be extended using your * custom control behaviors. What is a control behavior? Control Behaviors * allow you to automate and dynamically change the state or value of a * controller. One behavior per controller is currently supported. i case you * need to use more that one bahavior, the implementation has to happen * on your side - inside your control behavior.
* by Andreas Schlegel 2010
* */ import controlP5.*; ControlP5 controlP5; int myColorBackground = color(0,0,0); public int sliderValue = 100; void setup() { size(400,400); frameRate(30); controlP5 = new ControlP5(this); controlP5.addSlider("sliderValue",0,255,128,100,50 + height/2,40,100); controlP5.addSlider("slider",100,255,128,100,50,100,40); controlP5.addBang("bang",40,50 + height/2,40,40); // add a custom ControlBehavior to controller bang, // class TimerEvent is included in this sketch at the bottom // and extends abstract class ControlBehavior. controlP5.controller("bang").setBehavior(new TimedEvent()); // use an anonymous class of type ControlBehavior. controlP5.controller("slider").setBehavior(new ControlBehavior() { float a = 0; public void update() { setValue(sin(a += 0.1) * 50 + 150); } }); } void draw() { background(myColorBackground); fill(sliderValue); rect(0,0,width,height/2); } void slider(float theColor) { myColorBackground = color(theColor); println("# a slider event. setting background to "+theColor); } public void bang() { println("# an event received from controller bang."); // a bang will set the value of controller sliderValue // to a random number between 0 and 255. controlP5.controller("sliderValue").setValue(random(0,255)); } // custom ControlBehavior class TimedEvent extends ControlBehavior { long myTime; int interval = 200; public TimedEvent() { reset(); } void reset() { myTime = millis() + interval; } public void update() { if(millis()>myTime) { setValue(1); reset(); } } }
public void removeBehavior()
public ControlBehavior behavior()
public float defaultValue()
public void setDefaultValue(float theValue)
theValue
- floatpublic void setMoveable(boolean theValue)
theValue
- booleanpublic boolean isMoveable()
public void setLabelVisible(boolean theValue)
theValue
- booleanpublic void setBroadcast(boolean theFlag)
theFlag
- booleanpublic boolean isBroadcast()
public CVector3f position()
position
in interface ControllerInterface
public void setPosition(float theX, float theY)
setPosition
in interface ControllerInterface
theX
- floattheY
- floatpublic CVector3f absolutePosition()
absolutePosition
in interface ControllerInterface
public void updateAbsolutePosition()
updateAbsolutePosition
in interface ControllerInterface
public final void continuousUpdateEvents()
continuousUpdateEvents
in interface ControllerInterface
public final void updateEvents()
updateEvents
in interface ControllerInterface
public void updateInternalEvents(processing.core.PApplet theApplet)
updateInternalEvents
in interface ControllerInterface
ControllerInterface.updateInternalEvents
public void draw(processing.core.PApplet theApplet)
draw
in interface CDrawable
draw
in interface ControllerInterface
theApplet
- PAppletControllerDisplay
public void add(ControllerInterface theElement)
add
in interface ControllerInterface
theElement
- ControllerInterfacepublic void remove(ControllerInterface theElement)
remove
in interface ControllerInterface
theElement
- ControllerInterfacepublic void remove()
remove
in interface ControllerInterface
public java.lang.String name()
name
in interface ControllerInterface
public void moveTo(java.lang.String theTabName)
theTabName
- Stringpublic void moveTo(Tab theTab)
theTab
- public void moveTo(processing.core.PApplet theApplet)
theApplet
- public void moveTo(processing.core.PApplet theApplet, java.lang.String theTabName)
theApplet
- theTabName
- public void moveTo(ControlWindow theControlWindow)
theControlWindow
- public void moveTo(ControlWindow theControlWindow, java.lang.String theTabName)
public void moveTo(ControlGroup theGroup, Tab theTab, ControlWindow theControlWindow)
moveTo
in interface ControllerInterface
theGroup
- ControlGrouptheTab
- TabtheControlWindow
- ControlWindowpublic void moveTo(ControlGroup theGroup)
public void moveTo(ControllerGroup theGroup)
public void setTab(java.lang.String theName)
theName
- Stringpublic void setTab(ControlWindow theWindow, java.lang.String theName)
public void setGroup(java.lang.String theName)
theName
- Stringpublic void setGroup(ControllerGroup theGroup)
public void setWindow(processing.core.PApplet theApplet)
theApplet
- PAppletpublic ControlWindow setWindow(ControlWindow theWindow)
theWindwo
- ControlWindowpublic Tab getTab()
getTab
in interface ControllerInterface
public final void setParent(ControllerInterface theParent)
theParent
- ControllerInterfacepublic ControllerInterface parent()
parent
in interface ControllerInterface
public ControlWindow getWindow()
getWindow
in interface ControllerInterface
public boolean isInside()
public boolean isMousePressed()
public final boolean setMousePressed(boolean theStatus)
setMousePressed
in interface ControllerInterface
theStatus
- boolean
public void keyEvent(java.awt.event.KeyEvent theEvent)
keyEvent
in interface ControllerInterface
KeyEvent
- theEventpublic void setId(int theId)
setId
in interface ControllerInterface
int
- theIdpublic int id()
id
in interface ControllerInterface
public void plugTo(java.lang.Object[] theObjects)
theObject
- public void plugTo(java.lang.Object theObject)
public void unplugFrom(java.lang.Object[] theObjects)
public void unplugFrom(java.lang.Object theObject)
public abstract void setValue(float theValue)
theValue
- floatpublic void setArrayValue(float[] theArray)
public final void changeValue(float theValue)
theValue
- floatpublic void update()
update
in interface ControllerInterface
public void setUpdate(boolean theFlag)
setUpdate
in interface ControllerInterface
theFlag
- booleanpublic boolean isUpdate()
isUpdate
in interface ControllerInterface
public void trigger()
public float value()
value
in interface ControllerInterface
public java.lang.String stringValue()
stringValue
in interface ControllerInterface
public float[] arrayValue()
public int getPickingColor()
getPickingColor
in interface ControllerInterface
public CColor color()
color
in interface ControllerInterface
public CColor getColor()
public void setLabel(java.lang.String theLabel)
setLabel
in interface ControllerInterface
theLabel
- Stringpublic void setCaptionLabel(java.lang.String theLabel)
theLabel
- public void setValueLabel(java.lang.String theLabel)
theLabel
- public java.lang.String label()
public void addListener(ControlListener theListener)
theListener
- ControlListenerpublic void removeListener(ControlListener theListener)
theListener
- ControlListenerpublic int listenerSize()
public boolean isVisible()
isVisible
in interface ControllerInterface
public void setVisible(boolean theFlag)
theFlag
- booleanpublic void hide()
hide
in interface ControllerInterface
public void show()
show
in interface ControllerInterface
public void setColor(CColor theColor)
public void setColorActive(int theColor)
setColorActive
in interface ControllerInterface
theColor
- intpublic void setColorForeground(int theColor)
setColorForeground
in interface ControllerInterface
theColor
- intpublic void setColorBackground(int theColor)
setColorBackground
in interface ControllerInterface
theColor
- intpublic void setColorLabel(int theColor)
setColorLabel
in interface ControllerInterface
theColor
- intpublic void setColorCaptionLabel(int theColor)
theColor
- public void setColorValue(int theColor)
setColorValue
in interface ControllerInterface
theColor
- intpublic void setColorValueLabel(int theColor)
public Controller setImages(processing.core.PImage theImageDefault, processing.core.PImage theImageOver, processing.core.PImage theImageActive)
public Controller setImages(processing.core.PImage theImageDefault, processing.core.PImage theImageOver, processing.core.PImage theImageActive, processing.core.PImage theImageHighlight)
public processing.core.PImage setImage(processing.core.PImage theImage)
theImage
- public processing.core.PImage setImage(processing.core.PImage theImage, int theState)
public Controller updateSize()
public void setSize(processing.core.PImage theImage)
public void setSize(int theWidth, int theHeight)
public void setDisplay(ControllerDisplay theDisplay)
theDisplay
- ControllerDisplay
public void setDisplay(ControllerDisplay theDisplay, int theMode)
public Label captionLabel()
Label
public Label valueLabel()
Label
public float max()
public float min()
public void setMin(float theValue)
theValue
- floatpublic void setMax(float theValue)
theValue
- floatpublic Controller setWidth(int theWidth)
public Controller setHeight(int theHeight)
public int getWidth()
getWidth
in interface ControllerInterface
public int getHeight()
getHeight
in interface ControllerInterface
public void setDecimalPrecision(int theValue)
theValue
- public ControlWindow controlWindow()
public void setSprite(ControllerSprite theSprite)
public ControllerSprite getSprite()
public void enableSprite()
public void disableSprite()
public void lock()
public void unlock()
public boolean isLock()
public void setLock(boolean theValue)
public void setUserInteraction(boolean theValue)
public boolean isUserInteraction()
public boolean isXMLsavable()
isXMLsavable
in interface ControllerInterface
public Controller linebreak()
public ControlP5XMLElement getAsXML()
getAsXML
in interface ControllerInterface
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |