We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Scrollbar what’s the best way
Page Index Toggle Pages: 1
Scrollbar what’s the best way? (Read 605 times)
Scrollbar what’s the best way?
Feb 27th, 2006, 8:44am
 
Hi,

I am looking for a Vertical scroll bar. I have found the example of a horizontal one here but it seems a bit complex for a scrollbar; are there any other methods for scrolling objects? In my case I need to scroll 1000's of objects all at once.

Thanks,

4dplane
Re: Scrollbar what’s the best way?
Reply #1 - Feb 27th, 2006, 11:27am
 
Why not just apply a transform matrix on all your objects to "scroll" them?

Yeah. I know you're talking about vertical scroll bars. But at the end you seem to be asking something else entirely.

Just need clarification..
Re: Scrollbar what’s the best way?
Reply #2 - Feb 27th, 2006, 1:57pm
 
An easy thing to do is make a slider (vertical or horizontal) and apply transformation from the value of the slider.

-seltar
Re: Scrollbar what’s the best way?
Reply #3 - Feb 27th, 2006, 10:39pm
 
To clarify, I will have a thousand drawn rects on screen and I will need to scroll them up and down. I could just make the rects smaller to see them all on stage at once but I would like to be able to view each rect at (20, 20) which means I will need to scroll up higher to view the other squares.

It seems the two of you are saying I should look into the transform matrix and/or slider bars that modify the transformation values?

Thanks,

4dplane

Re: Scrollbar what’s the best way?
Reply #4 - Feb 28th, 2006, 12:41am
 
here's a really fast hack towards a solution. Rather than use a matrix transform, I just set up a parent node (it seemed simpler.)
Code:

//simple scrolling
float handleX;
float handleY;
float handleW = 20;
float handleH = 15;
boolean isDraggable = false;
int handleFill = 150;
int windowWidth;

// rects fill
int rectCount = 500;
float[]rectX = new float[rectCount];
float[]rectY = new float[rectCount];
color[]rectColor = new color[rectCount];

float parentNodeX, parentNodeY;
void setup(){
size(200, 200);
windowWidth = width-22;
handleX = width-21;
handleY = height/2-handleH/2;
parentNodeX = windowWidth/2;
parentNodeY = height/2;

for (int i=0; i<rectCount; i++){
rectX[i] = random(-windowWidth/2, windowWidth/2-50);
rectY[i] = random(-500, 500);
rectColor[i] = color(random(255), random(255), random(255));
}
}

void draw(){
background(255);
//window decorations
stroke(0);
fill(255);
rect(0, 0, width-1, height-1);
fill(200);
rect(windowWidth, 0, width-2, height-2);

// draw window content
for (int i=0; i<rectCount; i++){
fill(rectColor[i]);
rect(parentNodeX+rectX[i],parentNodeY+rectY[i], 50, 50);
}
//handle
fill(handleFill);
rect(handleX, handleY, handleW, handleH);
if (isDraggable && mouseY>handleH/2 && mouseY<height-handleH/2){
handleY = mouseY-handleH/2;
parentNodeY=(handleY+handleH/2)+(handleY+handleH/2-height/2)*(1000/175);
}
}

void mousePressed(){
if (mouseX>handleX && mouseX<handleX+handleW &&
mouseY>handleY && mouseY<handleY+handleH){
isDraggable = true;
handleFill = color(100, 200, 255);
}
}
void mouseReleased(){
isDraggable = false;
handleFill = 150;
}

void mouseMoved(){
if (mouseX>handleX && mouseX<handleX+handleW &&
mouseY>handleY && mouseY<handleY+handleH){
cursor(HAND);
}
else{
cursor(ARROW);
}
}

Re: Scrollbar what’s the best way?
Reply #5 - Mar 1st, 2006, 6:24am
 
Now that's what I call a HOOK UP! - thanks irag, I could not have written it better myself  

4dplane

*little time later*

I see, you are redrawing the square content over and over again as you scroll - very cool! Now the question is, is it necessary to do this? In the Macromedia Flash world I would draw all the squares in a movieclip and then scroll that movie clip. Very very simple - is there something more like this in processing?  

Thanks!

4dplane
Re: Scrollbar what’s the best way?
Reply #6 - Mar 1st, 2006, 11:19am
 
Nope :]

I see where you're coming from now.

In reality, even Flash draws every frame, over and over. But that part is masked out for you. You don't have to think about it.

However in Processing, you're given more control. In fact, you're handed the task of RENDERING every frame. So, to answer your question, no... there is no other way. To create "animation" in processing, you must draw every frame, over and over.

This is standard practice in computer graphics.
Dang. I'm a rhyming machine.
What's that blinky light?
Oh.. it's just processing....
Re: Scrollbar what’s the best way?
Reply #7 - Mar 1st, 2006, 8:33pm
 
Makes sense, little more work to make it happen but in the end you have much more control.

Thanks for the input!

4dplane
Page Index Toggle Pages: 1