class Buttons{ int x,y,w,h,col; String label; PImage pic; Buttons(int x, int y, int w, int h, int col, String label, PImage pic){ this.x = x; this.y = y; this.w = w; this.h = h; this.col = col; this.label = label; this.pic = pic; } void draw(){ stroke(0); fill(0); int xup,yup; if(over()){ if(mousePressed){ xup = x-1; yup = y-1; } else{ xup = x-4; yup = y-4; } } else{ xup = x; yup = y; } rect(x,y,w,h); if(pic == null){ fill(col); rect(xup,yup,w,h); } else{ image(pic,xup,yup,w,h); } if (label.length() > 0){ if (pic == null) fill(0); else fill(col); text(label,xup+2,yup+18); } } boolean over(){ if (mouseX <= x+w && mouseX >= x && mouseY <= y+h && mouseY >= y){ return true; } else{ return false; } } } class Slider{ int x,y,w,h,c1,c2; float xpos,xmin,xmax,xbar; String label,overlabel; boolean locked = false; Slider(int x, int y, int w, int h, int c1, int c2, String label, float xmin, float xmax, float xpos){ this.x = x; this.y = y; this.w = w; this.h = h; this.c1 = c1; this.c2 = c2; this.label = label; overlabel = str(xpos); this.xmin = xmin; this.xmax = xmax; this.xpos = xpos; xbar = ((float)w / (xmax-xmin)) * xpos; } void draw(){ stroke(0); int xup = (int)xbar; int yup = y; if(over()){ xup = (int)xbar-2; yup = y-2; } if(locked){ xup = (int)xbar-1; yup = y-1; } fill(c1); rect(x,y,w,h); fill(0); rect(x+xbar-2,y-1,5,h+2); fill(c2); rect(x+xup-2,yup-1,5,h+2); if (label.length() > 0){ fill(0); if(locked) text(overlabel,x+2,y+18); else text(label,x+2,y+18); } } void update(){ if (over() && mousePressed){ locked = true; } if (locked){ xbar = constrain(mouseX - x,0,w); xpos = ((xmax-xmin) / w) * xbar; overlabel = str(xpos); } if (!mousePressed){ locked = false; } } boolean over(){ if (mouseX <= x+w && mouseX >= x && mouseY <= y+h && mouseY >= y){ return true; } else{ return 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; } }