well, I scribbled together a small "solution" with phi.lhos advice.
Now left scrollbar is for textposition and right scrollbar for allowed text height (try moving the right bar up).
But I guess that's not what the poor guy wants...
He rather wants a fixed box and scroll the data within... I guess.
I haven't done that, probably you would have to manipulate start and end of
- for (int j = 0; j<dataSubSet.size(); j++) {
instead of text();
Greetings, Chrisir
- VScrollbar vs1, vs2;
- int offset = 0;
- String[] dataSubSet = {
- "This", "will", "probably", "take", "literally", "ages", "to", "figure", "out", "again.",
- "This", "will", "probably", "take", "literally", "ages", "to", "figure", "out", "again.",
- "This", "will", "probably", "take", "literally", "ages", "to", "figure", "out", "again.",
- "This", "will", "probably", "take", "literally", "ages", "to", "figure", "out", "again."
- };
- //
- void setup()
- {
- size(900, 900);
- noStroke();
- vs1 = new VScrollbar(10, 0, 20, height, 3*5+1);
- vs2 = new VScrollbar(width-10, 0, 20, height, 3*5+1);
- }
- void draw()
- {
- background(255);
- // Get the position of the left scrollbar
- // and convert to a value to display the text (pos X)
- float offset = vs1.getPos()-height+550;
- fill(255);
- // Get the position of the right scrollbar
- // and convert to a value to display the allowed height of the text rect
- float AllowedHeight = vs2.getPos()-width/2 + 255;
- fill(255);
- println ("offset " + offset+"; AllowedHeight: "+ AllowedHeight);
- int y= 20;
- int allowedHeight = 70 ;
- String myString="";
- for (int j = 0; j<dataSubSet.length-4; j+=4) {
- myString= myString
- +j
- +dataSubSet[j]+" "
- +dataSubSet[j+1]+" "
- +dataSubSet[j+2]+" "
- +dataSubSet[j+3]
- +"\n";
- }
- fill(0);
- // using text(stringdata, x, y, width, height)
- text(myString, 30, y+offset, screen.width, AllowedHeight );
- vs1.update();
- vs2.update();
- vs1.display();
- vs2.display();
- }
- // ================================================
- class VScrollbar
- {
- 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;
- VScrollbar (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 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(255);
- rect(xpos, ypos, swidth, sheight);
- if (over || locked) {
- fill(255, 255, 0);
- }
- else {
- fill(255, 0, 0);
- }
- rect(xpos, spos, swidth, swidth);
- }
- float getPos() {
- // Convert spos to be values between
- // 0 and the total width of the scrollbar
- return spos * ratio;
- }
- }