Created
July 30, 2018 21:18
-
-
Save vampjaz/73c516b9a28efd209878f6af0f7327a1 to your computer and use it in GitHub Desktop.
A nice scrollbar implementation for Processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ScrollBar { | |
float x,y,w,h; | |
float min,max,val; | |
String name; | |
ScrollBar(float xp, float yp, float sw, float sh, float lo, float hi, float v, String n) { | |
x=xp; | |
y=yp; | |
w=sw; | |
h=sh; | |
min=lo; | |
max=hi; | |
val=v; | |
name=n; | |
} | |
void run() { | |
float tempval = map(mouseX - x,0,w,min,max); | |
boolean mouseover = mouseX > x && mouseY > y && mouseX < x+w && mouseY < y+h; | |
if (mousePressed && mouseover) { | |
val = tempval; | |
} | |
float computed = x + map(val,min,max,0,w); | |
float tempcomputed = 0; | |
if (mouseover) {tempcomputed = x + map(tempval,min,max,0,w);} | |
noStroke(); | |
fill(60); | |
rect(x,y,w,h); | |
strokeWeight(2); | |
stroke(255,255,0); | |
line(computed,y,computed,y+h); | |
if (mouseover) { | |
stroke(0,255,255); | |
line(tempcomputed,y,tempcomputed,y+h); | |
fill(255,0,0); | |
text(name+" - "+val+" ("+tempval+")",x+10,y+12); | |
} else { | |
fill(255,0,0); | |
text(name+" - "+val,x+10,y+12); | |
} | |
} | |
float getVal() { | |
return val; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment