Repository navigation
Expand file tree
/
Copy pathMouseController.java
More file actions
87 lines (73 loc) · 2.09 KB
/
Copy pathMouseController.java
File metadata and controls
87 lines (73 loc) · 2.09 KB
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
public class MouseController{
private Application app;
private int mouseLastPressedButton=0;
private long mouseLastPressMillis=0;
private int mouseLastX=0;
private int mouseLastY=0;
private float mouseResolutionSlide = 30f;
private float mouseResolutionRotate = 0.8f;
private float mouseResolutionZoom = 0.8f;
public MouseController(Application app){
this.app=app;
}
public void mousePressed(int mouseX,int mouseY,int mouseButton) {
if(app.layers[app.currentLayer]!=null){
mouseLastPressedButton=mouseButton;
mouseLastX=mouseX;
mouseLastY=mouseY;
mouseLastPressMillis=System.currentTimeMillis();
}
}
public void mouseClicked(int mouseX,int mouseY,int mouseButton) {
}
public void mouseReleased(int mouseX,int mouseY,int mouseButton) {
LayerNineBlockPattern p = null;
if(app.layers[app.currentLayer] instanceof LayerNineBlockPattern){
p = ((LayerNineBlockPattern)app.layers[app.currentLayer]);
}
if(p!=null){
int x=mouseX-mouseLastX;
int y=mouseY-mouseLastY;
long time=System.currentTimeMillis()-mouseLastPressMillis;
if(x*x>25 || y*y>25){
switch(mouseLastPressedButton){
case 37:
p.scrollX.tcIncPerSec=
(float) ((Math.cos(p.angle.v())*(float)x
+Math.sin(p.angle.v())*(float)y)
*mouseResolutionSlide/(float)time);
p.scrollY.tcIncPerSec=
(float) ((-Math.sin(p.angle.v())*(float)(x)
+Math.cos(p.angle.v())*(float)(y))
* mouseResolutionSlide/(float)(time));
p.scrollX.tc=true;
p.scrollY.tc=true;
break;
case 39:
int way=1;//(mouseY>height/2)?-1:1;
p.angle.tcIncPerSec=way*(float)(x)*mouseResolutionRotate/(float)(time);
p.angle.tc=true;
break;
case 3:
p.zoom.tcIncPerSec=(float)(y)*mouseResolutionZoom/(float)(time);
p.zoom.tc=true;
break;
}
}else{
switch(mouseLastPressedButton){
case 37:
p.scrollX.tc=!p.scrollX.tc;
p.scrollY.tc=!p.scrollY.tc;
break;
case 39:
p.angle.tc=!p.angle.tc;
break;
case 3:
p.zoom.tc=!p.zoom.tc;
break;
}
}
mouseLastPressedButton=0;
}
}
}