public class ControlP5 extends ControlP5Base
controlP5 is a processing and java library for creating simple control GUIs. The ControlP5 class, the core of controlP5.
All addController-Methods are located inside the ControlP5Base class.
ControlP5Base
/**
* ControlP5 Basics
*
* 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, 2011
* 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);
// create a slider
// parameters:
// name, minValue, maxValue, defaultValue, x, y, width, height
cp5.addSlider("sliderA", 100, 200, 100, 100, 260, 100, 14);
// create 3 numberboxes and assign an id for each
cp5.addNumberbox("numberboxA", myColorRect, 100, 140, 100, 14).setId(1);
cp5.addNumberbox("numberboxB", myColorBackground, 100, 180, 100, 14).setId(2);
cp5.addNumberbox("numberboxC", 0, 100, 220, 100, 14).setId(3);
// create a texfield
cp5.addTextfield("textA", 100, 290, 100, 20);
// change individual settings for a controller
cp5.getController("numberboxA").setMax(255);
cp5.getController("numberboxA").setMin(0);
}
void draw() {
background(myColorBackground);
fill(myColorRect);
rect(0, 0, width, 100);
}
// events from controller numberboxC are received here
public void numberboxC(int theValue) {
println("### got an event from numberboxC : "+theValue);
}
// an event from slider sliderA will change the value of textfield textA here
public void sliderA(int theValue) {
Textfield txt = ((Textfield)cp5.getController("textA"));
txt.setValue(""+theValue);
}
// for every change (a textfield event confirmed with a return) in textfield textA,
// function textA will be invoked
public void textA(String theValue) {
println("### got an event from textA : "+theValue);
}
// function controlEvent will be invoked with every value change
// in any registered controller
public void controlEvent(ControlEvent theEvent) {
println("got a control event from controller with id "+theEvent.getId());
switch(theEvent.getId()) {
case(1): // numberboxA is registered with id 1
myColorRect = (int)(theEvent.getController().getValue());
break;
case(2): // numberboxB is registered with id 2
myColorBackground = (int)(theEvent.getController().getValue());
break;
}
}
Modifier and Type | Field and Description |
---|---|
boolean |
blockDraw
Deprecated.
|
ControlWindow |
controlWindow |
static boolean |
DEBUG
use this static variable to turn DEBUG on or off.
|
static boolean |
isApplet |
static java.util.logging.Logger |
logger |
processing.core.PApplet |
papplet |
static java.lang.String |
VERSION |
acceptClassList, ACTION_BROADCAST, ACTION_CLICK, ACTION_DRAG, ACTION_ENTER, ACTION_EXIT, ACTION_LEAVE, ACTION_MOVE, ACTION_PRESS, ACTION_PRESSED, ACTION_RELEASE, ACTION_RELEASED, ACTION_RELEASEDOUTSIDE, ACTION_WHEEL, ACTIVE, ALL, ALT, AQUA, ARC, ARRAY, BACKSPACE, BASELINE, BITFONT, BLACK, BLUE, BOOLEAN, BOTTOM, BOTTOM_OUTSIDE, CAPTIONLABEL, CENTER, CHECKBOX, COMMANDKEY, CONTROL, controlEventClass, CUSTOM, DECREASE, DEFAULT, DELETE, DONE, DOWN, DROPDOWN, ELLIPSE, ENTER, ESCAPE, EVENT, eventMethod, FADEIN, FADEOUT, FIELD, FLOAT, FUCHSIA, GRAY, GREEN, grixel, HALF_PI, HIDE, HIGHLIGHT, HORIZONTAL, IDLE, IMAGE, INACTIVE, INCREASE, INTEGER, INVALID, J2D, KEYCONTROL, LEFT, LEFT_OUTSIDE, LIME, LINE, LIST, LOAD, MAROON, MENU, METHOD, MOVE, MULTI, MULTIPLES, NAVY, OLIVE, ORANGE, OVER, P2D, P3D, PI, PRESSED, PRINT, PURPLE, RED, RELEASE, RESET, RIGHT, RIGHT_OUTSIDE, SAVE, SHIFT, SILVER, SINGLE, SINGLE_COLUMN, SINGLE_ROW, SPRITE, standard56, standard58, STRING, SWITCH, SWITCH_BACK, SWITCH_FORE, synt24, TAB, TEAL, THEME_A, THEME_CP52014, THEME_CP5BLUE, THEME_RED, THEME_RETRO, THEME_WHITE, TOP, TOP_OUTSIDE, TRANSITION_WAIT_FADEIN, TREE, TWO_PI, UP, VALUELABEL, VERBOSE, VERTICAL, WAIT, WHITE, YELLOW
Constructor and Description |
---|
ControlP5(processing.core.PApplet theParent)
Create a new instance of controlP5.
|
ControlP5(processing.core.PApplet theParent,
ControlFont theControlFont) |
ControlP5(processing.core.PApplet theParent,
processing.core.PFont thePFont) |
Modifier and Type | Method and Description |
---|---|
ControlP5 |
addCallback(CallbackListener... theListeners) |
ControlP5 |
addCallback(CallbackListener theListener) |
ControlP5 |
addCallback(CallbackListener theListener,
Controller<?>... theControllers) |
ControlP5 |
addCanvas(Canvas theCanvas)
adds a Canvas to the default sketch window.
|
void |
addControlsFor(java.lang.Object theObject)
TODO
|
ControlP5 |
addListener(ControlListener... theListeners) |
void |
addPositionTo(int theX,
int theY,
ControllerInterface<?>... theControllers) |
void |
addPositionTo(int theX,
int theY,
java.util.List<ControllerInterface<?>> theControllers) |
static boolean |
b(java.lang.Object o) |
ControllerGroup<?> |
begin()
cp5.begin() and cp5.end() are mechanisms to
auto-layout controllers, see the ControlP5beginEnd
example.
|
ControllerGroup<?> |
begin(ControllerGroup<?> theGroup) |
ControllerGroup<?> |
begin(ControllerGroup<?> theGroup,
int theX,
int theY) |
ControllerGroup<?> |
begin(ControlWindow theWindow) |
ControllerGroup<?> |
begin(ControlWindow theWindow,
int theX,
int theY) |
ControllerGroup<?> |
begin(int theX,
int theY) |
static double |
d(java.lang.Object o) |
void |
disableShortcuts()
disables shortcuts such as alt-h for hiding/showing
controllers
|
void |
dispose()
disposes and clears all controlP5 elements.
|
void |
draw()
call draw() from your program when autoDraw is
disabled.
|
void |
enableShortcuts()
enables shortcuts.
|
ControllerGroup<?> |
end()
cp5.begin() and cp5.end() are mechanisms to
auto-layout controllers, see the ControlP5beginEnd
example.
|
ControllerGroup<?> |
end(ControllerGroup<?> theGroup) |
static float |
f(java.lang.Object o) |
<C> C |
get(java.lang.Class<C> theClass,
java.lang.String theName) |
ControllerInterface<?> |
get(java.lang.Object theObject,
java.lang.String theName) |
ControllerInterface<?> |
get(java.lang.String theName) |
java.util.List<ControllerInterface<?>> |
getAll()
Returns a List of all controllers currently
registered.
|
<T> java.util.List<T> |
getAll(java.lang.Class<T> theClass)
Returns a list of controllers or groups of a
particular type.
|
static CColor |
getColor() |
ControlBroadcaster |
getControlBroadcaster() |
Controller<?> |
getController(java.lang.String theName) |
ControllerInterface<?>[] |
getControllerList()
Deprecated.
|
ControlFont |
getFont() |
ControllerGroup<?> |
getGroup(java.lang.String theGroupName) |
java.util.List<ControllerInterface<?>> |
getList() |
ControlListener |
getListener(int theIndex) |
java.util.List<ControllerInterface<?>> |
getMouseOverList()
convenience method to check if the mouse (or pointer)
is hovering over a specific controller.
|
ControlWindow.Pointer |
getPointer()
convenience method to access the pointer of the main
control window.
|
Tab |
getTab(ControlWindow theWindow,
java.lang.String theName) |
Tab |
getTab(java.lang.String theName) |
Tooltip |
getTooltip() |
float |
getValue(java.lang.String theIndex) |
ControlWindow |
getWindow()
convenience method to access the main window
(ControlWindow class).
|
ControlWindow |
getWindow(processing.core.PApplet theApplet) |
void |
hide()
hide all controllers and tabs inside your sketch
window.
|
static int |
i(java.lang.Object o) |
static int |
i(java.lang.String o) |
static java.lang.Object |
invoke(java.lang.Object theObject,
java.lang.String theMember,
java.lang.Object... theParams) |
boolean |
isAutoDraw()
check if the autoDraw function for the main window is
enabled(true) or disabled(false).
|
boolean |
isMouseOver()
convenience method to check if the mouse (or pointer)
is hovering over any controller.
|
boolean |
isMouseOver(ControllerInterface<?> theController)
convenience method to check if the mouse (or pointer)
is hovering over a specific controller.
|
boolean |
isMoveable()
Checks if controllers are generally moveable
|
static boolean |
isNumeric(java.lang.Object o) |
static boolean |
isNumeric(java.lang.String str) |
boolean |
isShortcuts() |
boolean |
isUpdate()
checks if automatic updates are enabled.
|
boolean |
isVisible()
returns true or false according to the current
visibility flag.
|
void |
keyEvent(processing.event.KeyEvent theKeyEvent) |
static long |
l(java.lang.Object o) |
boolean |
loadLayout(java.lang.String theFilePath) |
boolean |
loadProperties()
Loads properties from a default properties file and
changes values of controllers accordingly.
|
boolean |
loadProperties(java.lang.String theFilePath)
Loads properties from a properties file and changes
the values of controllers accordingly, the filepath
is given by parameter theFilePath.
|
static java.util.logging.Logger |
logger() |
void |
mouseEvent(processing.event.MouseEvent theMouseEvent) |
void |
move(java.lang.Object theObject,
ControllerGroup<?> theGroup) |
void |
moveControllersForObject(java.lang.Object theObject,
ControllerGroup<?> theGroup) |
void |
pre() |
void |
printControllerMap() |
ControlP5 |
register(ControllerInterface<?> theController) |
ControlP5 |
register(java.lang.Object theObject,
java.lang.String theIndex,
ControllerInterface<?> theController)
registers a Controller with ControlP5, a Controller
should/must be registered with a unique name.
|
void |
remove(java.lang.String theName)
removes a controlP5 element such as a controller,
group, or tab by name.
|
ControlP5 |
removeCallback(CallbackListener... theListeners) |
ControlP5 |
removeCallback(Controller<?>... theControllers) |
ControlP5 |
removeCallback(Controller<?> theController) |
ControlP5 |
removeCanvas(Canvas theCanvas) |
ControlP5 |
removeListener(ControlListener... theListeners) |
ControlP5 |
removeListener(ControlListener theListener) |
static java.lang.String |
s(java.lang.Object o) |
static java.lang.String |
s(java.lang.Object o,
java.lang.String theDefault) |
static java.lang.String |
s(java.lang.String o) |
void |
saveLayout(java.lang.String theFilePath) |
boolean |
saveProperties()
Saves the current values of controllers into a
default properties file
|
boolean |
saveProperties(java.lang.String theFilePath)
Saves the current values of controllers into a file,
the filepath is given by parameter theFilePath.
|
boolean |
saveProperties(java.lang.String theFilePath,
java.lang.String... theSets) |
void |
setAutoDraw(boolean theFlag)
by default controlP5 draws any controller on top of
any drawing done in the draw() function (this doesnt
apply to P3D where controlP5.draw() has to be called
manually in the sketch's draw() function ).
|
void |
setAutoInitialization(boolean theFlag)
autoInitialization can be very handy when it comes to
initializing values, e.g.
|
ControlP5 |
setBackground(int theColor) |
ControlP5 |
setBroadcast(boolean theValue) |
ControlP5 |
setColor(CColor theColor) |
ControlP5 |
setColorActive(int theColor)
sets the active state color of tabs and controllers,
this cascades down to all known controllers.
|
ControlP5 |
setColorBackground(int theColor)
sets the background color of tabs and controllers,
this cascades down to all known controllers.
|
ControlP5 |
setColorCaptionLabel(int theColor)
sets the label color of tabs and controllers, this
cascades down to all known controllers.
|
ControlP5 |
setColorForeground(int theColor)
sets the foreground color of tabs and controllers,
this cascades down to all known controllers.
|
ControlP5 |
setColorValueLabel(int theColor)
sets the value color of controllers, this cascades
down to all known controllers.
|
boolean |
setFont(ControlFont theControlFont) |
boolean |
setFont(int theBitFontIndex)
Deprecated.
|
boolean |
setFont(processing.core.PFont thePFont) |
boolean |
setFont(processing.core.PFont thePFont,
int theFontSize) |
ControlP5 |
setGraphics(processing.core.PApplet theApplet,
int theX,
int theY) |
ControlP5 |
setGraphics(processing.core.PGraphics theGraphics,
int theX,
int theY) |
void |
setMouseWheelRotation(int theRotation) |
ControlP5 |
setMoveable(boolean theFlag)
Enables/disables Controllers to be moved around when
ALT-key is down and mouse is dragged.
|
void |
setTabEventsActive(boolean theFlag)
By default event originating from tabs are disabled,
use setTabEventsActive(true) to receive controlEvents
when tabs are clicked.
|
void |
setTooltip(Tooltip theTooltip) |
void |
setUpdate(boolean theFlag)
changes the update behavior according to parameter
theFlag
|
ControlP5 |
setVisible(boolean b) |
void |
show()
shows all controllers and tabs in your sketch.
|
static java.util.List |
toList(java.lang.Object o) |
static java.util.Map |
toMap(java.lang.Object o) |
void |
update()
forces all controllers to update.
|
java.lang.String |
version()
Returns the current version of controlP5
|
addAccordion, addAccordion, addBang, addBang, addButton, addButton, addChart, addCheckBox, addCheckBox, addColorPicker, addColorPicker, addColorWheel, addColorWheel, addConsole, addControllersFor, addControllersFor, addFrameRate, addGroup, addGroup, addKnob, addKnob, addMatrix, addMatrix, addMultiList, addMultiList, addNumberbox, addNumberbox, addRadioButton, addRadioButton, addRange, addRange, addScrollableList, addScrollableList, addSlider, addSlider, addSlider2D, addSlider2D, addTab, addTextarea, addTextfield, addTextfield, addTextlabel, addToggle, addToggle, getDefaultTab, getKey, getKeyCode, getLayout, getObjectForController, getProperties, getPublicMethodsFor, getPublicMethodsFor, getPublicMethodsFor, getPublicMethodsFor, hide, isAltDown, isControlDown, isMetaDown, isShiftDown, listenTo, mapKeyFor, moveTo, printPublicMethodsFor, printPublicMethodsFor, remove, removeKeyFor, removeKeyFor, removeKeysFor, removeKeysFor, removeProperty, setAutoAddDirection, setAutoSpacing, setAutoSpacing, setAutoSpacing, setAutoSpacing, setColor, setPosition, show, stopListeningTo
addAccordion, addAccordion, addBang, addBang, addBang, addBang, addBoundingBox, addBoundingBox, addButton, addButton, addButton, addButton, addButton, addChart, addCheckBox, addCheckBox, addColorPicker, addColorPicker, addColorWheel, addColorWheel, addController, addController, addControlWindow, addControlWindow, addControlWindow, addControlWindow, addControlWindow, addDropdownList, addDropdownList, addDropdownList, addGroup, addGroup, addGroup, addGroup, addGroup, addGroup, addKnob, addKnob, addKnob, addKnob, addKnob, addKnob, addKnob, addListBox, addListBox, addListBox, addMatrix, addMatrix, addMultiList, addMultiList, addNumberbox, addNumberbox, addNumberbox, addNumberbox, addNumberbox, addRadio, addRadio, addRadioButton, addRadioButton, addRange, addRange, addRange, addRange, addScrollableList, addScrollableList, addScrollableList, addSlider, addSlider, addSlider, addSlider, addSlider, addSlider, addSlider, addSlider2D, addSlider2D, addSlider2D, addSlider2D, addTab, addTab, addTextarea, addTextfield, addTextfield, addTextfield, addTextlabel, addTextlabel, addTextlabel, addTextlabel, addToggle, addToggle, addToggle, addToggle, addToggle, addToggle, addToggle, addTooltip, getController, getTextlabel, getTextlabel
@Deprecated public boolean blockDraw
public ControlWindow controlWindow
public static boolean DEBUG
public static boolean isApplet
public static final java.util.logging.Logger logger
public processing.core.PApplet papplet
public static final java.lang.String VERSION
public ControlP5(processing.core.PApplet theParent)
theParent
- PAppletpublic ControlP5(processing.core.PApplet theParent, ControlFont theControlFont)
public ControlP5(processing.core.PApplet theParent, processing.core.PFont thePFont)
public ControlP5 addCallback(CallbackListener... theListeners)
CallbackEvent
,
CallbackListener
public ControlP5 addCallback(CallbackListener theListener)
CallbackEvent
,
CallbackListener
public ControlP5 addCallback(CallbackListener theListener, Controller<?>... theControllers)
CallbackEvent
,
CallbackListener
public ControlP5 addCanvas(Canvas theCanvas)
Canvas
public void addControlsFor(java.lang.Object theObject)
public ControlP5 addListener(ControlListener... theListeners)
ControlListener
public void addPositionTo(int theX, int theY, ControllerInterface<?>... theControllers)
public void addPositionTo(int theX, int theY, java.util.List<ControllerInterface<?>> theControllers)
public static boolean b(java.lang.Object o)
public ControllerGroup<?> begin()
public ControllerGroup<?> begin(ControllerGroup<?> theGroup)
public ControllerGroup<?> begin(ControllerGroup<?> theGroup, int theX, int theY)
public ControllerGroup<?> begin(ControlWindow theWindow)
public ControllerGroup<?> begin(ControlWindow theWindow, int theX, int theY)
public ControllerGroup<?> begin(int theX, int theY)
public static double d(java.lang.Object o)
public void disableShortcuts()
public void dispose()
public void draw()
public void enableShortcuts()
public ControllerGroup<?> end()
public ControllerGroup<?> end(ControllerGroup<?> theGroup)
public static float f(java.lang.Object o)
public <C> C get(java.lang.Class<C> theClass, java.lang.String theName)
public ControllerInterface<?> get(java.lang.Object theObject, java.lang.String theName)
public ControllerInterface<?> get(java.lang.String theName)
public java.util.List<ControllerInterface<?>> getAll()
public <T> java.util.List<T> getAll(java.lang.Class<T> theClass)
List list = controlP5.getAll(Bang.class);
println(list);
for(Bang b:list) {
b.setColorForeground(color(255,255,0));
}
Here the foreground color of all Bangs
is changed to yellow.T
- theClass
- A class that extends
ControllerInterface, which applies to all
Controllers and ControllerGroupspublic static CColor getColor()
public ControlBroadcaster getControlBroadcaster()
ControlBroadcaster
public Controller<?> getController(java.lang.String theName)
@Deprecated public ControllerInterface<?>[] getControllerList()
getAll()
,
getAll(Class)
public ControlFont getFont()
public ControllerGroup<?> getGroup(java.lang.String theGroupName)
public java.util.List<ControllerInterface<?>> getList()
getAll(Class)
public ControlListener getListener(int theIndex)
ControlListener
public java.util.List<ControllerInterface<?>> getMouseOverList()
public ControlWindow.Pointer getPointer()
public Tab getTab(ControlWindow theWindow, java.lang.String theName)
public Tab getTab(java.lang.String theName)
public Tooltip getTooltip()
public float getValue(java.lang.String theIndex)
public ControlWindow getWindow()
public ControlWindow getWindow(processing.core.PApplet theApplet)
public void hide()
show()
,
isVisible()
public static int i(java.lang.Object o)
public static int i(java.lang.String o)
public static java.lang.Object invoke(java.lang.Object theObject, java.lang.String theMember, java.lang.Object... theParams)
public boolean isAutoDraw()
public boolean isMouseOver()
public boolean isMouseOver(ControllerInterface<?> theController)
public boolean isMoveable()
public static boolean isNumeric(java.lang.Object o)
public static boolean isNumeric(java.lang.String str)
public boolean isShortcuts()
public boolean isUpdate()
update()
,
setUpdate(boolean)
public boolean isVisible()
public void keyEvent(processing.event.KeyEvent theKeyEvent)
public static long l(java.lang.Object o)
public boolean loadLayout(java.lang.String theFilePath)
theFilePath
- public boolean loadProperties()
ControllerProperties
public boolean loadProperties(java.lang.String theFilePath)
theFilePath
- public static java.util.logging.Logger logger()
public void mouseEvent(processing.event.MouseEvent theMouseEvent)
public void move(java.lang.Object theObject, ControllerGroup<?> theGroup)
public void moveControllersForObject(java.lang.Object theObject, ControllerGroup<?> theGroup)
public void pre()
public void printControllerMap()
public ControlP5 register(ControllerInterface<?> theController)
public ControlP5 register(java.lang.Object theObject, java.lang.String theIndex, ControllerInterface<?> theController)
theController
- ControllerInterfacepublic void remove(java.lang.String theName)
theString
- Stringpublic ControlP5 removeCallback(CallbackListener... theListeners)
CallbackEvent
,
CallbackListener
public ControlP5 removeCallback(Controller<?>... theControllers)
CallbackEvent
,
CallbackListener
public ControlP5 removeCallback(Controller<?> theController)
CallbackEvent
,
CallbackListener
public ControlP5 removeListener(ControlListener... theListeners)
ControlListener
public ControlP5 removeListener(ControlListener theListener)
ControlListener
public static java.lang.String s(java.lang.Object o)
public static java.lang.String s(java.lang.Object o, java.lang.String theDefault)
public static java.lang.String s(java.lang.String o)
public void saveLayout(java.lang.String theFilePath)
theFilePath
- public boolean saveProperties()
ControllerProperties
public boolean saveProperties(java.lang.String theFilePath)
ControllerProperties
public boolean saveProperties(java.lang.String theFilePath, java.lang.String... theSets)
public void setAutoDraw(boolean theFlag)
theFlag
- booleanpublic void setAutoInitialization(boolean theFlag)
theFlag
- booleanpublic ControlP5 setBackground(int theColor)
public ControlP5 setBroadcast(boolean theValue)
public ControlP5 setColorActive(int theColor)
public ControlP5 setColorBackground(int theColor)
public ControlP5 setColorCaptionLabel(int theColor)
public ControlP5 setColorForeground(int theColor)
public ControlP5 setColorValueLabel(int theColor)
public boolean setFont(ControlFont theControlFont)
@Deprecated public boolean setFont(int theBitFontIndex)
public boolean setFont(processing.core.PFont thePFont)
public boolean setFont(processing.core.PFont thePFont, int theFontSize)
public ControlP5 setGraphics(processing.core.PApplet theApplet, int theX, int theY)
public ControlP5 setGraphics(processing.core.PGraphics theGraphics, int theX, int theY)
public void setMouseWheelRotation(int theRotation)
public ControlP5 setMoveable(boolean theFlag)
public void setTabEventsActive(boolean theFlag)
theFlag
- public void setTooltip(Tooltip theTooltip)
public void setUpdate(boolean theFlag)
theFlag
- update()
,
isUpdate()
public ControlP5 setVisible(boolean b)
public void show()
isVisible()
,
hide()
public static java.util.List toList(java.lang.Object o)
public static java.util.Map toMap(java.lang.Object o)
public void update()
isUpdate()
,
controlP5.ControlP5#setUpdate()
public java.lang.String version()
processing library controlP5 by Andreas Schlegel. (c) 2006-2014