-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgesture_recognizer.js
More file actions
53 lines (41 loc) · 1.22 KB
/
gesture_recognizer.js
File metadata and controls
53 lines (41 loc) · 1.22 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
GestureRecognizer = function() {
this.onMouseMove = new Event();
this.onMouseLeftDown = new Event();
this.onMouseRightDown = new Event();
this.onMouseRelease = new Event();
this.onMouseDrag = new Event();
this.onMouseDblClick = new Event();
this.lastClick = null;
}
GestureRecognizer.prototype.handleMouseDblClick = function(mousePos) {
this.onMouseDblClick.notify(new Point(mousePos.x, mousePos.y));
}
GestureRecognizer.prototype.handleMouseMove = function(mousePos) {
// TODO: handle gesture here
if (this.lastClick) {
this.onMouseDrag.notify(
{
"beginPoint": this.lastClick,
"endPoint": new Point(mousePos.x, mousePos.y)
});
}
else {
this.onMouseMove.notify({"point": new Point(mousePos.x, mousePos.y)});
}
}
GestureRecognizer.prototype.handleMouseDown = function(mousePos, isRightButton) {
// TODO: handle gesture here
var point = new Point(mousePos.x, mousePos.y);
if (isRightButton) {
this.onMouseRightDown.notify(point);
}
else {
this.onMouseLeftDown.notify(point);
this.lastClick = point;
}
}
GestureRecognizer.prototype.handleMouseRelease = function(mousePos) {
// TODO: handle gesture here
this.onMouseRelease.notify(new Point(mousePos.x, mousePos.y));
this.lastClick = null;
}