cursor(HAND) not working as expected
in
Programming Questions
•
2 years ago
Hi,
I'm having some trouble with the cursor() function. If you run the code below you will see that the cursor only turns into a hand when rolling over button2. button1 changes colour when you roll over it but the cursor does not change to a hand.
Can anyone tell me if I am doing this wrong? The example is straight out the Processing Hand Book. I just added Cursor (Hand); to the void display() block.
Thanks in Advance,
Dan.
I'm having some trouble with the cursor() function. If you run the code below you will see that the cursor only turns into a hand when rolling over button2. button1 changes colour when you roll over it but the cursor does not change to a hand.
Can anyone tell me if I am doing this wrong? The example is straight out the Processing Hand Book. I just added Cursor (Hand); to the void display() block.
Thanks in Advance,
Dan.
- Button button1, button2;
void setup() {
size(200, 200);
// Inputs: x, y, size,
// base color, over color, press color
button1 = new Button(25, 25, 20,
color(204), color(255), color(0));
button2 = new Button(25, 80, 20,
color(204), color(255), color(0));
}
void draw() {
background(204);
stroke(255);
button1.update();
button1.display();
button2.update();
button2.display();
}
void mousePressed() {
button1.press();
button2.press();
}
void mouseReleased() {
button1.release();
button2.release();
}
class Button {
int x, y; // The x- and y-coordinates
int size; // Dimension (width and height)
color baseGray; // Default gray value
color overGray; // Value when mouse is over the button
color pressGray; // Value when mouse is over and pressed
boolean over = false; // True when the mouse is over
boolean pressed = false; // True when the mouse is over and pressed
Button(int xp, int yp, int s, color b, color o, color p) {
x = xp;
y = yp;
size = s;
baseGray = b;
overGray = o;
pressGray = p;
}
// Updates the over field every frame
void update() {
if ((mouseX >= x) && (mouseX <= x + size) &&
(mouseY >= y) && (mouseY <= y + size)) {
over = true;
} else {
over = false;
}
}
boolean press() {
if (over == true) {
pressed = true;
return true;
} else {
return false;
}
}
void release() {
pressed = false; // Set to false when the mouse is released
}
void display() {
if (pressed == true) {
fill(pressGray);
} else if (over == true) {
fill(overGray);
cursor(HAND);
} else {
fill(baseGray);
cursor(ARROW);
}
stroke(255);
rect(x, y, size, size);
}
}
1