I am facing issues with deleting 2D primitives. I attempted to create a rectangle in front of these primitives to conceal them. However, I need to hide them when clicking somewhere, which leads me to believe that the draw()
function is overriding the mouseclicked
.
In my code snippet, "maFenetre" represents what I intend to hide/delete.
float windowHeight = 700;
float windowBar = 50;
float xIcon = 80;
float x = random(0, 500);
float y = random(0, 800);
color red = #FF0000;
color white = #FFFFFF;
void setup() {
size(1500, 1500);
background(#C1C1C1);
}
void rectangle(){
rect((x + windowWidth) - xIcon, y, xIcon, windowBar);
}
void maFenetre(){
//window
noStroke();
fill(#89E0FF);
rectMode(CORNER);
rect(x, y, windowWidth, windowHeight);
//crossbar
rectMode(CORNER);
fill(white);
noStroke();
rect(x, y, windowWidth, windowBar);
if ((mouseX >= (x + windowWidth) - xIcon && mouseX <= x + windowWidth) && (mouseY >= y && mouseY <= y + windowBar)) {
fill(red);
rectangle();
}
//expand bar
if ((mouseX >= (x + windowWidth) - xIcon * 2 && mouseX <= (x + windowWidth) - xIcon) && (mouseY >= y && mouseY <= y + windowBar)) {
fill(#CEDDDE);
noStroke();
rect((x + windowWidth) - xIcon * 2, y, xIcon, windowBar);
}
//shrink bar
if ((mouseX >= (x + windowWidth) - xIcon * 3 && mouseX <= (x + windowWidth) - xIcon * 2) && (mouseY >= y && mouseY <= y + windowBar)) {
fill(#CEDDDE);
noStroke();
rect((x + windowWidth) - xIcon * 3, y, xIcon, windowBar);
}
//shrink icon
stroke(#000000);
strokeWeight(2);
line((x + windowWidth) - xIcon * 2.65, y + windowBar/2,(x + windowWidth) - xIcon * 2.35, y + windowBar/2);
//expand icon
stroke(#000000);
strokeWeight(2);
noFill();
rectMode(CENTER);
rect((x + windowWidth) - xIcon * 1.5, y + windowBar/2, 20, 20);
//close icon
stroke(#030303);
strokeWeight(2.5);
line((x+windowWidth)-xIcon*0.62,y+windowBar*0.35,(x+windowWidth)-xIcon*0.38,y+windowBar*0.75);
line((x+windowWidth)-xIcon*0.62,y+windowBar*0.75,(x+windowWidth)-xIcon*0.38,y+windowBar*0.35);
}
void draw() {
maFenetre();
}
void mouseReleased(){
if (mousePressed == ((mouseX >= (x + windowWidth) - xIcon && mouseX <= x + windowWidth) && (mouseY >= y && mouseY <= y + windowBar))){
}
else{
noStroke();
rectMode(CORNER);
fill(#C1C1C1);
rect(x-1, y-1, windowWidth+2, windowHeight+2);
}
}