在下面的代码中,我尝试使用显示的图像创建 3 个按比例缩放的按钮。发生的问题是,当鼠标悬停在按钮上并且按钮按下事件不起作用时,按钮不会改变颜色。如果我将按钮的大小设置为固定值而不是变量的值,则一切正常。有谁知道为什么会发生这种情况或我如何以其他方式实现缩放?
这是我的代码:
import controlP5.*;
ControlP5 cp5;
int bg = color(255, 255, 255);
int bSX, bPY;
Button BrTP;
class playground extends Canvas {
int c1 = color(105, 130, 157);
int c2 = color(117, 144, 174);
PImage img = loadImage("bg.png");
void setup(PApplet a) {
}
void draw(PGraphics g) {
g.image(img, 10, 10, img.width, img.height);
}
}
void setup() {
size(400, 400);
noStroke();
surface.setResizable(false);
cp5 = new ControlP5(this);
playground canv = new playground();
canv.pre();
surface.setSize(canv.img.width+20, canv.img.height+80);
surface.setLocation((displayWidth - canv.img.width-20) / 2, (displayHeight - 65 - canv.img.height-80) / 2);
cp5.addCanvas(canv);
bSX = (canv.img.width - 20) / 3; // buttonSizeX
bPY = canv.img.height + 20; // buttonPositionY
BrTP = cp5.addButton("randomTP").setValue(0).setPosition(10, bPY).setSize(bSX, 50);
cp5.addButton("safeTP").setPosition(20 + (canv.img.width - 20) / 3, canv.img.height + 20).setSize(bSX, 50);
cp5.addButton("wait").setPosition(30 + 2 * (canv.img.width - 20) / 3, canv.img.height + 20).setSize(bSX, 50);
}
void draw() {}
public void controlEvent(ControlEvent e) {
println(e.getController().getName());
}
public void randomTP(int val) {
println("rTP:"+val);
}