class Scrollbar{ int x, y; float sw, sh; float pos; float posMin, posMax; boolean rollover; boolean locked; float minVal; float maxVal; color backgroundColor; color frontColor; color overColor; color clicC; String label; Scrollbar(int xp, int yp, int w, int h, float miv, float mav, String _l, color _bc, color _fc, color _oc){ x = xp; y = yp; sw = w; sh = h; minVal = miv; maxVal = mav; pos = 40; posMin = y+sh-sh; posMax = y; label = _l; backgroundColor = _bc; frontColor = _fc; overColor = _oc; } void update(int mx, int my){ if(over(mx, my) == true){ rollover = true; }else{ rollover = false; } if(locked == true){ pos = -1*(constrain(-1*(y+sh-mouseY), -1*sh, 0)); // pos = -1*(y+sh-mouseY); } } void press(int mx, int my){ if(rollover==true){ locked = true; }else{ locked = false; } } void release(){ locked = false; } boolean over(int mx, int my){ if((mx > x) && (mx < x+sw) && (my > y) && (my < y+sh)){ return true; }else{ return false; } } void display(){ fill(backgroundColor); rect(x, y, sw, sh); // white background. if((rollover==true) || (locked==true)){ fill(overColor); }else{ fill(frontColor); } rect(x, y+sh, sw,-pos); // clicked rectangle float oe = y+sh; } float getPos(){ float offset = map(pos, 0, sh, minVal, maxVal); return offset; } void displayText(){ if((rollover==true) || (locked==true)){ fill(overColor); }else{ fill(frontColor); } textFont(font, 14); textAlign(CENTER); text(round(getPos()), x+(sw/2), (y+sh)-pos); text(label, x+(sw/2), y+sh+15); } }