|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectcontrolP5.ControlP5Base
controlP5.ControlP5
public class ControlP5
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;
}
}
Field Summary | |
---|---|
static CColor |
CP5BLUE
|
static boolean |
DEBUG
use this static variable to turn DEBUG on or off. |
static int |
grixel
|
static CColor |
RED
|
static CColor |
RETRO
|
static int |
standard56
|
static int |
standard58
|
static int |
synt24
|
static CColor |
WHITE
|
Fields inherited from interface controlP5.ControlP5Constants |
---|
acceptClassList, ACTION_BROADCAST, ACTION_ENTER, ACTION_LEAVE, ACTION_PRESSED, ACTION_RELEASED, ACTION_RELEASEDOUTSIDE, ACTIVE, ALL, ALT, ARC, ARRAY, BACKSPACE, BASELINE, BITFONT, BOOLEAN, BOTTOM, BOTTOM_OUTSIDE, CAPTIONLABEL, CENTER, COMMANDKEY, CONTROL, controlEventClass, CUSTOM, DECREASE, DEFAULT, DELETE, DONE, DOWN, ELLIPSE, ENTER, ESCAPE, EVENT, eventMethod, FADEIN, FADEOUT, FIELD, FLOAT, HALF_PI, HIDE, HIGHLIGHT, HORIZONTAL, IDLE, IMAGE, INACTIVE, INCREASE, INTEGER, INVALID, KEYCONTROL, LEFT, LEFT_OUTSIDE, LINE, LOAD, MENU, METHOD, MOVE, MULTIPLES, OVER, PI, PRESSED, PRINT, RELEASE, RESET, RIGHT, RIGHT_OUTSIDE, SAVE, SHIFT, SINGLE, SINGLE_COLUMN, SINGLE_ROW, SPRITE, STRING, SWITCH, SWITCH_BACK, SWITCH_FORE, TAB, TOP, TOP_OUTSIDE, TRANSITION_WAIT_FADEIN, TWO_PI, UP, VALUELABEL, VERBOSE, VERTICAL, WAIT |
Constructor Summary | |
---|---|
ControlP5(processing.core.PApplet theParent)
Create a new instance of controlP5. |
|
ControlP5(processing.core.PApplet theParent,
ControlFont theControlFont)
|
Method Summary | |
---|---|
ControlP5 |
addCallback(CallbackListener theListener)
|
ControlP5 |
addCallback(CallbackListener[] theListeners)
|
ControlP5 |
addCallback(CallbackListener theListener,
Controller[] theControllers)
|
ControlP5 |
addCanvas(ControlWindowCanvas theCanvas)
adds a ControlWindowCanvas to the default sketch window. |
ControlP5 |
addListener(ControlListener[] theListeners)
|
void |
addPositionTo(int theX,
int theY,
ControllerInterface[] theControllers)
|
void |
addPositionTo(int theX,
int theY,
java.util.List theControllers)
|
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)
|
ControlP5 |
disableMouseWheel()
disables the mouse wheel as input for the main window, by default the mouse wheel is enabled. |
void |
disableShortcuts()
disables shortcuts such as alt-h for hiding/showing controllers |
ControlP5 |
enableMouseWheel()
enables the mouse wheel as input for the main window, by default the mouse wheel is enabled. |
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)
|
java.lang.Object |
get(java.lang.Class theClass,
java.lang.String theName)
|
ControllerInterface |
get(java.lang.String theName)
|
java.util.List |
getAll()
Returns a List of all controllers currently registered. |
java.util.List |
getAll(java.lang.Class 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)
|
ControlListener |
getListener(int theIndex)
|
java.util.List |
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()
|
ControlWindow |
getWindow()
convenience method to access the main window (ControlWindow class). |
ControlWindow |
getWindow(processing.core.PApplet theApplet)
|
ControlWindow |
getWindow(java.lang.String theWindowName)
|
void |
hide()
hide all controllers and tabs inside your sketch window. |
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 |
isMouseWheel()
checks the status of the mouse wheel. |
boolean |
isMoveable()
Checks if controllers are generally moveable |
boolean |
isShortcuts()
|
boolean |
isUpdate()
checks if automatic updates are enabled. |
boolean |
isVisible()
returns true or false according to the current visibility flag. |
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 |
move(java.lang.Object theObject,
ControllerGroup theGroup)
|
void |
moveControllersForObject(java.lang.Object theObject,
ControllerGroup theGroup)
|
void |
printControllerMap()
|
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 theController)
|
ControlP5 |
removeCallback(Controller[] theControllers)
|
ControlP5 |
removeListener(ControlListener theListener)
|
ControlP5 |
removeListener(ControlListener[] theListeners)
|
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 |
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)
|
boolean |
setFont(processing.core.PFont thePFont)
|
boolean |
setFont(processing.core.PFont thePFont,
int theFontSize)
|
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 |
void |
show()
shows all controllers and tabs in your sketch. |
void |
update()
forces all controllers to update. |
java.lang.String |
version()
Returns the current version of controlP5 |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final CColor CP5BLUE
public static boolean DEBUG
public static final int grixel
public static final CColor RED
public static final CColor RETRO
public static final int standard56
public static final int standard58
public static final int synt24
public static final CColor WHITE
Constructor Detail |
---|
public ControlP5(processing.core.PApplet theParent)
theParent
- PAppletpublic ControlP5(processing.core.PApplet theParent, ControlFont theControlFont)
Method Detail |
---|
public ControlP5 addCallback(CallbackListener theListener)
CallbackEvent
,
CallbackListener
public ControlP5 addCallback(CallbackListener[] theListeners)
CallbackEvent
,
CallbackListener
public ControlP5 addCallback(CallbackListener theListener, Controller[] theControllers)
CallbackEvent
,
CallbackListener
public ControlP5 addCanvas(ControlWindowCanvas theCanvas)
ControlWindowCanvas
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 theControllers)
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 ControlP5 disableMouseWheel()
public void disableShortcuts()
public ControlP5 enableMouseWheel()
public void enableShortcuts()
public ControllerGroup end()
public ControllerGroup end(ControllerGroup theGroup)
public java.lang.Object get(java.lang.Class theClass, java.lang.String theName)
public ControllerInterface get(java.lang.String theName)
public java.util.List getAll()
public java.util.List getAll(java.lang.Class 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.
theClass
- A class that extends ControllerInterface, which applies to all Controllers
and ControllerGroups
public static CColor getColor()
public ControlBroadcaster getControlBroadcaster()
ControlBroadcaster
public Controller getController(java.lang.String theName)
@Deprecated public ControllerInterface[] getControllerList()
ControlP5.getAll()
,
ControlP5.getAll(Class)
public ControlFont getFont()
public ControllerGroup getGroup(java.lang.String theGroupName)
public ControlListener getListener(int theIndex)
ControlListener
public java.util.List 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 ControlWindow getWindow()
public ControlWindow getWindow(processing.core.PApplet theApplet)
public ControlWindow getWindow(java.lang.String theWindowName)
public void hide()
ControlP5.show()
,
ControlP5.isVisible()
public boolean isAutoDraw()
public boolean isMouseOver()
public boolean isMouseOver(ControllerInterface theController)
public boolean isMouseWheel()
public boolean isMoveable()
public boolean isShortcuts()
public boolean isUpdate()
ControlP5.update()
,
ControlP5.setUpdate(boolean)
public boolean isVisible()
ControlP5.show()
,
ControlP5.hide()
public boolean loadProperties()
ControllerProperties
public boolean loadProperties(java.lang.String theFilePath)
theFilePath
-
public static java.util.logging.Logger logger()
public void move(java.lang.Object theObject, ControllerGroup theGroup)
public void moveControllersForObject(java.lang.Object theObject, ControllerGroup theGroup)
public void printControllerMap()
public ControlP5 register(java.lang.Object theObject, java.lang.String theIndex, ControllerInterface theController)
theController
- ControllerInterface
public void remove(java.lang.String theName)
theString
- Stringpublic ControlP5 removeCallback(CallbackListener[] theListeners)
CallbackEvent
,
CallbackListener
public ControlP5 removeCallback(Controller theController)
CallbackEvent
,
CallbackListener
public ControlP5 removeCallback(Controller[] theControllers)
CallbackEvent
,
CallbackListener
public ControlP5 removeListener(ControlListener theListener)
ControlListener
public ControlP5 removeListener(ControlListener[] theListeners)
ControlListener
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 setColor(CColor theColor)
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)
public boolean setFont(int theBitFontIndex)
public boolean setFont(processing.core.PFont thePFont)
public boolean setFont(processing.core.PFont thePFont, int theFontSize)
public ControlP5 setMoveable(boolean theFlag)
public void setTabEventsActive(boolean theFlag)
theFlag
- public void setTooltip(Tooltip theTooltip)
public void setUpdate(boolean theFlag)
theFlag
- ControlP5.update()
,
ControlP5.isUpdate()
public void show()
ControlP5.isVisible()
,
ControlP5.hide()
public void update()
ControlP5.isUpdate()
,
controlP5.ControlP5#setUpdate()
public java.lang.String version()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |