class HScrollbar { //PROPERTIES int swidth, sheight; // gršsse des balkens int xpos, ypos; // position des balkens float spos, newspos; // x position des reglers int sposMin, sposMax; // max und min wert des reglers float s; // Schrittgršsse boolean over; // ist die maus Ÿber dem regler boolean locked; //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //CONSTRUCTOR HScrollbar (int xp, int yp, int sw, int sh,int s) { this.s=s; swidth = sw; sheight = sh; xpos = xp; ypos = yp-sheight/2; spos = xpos + swidth/2 - sheight/2; newspos = spos; sposMin = xpos; sposMax = xpos + swidth - sheight; } //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //METHODES void update() { if(over()) { over = true; } else { over = false; } if(mousePressed && over) { locked = true; } if(!mousePressed) { locked = false; } if(locked) { newspos = constrain(mouseX-sheight/2, sposMin, sposMax); } if(abs(newspos - spos) > 1) { spos = spos + (newspos-spos); } } //--------------------------------------------------------------------------------------------------------- int constrain(int val, int minv, int maxv) { return min(max(val, minv), maxv); } //--------------------------------------------------------------------------------------------------------- boolean over() { if(mouseX > xpos && mouseX < xpos+swidth && mouseY > ypos && mouseY < ypos+sheight) { return true; } else { return false; } } //--------------------------------------------------------------------------------------------------------- void display() { fill(255); rect(xpos, ypos, swidth, sheight); if(over || locked) { fill(153, 102, 0); } else { fill(102, 102, 102); } rect(spos, ypos, sheight, sheight); } //--------------------------------------------------------------------------------------------------------- float getPos() { return round (spos-xpos+1)*s; } //--------------------------------------------------------------------------------------------------------- }