class Scrollbar { int x, y; float sw, sh; float pos; float posMin, posMax; boolean rollover; boolean locked; float minVal, maxVal; Scrollbar(int xp, int yp, int w, int h, float miv, float mav){ x = xp; y = yp; sw = w; sh = h; minVal = miv; maxVal = mav; pos = x + sw/2 - sh/2; posMin = x; posMax = x + sw - sh; } //Updates over the boolean and the position of the thumb void update(int mx, int my) { if (over(mx, my) == true) { rollover = true; } else { rollover = false; } if (locked == true) { pos = constrain(mx-sh/2, posMin, posMax); } } //locks the thumb so the mouse can move off and still update void press(int mx, int my) { if (rollover == true) { locked = true; } else { locked = false; } } //resets the scrollbar to neutral void release() { locked = false; } //returns true if the cursor is over the scrollbar boolean over(int mx, int my) { if ((mx > x) && (mx < x+sw) && (my > y) && (my < y+sh)) { return true; } else { return false; } } //draws the scrollbar to the screen void display() { stroke(155); fill(255); rect(x, y, sw, sh); if ((rollover == true) || (locked == true)) { fill(0); } else { fill(155); } stroke(155); fill(225); rect(pos, y, sh, sh); line(x, 412, (sw+x), 412); //line(x, 319, (sw+x), 319); } // Returns the current value of the thumb float getPos() { float scalar = sw/(sw-sh); float ratio = (pos - x) * scalar; float offset = minVal + (ratio/sw * (maxVal-minVal)); return offset; } }