You declare an ImageScroller in the format
new
ImageScroller(image, x, y, width, height).To use Image Scroller, there's some prerequisites you have to fulfill.
- First, you have to make the ImageScroller wide enough to include the width of the image, and the scrollbar.
- Second, your
draw()function must include a call tosc.drawImage()at the end. - Third, your
mouseReleased()function must include the following lines of code at the beginning of the function:
if(sc.mouseReleased(mouseX, mouseY))
{
redraw();
return;
} - Another point to note: if you are going to use measurements
based on
widthandheight, you'll have to initialize the ImageScroller in the draw function. The example below, which you can see in operation here, does this.
ImageScroller sc = null;
void setup()
{
//...
}
void draw()
{
//this code will place the image-scroller at the
bottom right of the screen
PImage im = loadImage("YourImageGoesHere.gif");
//how many pixels to put to the right and below
the image
int spacer = 10;
//note the use of ImageScroller.SCROLLBAR_WIDTH to
set the right width \/ \/
sc = (sc == null ? new ImageScroller(im, width -
(im.width + spacer + ImageScroller.SCROLLBAR_WIDTH),
height - (im.height + spacer), (im.width +
ImageScroller.SCROLLBAR_WIDTH), 200) : sc);
//...
sc.drawImage();
}
void mouseReleased()
{
if(sc.mouseReleased(mouseX,
mouseY))
{
redraw();
return;
}
//...
}
You can download the ImageScroller pde file for use in your own projects here.
