-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouseKeyboardHandler.pde
More file actions
177 lines (149 loc) · 4.79 KB
/
MouseKeyboardHandler.pde
File metadata and controls
177 lines (149 loc) · 4.79 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
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
/*
* Copyright (c) 2010 The Jackson Laboratory
*
* This software was developed by Matt Hibbs' Lab at The Jackson
* Laboratory (see http://cbfg.jax.org/).
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/
void keyPressed(java.awt.event.KeyEvent event) { // most key events are handled by the MenuBar
if (key == ESC) {
if (!ENABLE_KINECT) {
exiting = !exiting;
key = 0; // nullify the key, preventing Processing from closing automatically
}
// if Kinect version, exit
}
if (exiting) {
yes.keyAction(key, keyCode, event.getModifiersEx());
no.keyAction(key, keyCode, event.getModifiersEx());
} else {
texts.keyAction(key, keyCode, event.getModifiersEx());
}
}
void keyReleased(java.awt.event.
KeyEvent event) {
if (! exiting && tabs.active && tabs.focus) {
tabs.keyAction(key, keyCode, event.getModifiersEx());
}
}
void mousePressed() {
if (mouseX > 10 && mouseX < 95 && mouseY < menuY + drawHeight && mouseY > menuY + drawHeight - 20 && !exiting && !dragging) {
menuTargetY = (menuY == 0.0) ? -100.0 : 0.0;
tabs.focus = (menuY == 0.0);
}
if (!ENABLE_KINECT && !exiting && !dragging && mouseX > fileTree.x + fileTree.cWidth && mouseX < tabs.x && mouseY > fileTree.y && mouseY < drawHeight + menuTargetY && (mouseX < legendX || mouseX > legendX + legendW || mouseY < legendY || mouseY > legendY + legendH)) {
if (tabsXTarget == 110) {
tabsXTarget = 335;
} else {
tabsXTarget = 110;
}
} else if (exiting) {
yes.mouseAction();
no.mouseAction();
} else if (mouseY < drawHeight + menuTargetY && (mouseX < legendX || mouseX > legendX + legendW || mouseY < legendY || mouseY > legendY + legendH)) {
tabs.mouseAction();
} else {
texts.mouseAction();
}
}
void mouseMoved() {
if (!exiting && !dragging) {
tabs.mouseAction();
texts.mouseAction();
} else {
yes.mouseAction();
no.mouseAction();
}
}
void mouseReleased() {
if (!exiting && !dragging) {
tabs.mouseAction();
texts.mouseAction();
} else {
yes.mouseAction();
no.mouseAction();
}
}
boolean mouseInRect(Object o, float x1, float y1, float x2, float y2) {
if (mouseLock != -1 && mouseLock != o.hashCode()) {
return false;
}
if (exiting || users == null) {
return false;
}
for (int i = 0; i < users.size(); i++) {
PVector mouse = users.get(i).cursorPos;
if (mouse.x > x1 && mouse.x < x2 && mouse.y > y1 && mouse.y < y2) {
return true;
}
}
if (ENABLE_KINECT_SIMULATE && mouseX > x1 && mouseX < x2 && mouseY > y1 && mouseY < y2) {
return true;
}
return false;
}
boolean mousePressedInRect(Object o, float x1, float y1, float x2, float y2) {
if (mouseLock != -1 && mouseLock != o.hashCode()) {
return false;
}
if (exiting || users == null) {
return false;
}
for (int i = 0; i < users.size(); i++) {
PVector mouse = users.get(i).cursorPos;
if (mouse.x > x1 && mouse.x < x2 && mouse.y > y1 && mouse.y < y2 && users.get(i).pressed) {
return true;
}
}
if (ENABLE_KINECT_SIMULATE && mousePressed && mouseButton == LEFT && mouseX > x1 && mouseX < x2 && mouseY > y1 && mouseY < y2) {
return true;
}
return false;
}
boolean killMouseEvents(Object o) {
if (mouseLock != -1 && mouseLock != o.hashCode()) {
return false;
}
for (int i = 0; i < users.size(); i++) {
users.get(i).pressed = false;
}
return true;
}
void killMouseEvents() {
for (int i = 0; i < users.size(); i++) {
users.get(i).pressed = false;
users.get(i).righthandDown = -1;
users.get(i).ready = false;
}
}
boolean lockMouse(Object o) {
if (mouseLock == -1 || mouseLock == o.hashCode()) {
mouseLock = o.hashCode();
return true;
} else {
return false;
}
}
boolean freeMouse(Object o) {
if (mouseLock == -1 || mouseLock == o.hashCode()) {
mouseLock = -1;
return true;
} else {
return false;
}
}
void freeMouse() {
mouseLock = -1;
}