У меня есть этот пользовательский класс Button
, который расширяет PGraphics
, но я не могу понять, как заставить его работать, функция draw
просто ничего не делает, я проверил пиксели и до sketch(this, x, y);
, все пиксели равны 0
: мышление:
public abstract class Button extends PGraphics {
private final int color;
private final int clickedColor;
private final int x;
private final int width;
private final int height;
private final int y;
private String text = "";
private boolean clicked = false;
protected final Main sketch;
public Button(Main sketch, final int x, final int y, final int width, final int height) {
this.sketch = sketch;
this.x = x;
this.width = width;
this.height = height;
this.y = y;
color = this.color(200f);
clickedColor = this.color(100f);
setSize(getWidth(), getHeight());
setParent(sketch);
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public abstract void onClick();
public void draw() {
beginDraw();
if (clicked) {
background(clickedColor);
} else {
background(color);
}
stroke(color(0f));
strokeWeight(4f);
text(text,
(x + width) / 2f - text.length() * textSize,
(y + height) / 2f - text.length() * textSize);
endDraw();
loadPixels();
// Here, all the pixels are equals to '0' :/
sketch.image(this, x, y);
}
public void mouseEvent(MouseEvent event) {
switch (event.getAction()) {
case MouseEvent.PRESS:
clicked = true;
break;
case MouseEvent.RELEASE:
clicked = false;
break;
default:
throw new IllegalStateException("Unexpected value: " + event.getAction());
}
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public boolean isClicked() {
return clicked;
}
public void setClicked(final boolean clicked) {
this.clicked = clicked;
}
}
Так как заставить это работать?