// lifted from Casey Reas and Ben Fry, 'Processing,' // chapter 7, code example 47-05. class Button { int x, y, wide, high; // The x- and y-coordinates and sizes 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 wd, int hg, color b, color o, color p) { x = xp; y = yp; wide = wd; high = hg; baseGray = b; overGray = o; pressGray = p; } // Updates the over field every frame void update() { if ((mouseX >= x) && (mouseX <= x + wide) && (mouseY >= y) && (mouseY <= y + high)) { 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); } else { fill(baseGray); } stroke(255); rect(x, y, wide, high); } }