FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Updates to Scrollbar Example for Processing.js · pif/processing@8e1f401 · GitHub

Repository navigation

Commit 8e1f401

Browse files
committed
Updates to Scrollbar Example for Processing.js
1 parent 4dad66d commit 8e1f401

3 files changed

Lines changed: 26 additions & 19 deletions

File tree

‎java/examples/Topics/GUI/Scrollbar/Scrollbar.pde‎

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,49 @@
33
*
44
* Move the scrollbars left and right to change the positions of the images.
55
*/
6-
7-
HScrollbar hs1, hs2;
86

9-
PImage top, bottom; // Two image to load
10-
int topWidth, bottomWidth; // The width of the top and bottom images
117

8+
// The next line is needed if running in JavaScript Mode with Processing.js
9+
/* @pjs preload="seedTop.jpg,seedBottom.jpg"; */
10+
11+
12+
HScrollbar hs1, hs2; // Two scrollbars
13+
PImage img1, img2; // Two image to load
1214

1315
void setup() {
1416
size(640, 360);
1517
noStroke();
16-
hs1 = new HScrollbar(0, height*0.33, width, 20, 3*5+1);
17-
hs2 = new HScrollbar(0, height*0.66, width, 20, 3*5+1);
18-
top = loadImage("seedTop.jpg");
19-
topWidth = top.width;
20-
bottom = loadImage("seedBottom.jpg");
21-
bottomWidth = bottom.width;
18+
19+
hs1 = new HScrollbar(0, height/2-8, width, 16, 16);
20+
hs2 = new HScrollbar(0, height/2+8, width, 16, 16);
21+
22+
// Load images
23+
img1 = loadImage("seedTop.jpg");
24+
img2 = loadImage("seedBottom.jpg");
2225
}
2326

2427
void draw() {
2528
background(255);
2629

27-
// Get the position of the top scrollbar
28-
// and convert to a value to display the top image
29-
float topPos = hs1.getPos()-width/2;
30+
// Get the position of the img1 scrollbar
31+
// and convert to a value to display the img1 image
32+
float img1Pos = hs1.getPos()-width/2;
3033
fill(255);
31-
image(top, width/2-topWidth/2 + topPos*2, 0);
34+
image(img1, width/2-img1.width/2 + img1Pos*1.5, 0);
3235

33-
// Get the position of the bottom scrollbar
34-
// and convert to a value to display the bottom image
35-
float bottomPos = hs2.getPos()-width/2;
36+
// Get the position of the img2 scrollbar
37+
// and convert to a value to display the img2 image
38+
float img2Pos = hs2.getPos()-width/2;
3639
fill(255);
37-
image(bottom, width/2-bottomWidth/2 + bottomPos*2, height/2);
40+
image(img2, width/2-img2.width/2 + img2Pos*1.5, height/2);
3841

3942
hs1.update();
4043
hs2.update();
4144
hs1.display();
4245
hs2.display();
46+
47+
stroke(0);
48+
line(0, height/2, width, height/2);
4349
}
4450

4551

@@ -93,14 +99,15 @@ class HScrollbar {
9399

94100
boolean overEvent() {
95101
if(mouseX > xpos && mouseX < xpos+swidth &&
96-
mouseY > ypos && mouseY < ypos+sheight) {
102+
mouseY > ypos && mouseY < ypos+sheight) {
97103
return true;
98104
} else {
99105
return false;
100106
}
101107
}
102108

103109
void display() {
110+
noStroke();
104111
fill(204);
105112
rect(xpos, ypos, swidth, sheight);
106113
if(over || locked) {
11.4 KB
LoadingViewer requires iframe.
20.7 KB
LoadingViewer requires iframe.

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL