class Button { int x, y; int w, h; color basecolor, highlightcolor; color currentcolor; boolean over = false; boolean pressed = false; int data = 0; void pressed() { if(over && mousePressed) { pressed = true; action(); } else { pressed = false; } } 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; } } void action(){} } class ImageButton extends Button { PImage base; PImage roll; PImage down; PImage currentimage; ImageButton (){} // Creates image button // e.g. btn = MakeButton("base.gif", "roll.gif", "down.gif", widht/2, height/2); ImageButton (String baseFile, String rollFile, String downFile, int x, int y, int onPressData ){ PImage b = loadImage(baseFile); PImage r = loadImage(rollFile); PImage d = loadImage(downFile); data = onPressData; x = x - b.width/2; y = y - b.height/2; int w = b.width; int h = b.height; _ImageButton(x, y, w, h, b, r, d); } void _ImageButton(int ix, int iy, int iw, int ih, PImage ibase, PImage iroll, PImage idown) { x = ix; y = iy; w = iw; h = ih; base = ibase; roll = iroll; down = idown; currentimage = base; } void draw(){ update(); display(); } void update() { over(); pressed(); if(pressed) { currentimage = down; } else if (over){ currentimage = roll; } else { currentimage = base; } } void over() { if( overRect(x, y, w, h) ) { over = true; } else { over = false; } } void display() { image(currentimage, x, y); } }