// Button class by Casey Reas and Ben Fry class Button{ int x, y; int w, h; color baseGray; color overGray; color pressGray; color labelGray; color labelOverColor; boolean over = false; boolean pressed = false; String label; // xPosition, yPosition, width, height, backgroundColor, HoverColor, ClickColor. Button(int _x, int _y, int _w, int _h, color _b, color _o, color _p){ x = _x; y = _y; w = _w; h = _h; baseGray = _b; overGray = _o; pressGray = _p; label = ""; } // xPosition, yPosition, width, height, backgroundColor, HoverColor, ClickColor, Label. Button(int _x, int _y, int _w, int _h, color _b, color _o, color _p, String _l, color _lc, color _loc){ x = _x; y = _y; w = _w; h = _h; baseGray = _b; overGray = _o; pressGray = _p; label = _l; labelGray = _lc; labelOverColor = _loc; } // Updates the over field every frame void update(){ if((mouseX >= x) && (mouseX <= x+w) && (mouseY >= y) && (mouseY <= y+h)){ 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); } // noStroke(); rect(x, y, w, h); if(over==true){ fill(labelOverColor); }else{ fill(labelGray); } if(label == "play"){ beginShape(TRIANGLES); vertex(x+10, y+5); vertex(x+w-10, y+(h/2)); vertex(x+10, y+h-5); endShape(); }else if(label == "pause"){ rect(x+9, y+5, 5, h-10); rect(x+15, y+5, 5, h-10); }else{ textAlign(CENTER, CENTER); text(label, x+w/2, y+h/2); } } }