-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyCursor.pde
90 lines (89 loc) · 1.72 KB
/
MyCursor.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
class MyCursor{
int x,y;
boolean isDragging;
float weight;
int filesize;
boolean showcursor;
boolean isInBorder;
float speed=1.0;
File draggingFile;
MyCursor(){
x=100;
y=100;
weight=1.0;
filesize=1;
isInBorder=false;
}
void update(Border borders[],File files[]){
for(int i=0;i<3;i++){
if(mousePressed && !isDragging){
if(files[i].cursorIn(this)){
files[i].isdragged=true;
files[i].offsetX=files[i].x-x;
files[i].offsetY=files[i].y-y;
isDragging=true;
filesize=files[i].dataSize;
}
}else if(!mousePressed){
files[i].isdragged=false;
isDragging=false;
}
}
isInBorder=false;
for(int i=0;i<2;i++){
if(borders[i].cursorIn(this)){
weight=borders[i].weight;
isInBorder=true;
}
}
int dx=0,dy=0;
if(showcursor){
dx=mouseX-pmouseX;
dy=mouseY-pmouseY;
}else{
dx=mouseX-500;
dy=mouseY-500;
}
if(isInBorder && isDragging){
speed=weight*(1.0/filesize);
}else{
speed=1.0;
}
x+=dx*speed;
y+=dy*speed;
if(x<0){
x=0;
}else if(width<=x){
x=width-1;
}
if(y<0){
y=0;
}else if(height<=y){
y=height-1;
}
}
void render(){
if(showcursor){
cursor();
}else{
noCursor();
}
if(mousePressed && isDragging){
fill(0);
stroke(#0000FF);
}else if(mousePressed){
fill(0);
stroke(#FF0000);
}else{
fill(0);
stroke(#000000);
}
strokeWeight(3);
line(x,y,x+20,y);
line(x,y,x,y+20);
line(x,y,x+30,y+30);
ellipse(x,y,5,5);
textSize(48);
text("Speed:"+str(speed),900,0,1000,100);
}
}