class Box{ Box parent; float width, height; float top, left, right, bottom; Box (Box parent, float width, float height){ this(parent, width, height, 0, 0); } Box (Box parent, float width, float height, float offsetLeft, float offsetTop){ this.width = width; this.height = height; //top = ( parent.height - this.height ) /2 + offsetTop; //left = ( parent.width - this.width ) /2 + offsetLeft; top = parent.top + offsetTop; left = parent.left + offsetLeft; bottom = top + this.height; right = left + this.width; } Box (PApplet parent, float width, float height){ this(parent, width, height, 0, 0); } Box (PApplet parent, float width, float height, float offsetLeft, float offsetTop){ this.width = width; this.height = height; //top = ( parent.height - this.height ) /2 + offsetTop; //left = ( parent.width - this.width ) /2 + offsetLeft; top = offsetTop; left = offsetLeft; bottom = top + this.height; right = left + this.width; } boolean containsPoint(float x, float y){ return x >= left && x < right && y >= top && y < bottom; } boolean containsMouse(){ return containsPoint(mouseX,mouseY); } } void rect(Box b){ rect(b.left, b.top, b.width, b.height); } // text in box centered void text(String s, Box b){ float numberWidth = textWidth(s); float numberHeight = textAscent()+textDescent(); float numberX = b.left + (b.width - numberWidth)/2; float numberY = b.top + (b.height - numberHeight)/2 + textAscent(); text(s, numberX, numberY); }