You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.6 KiB
74 lines
1.6 KiB
class Position {
|
|
int id;
|
|
float posX, posY; // position
|
|
color bgColor, textColor; // couleur du fond et du texte
|
|
boolean hovered, dragged = false; // état au survol et en déplacement
|
|
float radius; // rayon du pion
|
|
PVector offset;
|
|
|
|
Position(int id) {
|
|
this.id = id;
|
|
this.bgColor = color(255);
|
|
this.textColor = color(0);
|
|
this.radius = 60;
|
|
}
|
|
|
|
void draw() {
|
|
color bgColor = this.getBgColor();
|
|
color textColor = this.getTextColor();
|
|
|
|
stroke(bgColor);
|
|
strokeWeight(0.5);
|
|
fill(bgColor);
|
|
float radius = this.radius;
|
|
circle(this.posX,this.posY,radius);
|
|
|
|
fill(textColor);
|
|
float textSize = radius/3*2;
|
|
textSize(textSize);
|
|
textFont(quicksandFont, textSize);
|
|
|
|
float pos_x = this.id<9? this.posX-radius/5: this.posX-radius/3;
|
|
text(this.id+1, pos_x, this.posY+radius/5+1);
|
|
}
|
|
|
|
color getBgColor() {
|
|
return this.dragged? color(255,255,255,100): this.hovered? this.textColor: this.bgColor;
|
|
}
|
|
|
|
color getTextColor() {
|
|
return this.dragged? color(0): this.hovered? this.bgColor: this.textColor;
|
|
}
|
|
|
|
int getScore() {
|
|
return this.id+1;
|
|
}
|
|
|
|
void setBgColor(color bgColor) {
|
|
this.bgColor = bgColor;
|
|
}
|
|
|
|
void setTextColor(color textColor) {
|
|
this.textColor = textColor;
|
|
}
|
|
|
|
void dragStart() {
|
|
this.dragged = true;
|
|
// calcul et stockage du décalage au curseur pour éviter l'effet snap
|
|
this.offset = new PVector(posX-mouseX, posY-mouseY);
|
|
}
|
|
|
|
void dragStop() {
|
|
this.dragged = false;
|
|
this.offset = new PVector(0,0);
|
|
}
|
|
|
|
void hoverStart() {
|
|
this.hovered = true;
|
|
}
|
|
|
|
void hoverStop() {
|
|
this.hovered = false;
|
|
}
|
|
}
|