import controlP5.*;
ControlP5 cp5;
int myColorBackground = color(0,0,0);
RadioButton r1, r2;
void setup() {
size(700,400);
cp5 = new ControlP5(this);
r1 = cp5.addRadioButton("radioButton")
.setPosition(100,180)
.setSize(40,20)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.setItemsPerRow(5)
.setSpacingColumn(50)
.addItem("50",1)
.addItem("100",2)
.addItem("150",3)
.addItem("200",4)
.addItem("250",5)
;
for(Toggle t:r1.getItems()) {
t.getCaptionLabel().setColorBackground(color(255,80));
t.getCaptionLabel().getStyle().moveMargin(-7,0,0,-3);
t.getCaptionLabel().getStyle().movePadding(7,0,0,3);//???
t.getCaptionLabel().getStyle().backgroundWidth = 45;
t.getCaptionLabel().getStyle().backgroundHeight = 13;
}
}
void draw() {
background(myColorBackground);
}
void keyPressed() {
switch(key) {
case('0'): r1.deactivateAll(); break;
case('1'): r1.activate(0); break;
case('2'): r1.activate(1); break;
case('3'): r1.activate(2); break;
case('4'): r1.activate(3); break;
case('5'): r1.activate(4); break;
}
}
void controlEvent(ControlEvent theEvent) {
if(theEvent.isFrom(r1)) {
print("got an event from "+theEvent.getName()+"\t");
for(int i=0;i<theEvent.getGroup().getArrayValue().length;i++) {
print(int(theEvent.getGroup().getArrayValue()[i]));
}
println("\t "+theEvent.getValue());
myColorBackground = color(int(theEvent.getGroup().getValue()*50),0,0);
}
}
void radioButton(int a) {
println("a radio Button event: "+a);
}
[processing学习]-07-radioButtom
最新推荐文章于 2024-04-16 22:48:36 发布