-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds-Canvas-Positionmanager.js
57 lines (50 loc) · 1.21 KB
/
ds-Canvas-Positionmanager.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
(function (root, global, Backbone, _, $, undefined) {
var ScrollManager = root.ScrollManager,
ScaleManager = root.ScaleManager,
pageOffset = {top: 0, left: 0},
Canvas = root.Canvas,
containerOffset = $(".ds-canvas").offset();
//root.demand("Sizemanager")
root.SizeManager.on("change", function () {
containerOffset = $(".ds-canvas").offset();
})
Canvas.on("setup", function (e) {
pageOffset = {
top: e.pageStartY,
left: e.pageStartX
}
}, this);
var PositionManager = {
cursorToPagecoords: function (x,y) {
var scaleX = ScaleManager.get("scaleX"),
scaleY = ScaleManager.get("scaleY"),
scrollLeft = ScrollManager.get("scrollLeft"),
scrollTop = ScrollManager.get("scrollTop");
if (typeof x !== "number") {
x = parseFloat(x);
}
if (typeof y !== "number") {
y = parseFloat(y);
}
x -= containerOffset.left || 0,
y -= containerOffset.top || 0;
if (ScrollManager) {
x += scrollLeft;
y += scrollTop;
}
if (ScaleManager) {
x /= scaleX;
y /= scaleY;
}
x -= pageOffset.left;
y -= pageOffset.top;
return {
pageX: x,
pageY: y
}
}
};
root.supply({
"PositionManager": PositionManager
})
})(ds, this, Backbone, _, jQuery);