boolean overRect(float x, float y, float width, float height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } // simple button class class Button { PVector pos; String msg; boolean locked; Button(PVector p, String m) { pos = p; msg = m; locked = false; } Button(float x, float y, String m) { pos = new PVector(x,y); msg = m; locked = false; } boolean update() { stroke(0); if (locked) fill(0,200,0); else fill(255); boolean over = overRect(pos.x-2, pos.y-textAscent()-2, textWidth(msg)+4, textDescent()+textAscent()+4); if (!locked && !mousePressed && over) { fill(255,255,0); } rect(pos.x-2, pos.y-textAscent()-2, textWidth(msg)+4, textDescent()+textAscent()+4); fill(0); text(msg, pos.x, pos.y); boolean toRet = false; if (locked && !mousePressed) { if (over) { toRet = true; } locked = false; } else if (mousePressed && over) { locked = true; } return toRet; } }