// extend version from processing examples public class Button { int x, y; color basecolor, highlightcolor; color currentcolor, checkedcolor; boolean over = false; boolean pressed = false; boolean checked = false; void update() { if(over()) { currentcolor = highlightcolor; } else if (checked) currentcolor = checkedcolor; else { currentcolor = basecolor; } } void setChecked(color c, boolean checked) { } boolean pressed() { if(over) { return true; } else { return false; } } boolean over() { return true; } void display() { } } public class RectTextButton extends Button { PFont font; int w; int h; int sz; String t; color checkCol; RectTextButton(int ix, int iy, int iw, int ih, String st, int textSize) { x = ix; y = iy; w = iw; h = ih; basecolor = color (255,255,255); highlightcolor = color (188,188,255); currentcolor = color (255,255,255); font = loadFont ("ArialNarrow.vlw"); sz = textSize; t= st; } boolean over() { if( overRect(x, y, w, h) ) { over = true; return true; } else { over = false; return false; } } void setChecked(color c, boolean bc) { if (checked) checkedcolor = c; checked = bc; } void display() { textFont(font,sz); stroke(0); fill(currentcolor); rect(x, y, w, h); fill (0); textAlign(CENTER); textLeading(sz); text (t,x+w/2, y + h / 2); } boolean overRect(int x, int y, int width, int height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } }