|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectcontrolP5.ControlEvent
public class ControlEvent
A controlEvent is sent to a PApplet or a ControlListener whenever a controller value has changed.
Events can also be sent when a tab is activated, but by default tab events are disabled and have
to be enabled with Tab
Tab.activateEvent(). for detailed information see the tab
documentation.
/**
* ControlP5 ControlEvent.
* every control event is automatically forwarded to the function controlEvent(ControlEvent)
* inside a sketch if such function is available. For further details about the API of
* the ControlEvent class, please refer to the documentation.
*
*
* find a list of public methods available for ControlEvent
* at the bottom of this sketch's source code
*
* by Andreas Schlegel, 2012
* www.sojamo.de/libraries/controlP5
*
*/
import controlP5.*;
ControlP5 cp5;
public int myColorRect = 200;
public int myColorBackground = 100;
void setup() {
size(400, 400);
noStroke();
cp5 = new ControlP5(this);
cp5.addNumberbox("n1")
.setValue(myColorRect)
.setPosition(100, 160)
.setSize(100, 14)
.setId(1);
cp5.addNumberbox("n2")
.setValue(myColorBackground)
.setPosition(100, 200)
.setSize(100, 14)
.setId(2);
cp5.addTextfield("n3")
.setPosition(100, 240)
.setSize(100, 20)
.setId(3);
}
void draw() {
background(myColorBackground);
fill(myColorRect);
rect(0, 0, width, 100);
}
void controlEvent(ControlEvent theEvent) {
println("got a control event from controller with id "+theEvent.getController().getId());
if (theEvent.isFrom(cp5.getController("n1"))) {
println("this event was triggered by Controller n1");
}
switch(theEvent.getController().getId()) {
case(1):
myColorRect = (int)(theEvent.getController().getValue());
break;
case(2):
myColorBackground = (int)(theEvent.getController().getValue());
break;
case(3):
println(theEvent.getController().getStringValue());
break;
}
}
/*
a list of all methods available for ControlEvent
use ControlP5.printPublicMethodsFor(ControlEvent.class);
to print the following list into the console.
You can find further details about class ControlEvent in the javadoc.
Format:
ClassName : returnType methodName(parameter type)
controlP5.ControlEvent : ControlGroup getGroup()
controlP5.ControlEvent : Controller getController()
controlP5.ControlEvent : String getLabel()
controlP5.ControlEvent : String getName()
controlP5.ControlEvent : String getStringValue()
controlP5.ControlEvent : Tab getTab()
controlP5.ControlEvent : boolean isController()
controlP5.ControlEvent : boolean isFrom(ControllerInterface)
controlP5.ControlEvent : boolean isFrom(String)
controlP5.ControlEvent : boolean isGroup()
controlP5.ControlEvent : boolean isTab()
controlP5.ControlEvent : float getValue()
controlP5.ControlEvent : float[] getArrayValue()
controlP5.ControlEvent : int getId()
controlP5.ControlEvent : int getType()
java.lang.Object : String toString()
java.lang.Object : boolean equals(Object)
*/
Field Summary | |
---|---|
static int |
CONTROLLER
|
static int |
GROUP
|
static int |
TAB
|
static int |
UNDEFINDED
|
Method Summary | |
---|---|
float[] |
getArrayValue()
Returns a float array, applies to e.g. |
float |
getArrayValue(int theIndex)
Returns a float value at a particular index from a controller's array value. |
Controller |
getController()
Returns the instance of the controller sending the ControlEvent. |
ControlGroup |
getGroup()
Returns the group that evoked the ControlEvent |
int |
getId()
Returns the controller's id, if an id has not been set before the default value -1 will be returned. |
java.lang.String |
getLabel()
Gets the text of the controller's label that has evoked the event. |
java.lang.String |
getName()
returns the controller's name |
java.lang.String |
getStringValue()
|
Tab |
getTab()
Returns the tab that triggered the ControlEvent |
int |
getType()
|
float |
getValue()
|
boolean |
isAssignableFrom(java.lang.Class c)
|
boolean |
isController()
Checks if the ControlEvent was triggered by a controller |
boolean |
isFrom(ControllerInterface theController)
Checks if the ControlEvent originates from a specific Controller or ControllerGroup. |
boolean |
isFrom(java.lang.String theControllerName)
checks if the ControlEvent originates from a specific Controller or ControllerGroup identifiable by name. |
boolean |
isGroup()
Checks if the ControlEvent was triggered by a ControlGroup |
boolean |
isTab()
Checks if the ControlEvent was triggered by a tab |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static int CONTROLLER
public static int GROUP
public static int TAB
public static int UNDEFINDED
Method Detail |
---|
public float[] getArrayValue()
public float getArrayValue(int theIndex)
theIndex
-
public Controller getController()
public ControlGroup getGroup()
public int getId()
public java.lang.String getLabel()
public java.lang.String getName()
public java.lang.String getStringValue()
public Tab getTab()
public int getType()
public float getValue()
public boolean isAssignableFrom(java.lang.Class c)
public boolean isController()
Controller
public boolean isFrom(ControllerInterface theController)
theController
-
public boolean isFrom(java.lang.String theControllerName)
theController
-
public boolean isGroup()
ControllerGroup
public boolean isTab()
Tab
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 |