-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSelectionTool.js
67 lines (59 loc) · 1.8 KB
/
SelectionTool.js
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
/*
* SelectionTool
*
*/
function SelectionTool(canvas) {
if (canvas) {
this.canvas = canvas;
} else {
throw new Error('ArgumentError');
}
this.selectedHandle = null;
}
SelectionTool.prototype = new Tool();
SelectionTool.prototype.mousedown = function(oEvent) {
var selectedFigures = this.canvas.getSelectedFigures();
this.selectedHandle = null;
for (var i = 0; selectedFigures[i]; i++) {
if((this.selectedHandle = selectedFigures[i].handleAtPoint(this.mouseOffset(oEvent)))) {
break;
}
}
if (this.selectedHandle) {
this.canvas.htmlCanvas.addEventListener('mousemove', this.mousemove, false);
} else {
var doRepaint = false;
for (var i = 0; selectedFigures[i]; i++) {
selectedFigures[i].setSelected(false);
doRepaint = true;
}
figure = this.canvas.figureAtPoint(this.mouseOffset(oEvent));
if (figure) {
figure.setSelected(true);
doRepaint = true;
}
if (doRepaint) {
this.canvas.repaint();
}
}
};
SelectionTool.prototype.mouseup = function(oEvent) {
if (this.selectedHandle) {
this.selectedHandle = null;
this.canvas.htmlCanvas.removeEventListener('mousemove', this.mousemove, false);
}
};
// this is messy and needs to be refactored
SelectionTool.prototype.mousemove = function(oEvent) {
// if method called from utside of the object context then
// get selection tool and recall method on a object
if (! this.canvas) {
tool = sl.canvas.getTool();
tool.mousemove(oEvent);
} else {
if (this.selectedHandle) {
this.selectedHandle.setLocation(this.mouseOffset(oEvent));
this.canvas.repaint();
}
}
};