151 lines
3.9 KiB
Plaintext
151 lines
3.9 KiB
Plaintext
class HScrollbar {
|
|
int swidth, sheight; // width and height of bar
|
|
float xpos, ypos; // x and y position of bar
|
|
float spos, newspos; // x position of timeline
|
|
float sposMin, sposMax; // max and min values of timeline
|
|
int loose; // how loose/heavy
|
|
boolean over, over_play; // is the mouse over the timeline?
|
|
boolean locked;
|
|
boolean play = true;
|
|
boolean timeLineHover;
|
|
boolean jumpBool;
|
|
float ratio;
|
|
float playspeed = 0.001;
|
|
// window_w/8, window_h-(window_h/8), window_w-2*(window_w/8), window_h/20, 1
|
|
HScrollbar (float xp, float yp, int sw, int sh, int l) {
|
|
swidth = sw;
|
|
sheight = sh;
|
|
int widthtoheight = sw - sh;
|
|
ratio = (float)sw / (float)widthtoheight;
|
|
xpos = xp;
|
|
ypos = yp;
|
|
spos = xpos;
|
|
newspos = spos;
|
|
sposMin = xpos;
|
|
sposMax = xpos + swidth - sheight/10;
|
|
loose = 2;
|
|
}
|
|
|
|
void update() {
|
|
|
|
if (overEvent()) {
|
|
over = true;
|
|
} else {
|
|
over = false;
|
|
}
|
|
if (mousePressed && over && !map_click) {
|
|
locked = true;
|
|
}
|
|
if (!mousePressed) {
|
|
locked = false;
|
|
}
|
|
if (locked) {
|
|
newspos = constrain(mouseX-sheight/20, sposMin, sposMax);
|
|
}
|
|
if (abs(newspos - spos) > 1) {
|
|
spos = spos + (newspos-spos)/loose;
|
|
}
|
|
if (overEvent_play()) {
|
|
over_play = true;
|
|
} else {
|
|
over_play = false;
|
|
}
|
|
if (play) {
|
|
if(spos < xpos+swidth-sheight/10){
|
|
newspos += playspeed;
|
|
spos += playspeed;
|
|
}
|
|
}
|
|
if (mouseY >= 1080/scaleAmount){
|
|
timeLineHover = true;
|
|
} else {
|
|
timeLineHover = false;
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
float constrain(float val, float minv, float maxv) {
|
|
return min(max(val, minv), maxv);
|
|
}
|
|
|
|
boolean overEvent() {
|
|
if (mouseX > xpos && mouseX < xpos+swidth &&
|
|
mouseY > ypos && mouseY < ypos+sheight) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
boolean overEvent_play() {
|
|
if (mouseX > xpos-1.5*sheight && mouseX < xpos-0.5*sheight &&
|
|
mouseY > ypos && mouseY < ypos+sheight) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void display() {
|
|
// pushMatrix();
|
|
// noStroke();
|
|
// fill(52,60,79,229);
|
|
// rect(0,1326/scaleAmount,window_w,114/scaleAmount);
|
|
stroke(127,127,127);
|
|
fill(#FFFFFF,25.5);
|
|
rect(-2,1079.75/scaleAmount,window_w+2,246.25/scaleAmount);
|
|
|
|
noStroke();
|
|
fill(102);
|
|
rect(xpos, ypos+sheight/2-sheight/15, swidth, sheight/10); //timeline?
|
|
triangle(xpos+swidth, ypos+sheight/5, xpos+swidth, ypos+4*sheight/5, xpos+swidth*1.05, ypos+sheight/2); //pfeil
|
|
|
|
// rect(xpos-sheight*1.5, ypos, sheight,sheight);
|
|
|
|
noFill();
|
|
strokeWeight(2/scaleAmount);
|
|
stroke(#FFFFFF);
|
|
rect(spos+2, ypos, 138/scaleAmount, 112/scaleAmount); //timeline?
|
|
|
|
|
|
// for(int i = yearMin; i < yearMax; i += 200){ //stoppel auf timeline
|
|
// fill(102);
|
|
// rect(map(i,yearMin,yearMax,sposMin,sposMax),ypos+sheight/4,sheight/10,sheight/2);
|
|
// if(i < 0){
|
|
// textSize(window_h/50);
|
|
// text(abs(i) + "B.C.", map(i,yearMin,yearMax,sposMin,sposMax)-sheight/2,ypos+sheight*1.5);
|
|
// } else if (i > 0){
|
|
// textSize(window_h/50);
|
|
// text(abs(i) + "N.C.", map(i,yearMin,yearMax,sposMin,sposMax)-sheight/2,ypos+sheight*1.5);
|
|
// } else {
|
|
// textSize(window_h/50);
|
|
// text(abs(i), map(i,yearMin,yearMax,sposMin,sposMax)-sheight/10,ypos+sheight*1.5);
|
|
// }
|
|
// }
|
|
|
|
if (over_play) {
|
|
fill(0);
|
|
} else {
|
|
fill(102);
|
|
}
|
|
if (play) {
|
|
rect(xpos-sheight*1.5+sheight/5, ypos+sheight/5, sheight/5, sheight-2*sheight/5);
|
|
rect(xpos-sheight*1.5+3*sheight/5, ypos+sheight/5, sheight/5, sheight-2*sheight/5);
|
|
} else {
|
|
triangle(xpos-sheight*1.5+sheight/5, ypos+sheight/5, xpos-sheight*1.5+sheight/5, ypos+4*sheight/5, xpos-sheight*0.65, ypos+sheight/2);
|
|
}
|
|
|
|
|
|
// popMatrix();
|
|
|
|
}
|
|
|
|
float getPos() {
|
|
return spos * ratio;
|
|
}
|
|
}
|