Wondering how to do something with mouseX/mouseY
in
Programming Questions
•
25 days ago
So basically, I'm fairly new to processing and have a question about how to make your mouse location affect various things in the code. I tried an exercise to see if I could do this by changing the appearance of the cursor when the mouse hovers over a button that I made. However, I found that I do not know how to specify whether or not my mouse is inside of the button on both axes. If the button was a square, the workaround that I implemented would be sufficient, although probably amateur. However, since the button is a circle, even if the mouse is just barely outside of the circle but within where the vertices would be on a similar sized square, the cursor changes. How do I tell the program to only execute this code if mouseX and mouseY are inside of button1?
Button button1;
void setup() {
size(800, 800);
smooth();
button1 = new Button(255, width/2, height/2, 100);
}
void draw() {
button1.display();
button1.buttonHover();
}
// Button class
class Button {
color c;
float x, y;
float buttonSize;
Button(color c_, float x_, float y_, float buttonSize_) {
c = c_;
x = x_;
y = y_;
buttonSize = buttonSize_;
}
void display() {
strokeWeight(5);
fill(c);
ellipse(x, y, buttonSize, buttonSize);
}
void buttonHover() {
if(mouseX < 450 && mouseX > 350 && mouseY > 350 && mouseY < 450) {
cursor(HAND);
fill(0,0,255);
ellipse(width/2,height/2,100,100);
}
else cursor(CROSS);
}
}
1