We are about to switch to a new forum software. Until then we have removed the registration on this forum.
From a previous processing thread, I can now make a vertical scrollbar. I want to make the slider start from the beginning through instead of the end.
class Scrollbar
{
int swidth, sheight; // width and height of bar
int xpos, ypos; // x and y position of bar
float spos, newspos; // x position of slider
int sposMin, sposMax; // max and min values of slider
int loose; // how loose/heavy
boolean over; // is the mouse over the slider?
boolean locked;
float ratio;
Scrollbar (int xp, int yp, int sw, int sh, int l) {
swidth = sw;
sheight = sh;
int heighttowidth = sh - sw;
ratio = (float)sh / (float)heighttowidth;
xpos = xp-swidth/2;
ypos = yp;
spos = ypos + sheight/2 - swidth/2;
newspos = spos;
sposMin = ypos;
sposMax = ypos + sheight - swidth;
loose = l;
}
void resizeScrollbar(int xp, int yp, int sw, int sh)
{
this.xpos = xp - swidth/2;
this.ypos = yp;
this.swidth = sw;
this.sheight = sh;
}
void update() {
if (over()) {
over = true;
} else {
over = false;
}
if (mousePressed && over) {
locked = true;
}
if (!mousePressed) {
locked = false;
}
if (locked) {
newspos = constrain(mouseY-swidth/2, sposMin, sposMax);
}
if (abs(newspos - spos) > 1) {
spos = spos + (newspos-spos)/loose;
}
}
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(220);
rect(xpos, ypos, swidth, sheight);
if (over || locked) {
fill(80);
} else {
fill(190);
}
rect(xpos, spos, swidth, swidth);
}
float getPos() {
// Convert spos to be values between
// 0 and the total width of the scrollbar
return spos * ratio;
}
}
Answers
i figured it out by changin spos to ypos
http://forum.processing.org/two/discussion/11731/can-anybody-show-me-how-to-create-a-vertical-scrollbar