public class ControlGroup<T> extends ControllerGroup<T> implements ControlListener
In previous versions you would use the ControlGroup class to bundle controllers in a group. Now please use the Group class to do so.
ControlGroup extends ControllerGroup, for a list and documentation of available methods see the
ControllerGroup
documentation.
Group
/**
* ControlP5 Group
*
*
* find a list of public methods available for the Group Controller
* at the bottom of this sketch.
*
* by Andreas Schlegel, 2012
* www.sojamo.de/libraries/controlp5
*
*/
import controlP5.*;
ControlP5 cp5;
void setup() {
size(700,400);
cp5 = new ControlP5(this);
Group g1 = cp5.addGroup("g1")
.setPosition(100,100)
.setBackgroundHeight(100)
.setBackgroundColor(color(255,50))
;
cp5.addBang("A-1")
.setPosition(10,20)
.setSize(80,20)
.setGroup(g1)
;
cp5.addBang("A-2")
.setPosition(10,60)
.setSize(80,20)
.setGroup(g1)
;
Group g2 = cp5.addGroup("g2")
.setPosition(300,100)
.setWidth(300)
.activateEvent(true)
.setBackgroundColor(color(255,80))
.setBackgroundHeight(100)
.setLabel("Hello World.")
;
cp5.addSlider("S-1")
.setPosition(80,10)
.setSize(180,9)
.setGroup(g2)
;
cp5.addSlider("S-2")
.setPosition(80,20)
.setSize(180,9)
.setGroup(g2)
;
cp5.addRadioButton("radio")
.setPosition(10,10)
.setSize(20,9)
.addItem("black",0)
.addItem("red",1)
.addItem("green",2)
.addItem("blue",3)
.addItem("grey",4)
.setGroup(g2)
;
}
void draw() {
background(0);
}
void controlEvent(ControlEvent theEvent) {
if(theEvent.isGroup()) {
println("got an event from group "
+theEvent.getGroup().getName()
+", isOpen? "+theEvent.getGroup().isOpen()
);
} else if (theEvent.isController()){
println("got something from a controller "
+theEvent.getController().getName()
);
}
}
void keyPressed() {
if(key==' ') {
if(cp5.getGroup("g1")!=null) {
cp5.getGroup("g1").remove();
}
}
}
/*
a list of all methods available for the Group Controller
use ControlP5.printPublicMethodsFor(Group.class);
to print the following list into the console.
You can find further details about class Group in the javadoc.
Format:
ClassName : returnType methodName(parameter type)
controlP5.ControlGroup : Group activateEvent(boolean)
controlP5.ControlGroup : Group addListener(ControlListener)
controlP5.ControlGroup : Group hideBar()
controlP5.ControlGroup : Group removeListener(ControlListener)
controlP5.ControlGroup : Group setBackgroundColor(int)
controlP5.ControlGroup : Group setBackgroundHeight(int)
controlP5.ControlGroup : Group setBarHeight(int)
controlP5.ControlGroup : Group showBar()
controlP5.ControlGroup : Group updateInternalEvents(PApplet)
controlP5.ControlGroup : String getInfo()
controlP5.ControlGroup : String toString()
controlP5.ControlGroup : boolean isBarVisible()
controlP5.ControlGroup : int getBackgroundHeight()
controlP5.ControlGroup : int getBarHeight()
controlP5.ControlGroup : int listenerSize()
controlP5.ControllerGroup : CColor getColor()
controlP5.ControllerGroup : ControlWindow getWindow()
controlP5.ControllerGroup : ControlWindowCanvas addCanvas(ControlWindowCanvas)
controlP5.ControllerGroup : Controller getController(String)
controlP5.ControllerGroup : ControllerProperty getProperty(String)
controlP5.ControllerGroup : ControllerProperty getProperty(String, String)
controlP5.ControllerGroup : Group add(ControllerInterface)
controlP5.ControllerGroup : Group bringToFront()
controlP5.ControllerGroup : Group bringToFront(ControllerInterface)
controlP5.ControllerGroup : Group close()
controlP5.ControllerGroup : Group disableCollapse()
controlP5.ControllerGroup : Group enableCollapse()
controlP5.ControllerGroup : Group hide()
controlP5.ControllerGroup : Group moveTo(ControlWindow)
controlP5.ControllerGroup : Group moveTo(PApplet)
controlP5.ControllerGroup : Group open()
controlP5.ControllerGroup : Group registerProperty(String)
controlP5.ControllerGroup : Group registerProperty(String, String)
controlP5.ControllerGroup : Group remove(CDrawable)
controlP5.ControllerGroup : Group remove(ControllerInterface)
controlP5.ControllerGroup : Group removeCanvas(ControlWindowCanvas)
controlP5.ControllerGroup : Group removeProperty(String)
controlP5.ControllerGroup : Group removeProperty(String, String)
controlP5.ControllerGroup : Group setAddress(String)
controlP5.ControllerGroup : Group setArrayValue(float[])
controlP5.ControllerGroup : Group setColor(CColor)
controlP5.ControllerGroup : Group setColorActive(int)
controlP5.ControllerGroup : Group setColorBackground(int)
controlP5.ControllerGroup : Group setColorForeground(int)
controlP5.ControllerGroup : Group setColorLabel(int)
controlP5.ControllerGroup : Group setColorValue(int)
controlP5.ControllerGroup : Group setHeight(int)
controlP5.ControllerGroup : Group setId(int)
controlP5.ControllerGroup : Group setLabel(String)
controlP5.ControllerGroup : Group setMouseOver(boolean)
controlP5.ControllerGroup : Group setMoveable(boolean)
controlP5.ControllerGroup : Group setOpen(boolean)
controlP5.ControllerGroup : Group setPosition(PVector)
controlP5.ControllerGroup : Group setPosition(float, float)
controlP5.ControllerGroup : Group setStringValue(String)
controlP5.ControllerGroup : Group setUpdate(boolean)
controlP5.ControllerGroup : Group setValue(float)
controlP5.ControllerGroup : Group setVisible(boolean)
controlP5.ControllerGroup : Group setWidth(int)
controlP5.ControllerGroup : Group show()
controlP5.ControllerGroup : Group update()
controlP5.ControllerGroup : Group updateAbsolutePosition()
controlP5.ControllerGroup : Label getCaptionLabel()
controlP5.ControllerGroup : Label getValueLabel()
controlP5.ControllerGroup : PVector getPosition()
controlP5.ControllerGroup : String getAddress()
controlP5.ControllerGroup : String getInfo()
controlP5.ControllerGroup : String getName()
controlP5.ControllerGroup : String getStringValue()
controlP5.ControllerGroup : String toString()
controlP5.ControllerGroup : Tab getTab()
controlP5.ControllerGroup : boolean isCollapse()
controlP5.ControllerGroup : boolean isMouseOver()
controlP5.ControllerGroup : boolean isMoveable()
controlP5.ControllerGroup : boolean isOpen()
controlP5.ControllerGroup : boolean isUpdate()
controlP5.ControllerGroup : boolean isVisible()
controlP5.ControllerGroup : boolean setMousePressed(boolean)
controlP5.ControllerGroup : float getValue()
controlP5.ControllerGroup : float[] getArrayValue()
controlP5.ControllerGroup : int getHeight()
controlP5.ControllerGroup : int getId()
controlP5.ControllerGroup : int getWidth()
controlP5.ControllerGroup : void remove()
java.lang.Object : String toString()
java.lang.Object : boolean equals(Object)
*/
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 |
---|
ControlGroup(ControlP5 theControlP5,
ControllerGroup<?> theParent,
java.lang.String theName,
int theX,
int theY,
int theW,
int theH) |
ControlGroup(ControlP5 theControlP5,
java.lang.String theName)
Convenience constructor to extend ControlGroup.
|
Modifier and Type | Method and Description |
---|---|
T |
activateEvent(boolean theFlag)
activates or deactivates the Event status of a ControlGroup.
|
T |
addListener(ControlListener theListener)
adds a listener to the controller.
|
void |
controlEvent(ControlEvent theEvent)
controlEvent is called by controlP5's ControlBroadcaster to inform available listeners about
value changes.
|
int |
getBackgroundHeight()
get the height of the controlGroup's background.
|
int |
getBarHeight() |
java.lang.String |
getInfo() |
int |
listenerSize() |
void |
mousePressed() |
T |
removeListener(ControlListener theListener)
remove a listener from the controller.
|
T |
setBackgroundColor(int theColor)
set the background color of a controlGroup.
|
T |
setBackgroundHeight(int theHeight)
set the height of the controlGroup's background.
|
T |
setBarHeight(int theHeight)
set the height of the top bar (used to open/close and move a controlGroup).
|
T |
setSize(int theWidth,
int theHeight) |
java.lang.String |
stringValue()
!!! experimental, see ControllerGroup.value()
|
java.lang.String |
toString() |
T |
updateInternalEvents(processing.core.PApplet theApplet)
a method for putting input events like e.g.
|
absolutePosition, add, addCanvas, addCloseButton, addDrawable, arrayValue, bringToFront, bringToFront, close, color, continuousUpdateEvents, controller, disableCollapse, draw, enableCollapse, getAbsolutePosition, getAddress, getArrayValue, getArrayValue, getCaptionLabel, getColor, getController, getHeight, getId, getName, getParent, getPickingColor, getPosition, getProperty, getProperty, getStringValue, getTab, getValue, getValueLabel, getWidth, getWindow, hide, hideArrow, hideBar, id, init, isBarVisible, isCollapse, isMouseOver, isMoveable, isOpen, isUpdate, isVisible, keyEvent, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, name, open, parent, position, registerProperty, registerProperty, remove, remove, remove, removeCanvas, removeCloseButton, removeProperty, removeProperty, setAbsolutePosition, setAddress, setArrayValue, setArrayValue, setCaptionLabel, setColor, setColorActive, setColorBackground, setColorForeground, setColorLabel, setColorValue, setGroup, setGroup, setHeight, setId, setLabel, setMouseOver, setMousePressed, setMoveable, setOpen, setPosition, setPosition, setStringValue, setTab, setTab, setTab, setTitle, setUpdate, setValue, setVisible, setWidth, show, showArrow, showBar, update, updateAbsolutePosition, updateEvents, value
public ControlGroup(ControlP5 theControlP5, ControllerGroup<?> theParent, java.lang.String theName, int theX, int theY, int theW, int theH)
public ControlGroup(ControlP5 theControlP5, java.lang.String theName)
theControlP5
- theName
- /**
* ControlP5 extending Controllers
*
* the following example shows how to extend the Controller class to
* create customizable Controllers. You can either extend the Controller class itself,
* or any class that extends Controller itself like the Slider, Button, DropdownList, etc.
*
* How to:
*
* 1) do a super call to the convenience constructor requiring
* 2 parameter (ControlP5 instance, name)
*
* 2) the Controller class has a set of empty methods that allow you to capture
* inputs from the mouse including
* onEnter(), onLeave(), onPress(), onRelease(), onClick(), onScroll(int), onDrag()
* These you can override and include functionality as needed.
*
* 3) use method getPointer() to return the local (relative)
* xy-coordinates of the controller
*
* 4) after instantiation custom controllers are treated the same
* as default controlP5 controllers.
*
* by Andreas Schlegel, 2012
* www.sojamo.de/libraries/controlp5
*
*/
import controlP5.*;
ControlP5 cp5;
PApplet p;
void setup() {
size(400, 400);
cp5 = new ControlP5(this);
// create 2 groups to show nesting of custom controllers and
//
Group g1 = cp5.addGroup("a").setPosition(0,100).setWidth(180);
Group g2 = cp5.addGroup("b").setPosition(0,10).setWidth(180);
g2.moveTo(g1);
// create 2 custom Controllers from class MyButton
// MyButton extends Controller and inherits all methods accordingly.
new MyButton(cp5, "b1").setPosition(0, 0).setSize(180, 200).moveTo(g2);
new MyButton(cp5, "b2").setPosition(205, 15).setSize(180, 200);
}
void draw() {
background(0);
}
// b1 will be called from Controller b1
public void b1(float theValue) {
println("yay button "+theValue);
}
public void controlEvent(ControlEvent theEvent) {
println("controlEvent : "+theEvent);
}
// Create a custom Controller, please not that
// MyButton extends Controller,
// is an indicator for the super class about the type of
// custom controller to be created.
class MyButton extends Controller {
int current = 0xffff0000;
float a = 128;
float na;
int y;
// use the convenience constructor of super class Controller
// MyButton will automatically registered and move to the
// default controlP5 tab.
MyButton(ControlP5 cp5, String theName) {
super(cp5, theName);
// replace the default view with a custom view.
setView(new ControllerView() {
public void display(PApplet p, Object b) {
// draw button background
na += (a-na) * 0.1;
p.fill(current,na);
p.rect(0, 0, getWidth(), getHeight());
// draw horizontal line which can be moved on the x-axis
// using the scroll wheel.
p.fill(0,255,0);
p.rect(0,y,width,10);
// draw the custom label
p.fill(128);
translate(0,getHeight()+14);
p.text(getName(),0,0);
p.text(getName(),0,0);
}
}
);
}
// override various input methods for mouse input control
void onEnter() {
cursor(HAND);
println("enter");
a = 255;
}
void onScroll(int n) {
println("scrolling");
y -= n;
y = constrain(y,0,getHeight()-10);
}
void onPress() {
println("press");
current = 0xffffff00;
}
void onClick() {
Pointer p1 = getPointer();
println("clicked at "+p1.x()+", "+p1.y());
current = 0xffffff00;
setValue(y);
}
void onRelease() {
println("release");
current = 0xffffffff;
}
void onMove() {
println("moving "+this+" "+_myControlWindow.getMouseOverList());
}
void onDrag() {
current = 0xff0000ff;
Pointer p1 = getPointer();
float dif = dist(p1.px(),p1.py(),p1.x(),p1.y());
println("dragging at "+p1.x()+", "+p1.y()+" "+dif);
}
void onReleaseOutside() {
onLeave();
}
void onLeave() {
println("leave");
cursor(ARROW);
a = 128;
}
}
public T activateEvent(boolean theFlag)
theFlag
- booleanTab
public T addListener(ControlListener theListener)
addListener
in interface ControllerInterface<T>
addListener
in class ControllerGroup<T>
theListener
- ControlListenerControlListener
public void controlEvent(ControlEvent theEvent)
ControlListener
controlEvent
in interface ControlListener
controlEvent
in class ControllerGroup<T>
theEvent
- ControlEventCallbackListener
,
CallbackEvent
public int getBackgroundHeight()
public int getBarHeight()
public java.lang.String getInfo()
getInfo
in class ControllerGroup<T>
public int listenerSize()
listenerSize
in class ControllerGroup<T>
public void mousePressed()
public T removeListener(ControlListener theListener)
removeListener
in class ControllerGroup<T>
theListener
- ControlListenerControlListener
public T setBackgroundColor(int theColor)
theColor
- public T setBackgroundHeight(int theHeight)
theHeight
- public T setBarHeight(int theHeight)
theHeight
- public T setSize(int theWidth, int theHeight)
setSize
in class ControllerGroup<T>
public java.lang.String stringValue()
stringValue
in interface ControllerInterface<T>
stringValue
in class ControllerGroup<T>
public java.lang.String toString()
toString
in class ControllerGroup<T>
public T updateInternalEvents(processing.core.PApplet theApplet)
ControllerInterface
updateInternalEvents
in interface ControllerInterface<T>
updateInternalEvents
in class ControllerGroup<T>
processing library controlP5 by Andreas Schlegel. (c) 2006-2014