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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
package NET.worlds.scape;
import NET.worlds.console.Console;
import NET.worlds.console.DialogDisabled;
import NET.worlds.console.ExposedPanel;
import NET.worlds.console.Main;
import NET.worlds.console.MainCallback;
import NET.worlds.console.Window;
import java.awt.Color;
import java.awt.FlowLayout;
import java.util.Enumeration;
import java.util.Vector;
class ToolBar extends ExposedPanel implements MainCallback, DialogDisabled {
private Vector buttons = new Vector();
private WidgetButton active;
private boolean activeDown;
private WidgetButton entered;
private WObject curWObj;
private boolean haveDelta = false;
private WObjectHighlighter highlight;
private boolean initialDrag;
private boolean isDialogDisabled;
private boolean testConstrained;
private boolean constrainToX;
private boolean constrainToY;
private int cumx;
private int cumy;
private float motionDivisor = 1.0F;
private static final int constrainThresh = 5;
public ToolBar() {
this.setLayout(new FlowLayout(0, 1, 1));
this.addButton(new HTransWidget(this));
this.addButton(new VTransWidget(this));
this.addButton(new PitchWidget(this));
this.addButton(new RollWidget(this));
this.addButton(new YawWidget(this));
this.addButton(new ScaleWidget(this));
this.addButton(new CutWidget(this));
this.addButton(new CopyWidget(this));
this.addButton(new PasteWidget(this));
this.addButton(new SaveWidget(this));
this.addButton(new UndoWidget(this));
this.setBackground(Color.lightGray);
}
public void done() {
if (this.highlight != null) {
this.highlight.stop();
}
}
private void addButton(WidgetButton button) {
this.add(button);
this.buttons.addElement(button);
}
public void setCurrentObject(Object obj) {
this.curWObj = obj instanceof WObject ? (WObject)obj : null;
if (this.highlight != null) {
this.highlight.stop();
this.highlight = null;
}
if (this.curWObj != null) {
this.highlight = new WObjectHighlighter(this.curWObj);
}
Enumeration e = this.buttons.elements();
this.clearPrompt();
while (e.hasMoreElements()) {
((WidgetButton)e.nextElement()).repaint();
}
}
public WObject getCurrentWObject() {
return this.curWObj;
}
@Override
public void dialogDisable(boolean disable) {
this.isDialogDisabled = disable;
}
@Override
public boolean handleEvent(java.awt.Event event) {
return this.isDialogDisabled ? false : super.handleEvent(event);
}
@Override
public synchronized boolean mouseDown(java.awt.Event event, int x, int y) {
WidgetButton button;
if (event.target instanceof WidgetButton && (event.modifiers & 4) == 0 && this.active == null && (button = (WidgetButton)event.target).available()) {
this.active = button;
this.active.draw(true);
if (this.active.usesDrag()) {
this.initialDrag = true;
this.highlight.stop();
Window.hideCursor();
Main.register(this);
this.haveDelta = true;
} else {
this.activeDown = true;
}
}
return true;
}
@Override
public synchronized boolean mouseDrag(java.awt.Event event, int x, int y) {
if (this.active != null) {
if (this.active.usesDrag()) {
if ((event.modifiers & 1) != 0 && !this.constrainToX && !this.constrainToY) {
this.testConstrained = true;
this.cumx = this.cumy = 0;
}
this.motionDivisor = (event.modifiers & 2) != 0 ? 10.0F : 1.0F;
this.haveDelta = true;
} else {
boolean inside = this.active.getBounds().inside(x, y);
if (inside != this.activeDown) {
this.active.draw(this.activeDown = inside);
}
}
}
return true;
}
@Override
public synchronized void mainCallback() {
if (this.haveDelta && this.active != null) {
int[] pos = Window.getHiddenCursorDelta();
if (this.testConstrained) {
this.cumx = this.cumx + pos[0];
this.cumy = this.cumy + pos[1];
int acumx = Math.abs(this.cumx);
int acumy = Math.abs(this.cumy);
if (acumx > acumy + 5) {
this.constrainToX = true;
} else {
if (acumy <= acumx + 5) {
return;
}
this.constrainToY = true;
}
this.testConstrained = false;
}
if (this.constrainToX) {
pos[0] += this.cumx;
this.cumx = 0;
pos[1] = 0;
} else if (this.constrainToY) {
pos[1] += this.cumy;
this.cumy = 0;
pos[0] = 0;
}
this.setPrompt(this.active.drag(this.initialDrag, pos[0] / this.motionDivisor, -pos[1] / this.motionDivisor));
this.initialDrag = false;
this.haveDelta = false;
}
}
@Override
public synchronized boolean mouseUp(java.awt.Event event, int x, int y) {
if (this.active != null) {
this.active.draw(false);
boolean needUpdate = true;
if (this.active.usesDrag()) {
this.highlight.start();
Main.unregister(this);
} else if (this.activeDown) {
this.active.perform();
this.activeDown = false;
} else {
needUpdate = false;
}
this.active = null;
if (needUpdate) {
Console.getFrame().getEditTile().update();
}
}
return true;
}
@Override
public boolean mouseEnter(java.awt.Event event, int x, int y) {
WidgetButton button;
if (this.active == null && event.target instanceof WidgetButton && (button = (WidgetButton)event.target).available()) {
this.entered = button;
this.setPrompt(this.entered.getPrompt());
}
return true;
}
@Override
public boolean mouseMove(java.awt.Event event, int x, int y) {
return this.mouseEnter(event, x, y);
}
@Override
public synchronized boolean keyUp(java.awt.Event event, int key) {
if ((event.modifiers & 1) == 0) {
this.testConstrained = this.constrainToX = this.constrainToY = false;
}
return true;
}
public void setPrompt(String prompt) {
Console.getFrame().getEditTile().setPrompt(prompt);
}
private void clearPrompt() {
this.entered = null;
Console.getFrame().getEditTile().setPrompt(null);
}
@Override
public boolean mouseExit(java.awt.Event event, int x, int y) {
if (this.active == null && event.target == this.entered) {
this.clearPrompt();
}
return true;
}
}
|