-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zoom.pde
executable file
·57 lines (49 loc) · 1.41 KB
/
Zoom.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//Zoom function
void mouseWheel(MouseEvent event) {
float e = event.getAmount();
//Zoom in
if(e == -1){
if(scale < 8
){
scale++;
imgH = int(imgH*(1+zoomFactor));
imgW = int(imgW*(1+zoomFactor));
int oldCenterX = centerX;
int oldCenterY = centerY;
centerX = centerX - int(zoomFactor*(mouseX - centerX));
centerY = centerY - int(zoomFactor*(mouseY - centerY));
//Calcuate the distance to center of the campus image
for(int i=0; i<lines.length-1; i=i+2){
lines[i] = int((lines[i] - oldCenterX)*(1+zoomFactor)
+ centerX);
lines[i+1] = int((lines[i+1] - oldCenterY)*(1+zoomFactor)
+ centerY);
}
}
}
//Zoom out
if(e == 1){
if(scale < 1){
scale = 1;
}
if(scale > 1
//¢erX <= imgW/2
){
scale--;
imgH = int(imgH/(1+zoomFactor));
imgW = int(imgW/(1+zoomFactor));
int oldCenterX = centerX;
int oldCenterY = centerY;
centerX = centerX + int((mouseX - centerX)
*(zoomFactor/(zoomFactor + 1)));
centerY = centerY + int((mouseY - centerY)
*(zoomFactor/(zoomFactor + 1)));
for(int i=0; i<lines.length-1; i=i+2){
lines[i] = int((lines[i] - oldCenterX)/(1+zoomFactor)
+ centerX);
lines[i+1] = int((lines[i+1] - oldCenterY)/(1+zoomFactor)
+ centerY);
}
}
}
}