1 package org.catacomb.graph.gui;
2
3
4
5
6 final class RollHandler extends MouseHandler {
7
8 private int xc;
9 private int yc;
10
11 private double rcx = Double.NaN;
12 private double rcy = Double.NaN;
13 private double rcz = Double.NaN;
14
15
16
17
18 final static int NORMAL = 0;
19 final static int SIMPLE = 1;
20
21 int actionMode = NORMAL;
22
23 boolean aaCache;
24
25
26
27 public RollHandler() {
28
29 }
30
31
32 public void init(Mouse m) {
33 xc = m.getX();
34 yc = m.getY();
35
36 if (actionMode == SIMPLE) {
37 if (m.leftButton()) {
38 setClaimIn();
39
40 } else {
41 setClaimOut();
42 }
43
44
45
46 } else if (m.rightButton()) {
47
48
49 }
50 }
51
52 public void advance(Mouse m) {
53 if (actionMode == NORMAL && m.leftButton()) {
54
55 int dx = m.getX() - xc;
56 int dy = m.getY() - yc;
57
58 if (dx * dx + dy * dy > 100) {
59
60 setClaimIn();
61 applyOnDown(m);
62 }
63 }
64 }
65
66
67 public void activate() {
68 actionMode = NORMAL;
69 super.activate();
70 }
71
72
73
74 public void simpleActivate() {
75 activate();
76 actionMode = SIMPLE;
77 }
78
79
80 public void setRollCenter(double x, double y, double z) {
81 rcx = x;
82 rcy = y;
83 rcz = z;
84 }
85
86
87
88 public void applyOnDown(Mouse m) {
89 if (Double.isNaN(rcx)) {
90 m.initializeRotation(m.getX(), m.getY());
91
92 } else {
93 m.initializeRotation(rcx, rcy, rcz);
94 }
95 }
96
97 public void applyOnDrag(Mouse m) {
98 int x = m.getX();
99 int y = m.getY();
100
101 m.dragRollRotate(x - xc, y - yc);
102 setFullRepaint();
103 }
104
105
106
107 public void applyOnRelease(Mouse m) {
108 m.restoreAA();
109
110
111
112 }
113
114 }
115
116