-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.js
More file actions
99 lines (84 loc) · 1.95 KB
/
Controller.js
File metadata and controls
99 lines (84 loc) · 1.95 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
nodes = [];
contents = {};
mouseDelta = new Vector(0, 0);
mousePosition = new Vector(0, 0);
rawMousePosition = new Vector(0, 0);
var mouseDown = [0, 0, 0, 0, 0, 0, 0, 0, 0],
mouseDownCount = 0;
pan = new Vector(0, 0);
zoom = 1;
activeTool = null;
function clearCanvas()
{
//canvas[0].width = canvas[0].width;
ctx.clearRect(0, 0, canvas[0].clientWidth, canvas[0].clientHeight);
}
function repaint()
{
clearCanvas();
for (let node of nodes)
{
node.paint();
}
}
function applyZoomAndPan(point)
{
return point.multiply(zoom).add(pan);
}
function applyZoom(number)
{
return number * zoom;
}
drekec = function() {
canvas.click(function() {
if (activeTool != null)
{
activeTool.use();
}
repaint();
});
canvas.mousemove(function(e) {
var rmp = canvas[0].getBoundingClientRect();
rmp = new Vector(e.pageX - rmp.left, e.pageY - rmp.top);
mouseDelta = rmp.subtract(rawMousePosition);
rawMousePosition = rmp;
var pos = rmp.subtract(pan);
pos = pos.divide(zoom);
mousePosition = pos;
if (mouseDownCount && mouseDown[1])
{
pan = pan.add(mouseDelta);
repaint();
}
});
$(window).bind('mousewheel DOMMouseScroll', function(event){
if (event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0) {
zoom *= 1.1;
}
else {
zoom /= 1.1;
}
repaint();
});
canvas[0].onmousedown = function(evt) {
++mouseDown[evt.button];
++mouseDownCount;
if (mouseDown[evt.button] < 0 || mouseDown[evt.button] > 1)
{
mouseDown[evt.button] = 0;
}
}
canvas[0].onmouseup = function(evt) {
--mouseDown[evt.button];
--mouseDownCount;
if (mouseDown[evt.button] < 0 || mouseDown[evt.button] > 1)
{
mouseDown[evt.button] = 0;
}
}
$("#clearCanvas").click(clearCanvas);
$("#editTool").click(function() { activeTool = new EditTool(); });
$("#nodeTool").click(function() { activeTool = new NodeTool(); });
$("#connectionTool").click(function() { activeTool = new ConnectionTool(); });
};
startFunctions.push(drekec);