-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslation.js-e
95 lines (84 loc) · 2.32 KB
/
translation.js-e
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
## Copyright (c) 2015, Empirical Modelling Group
## All rights reserved.
##
## See LICENSE.txt
${{
Translation = function (centreX, centreY, x, y, items) {
this.centreX = centreX;
this.centreY = centreY;
this.x = x;
this.y = y;
this.items = items;
}
Translation.prototype = new EdenUI.plugins.Canvas2D.Transform;
Translation.prototype.transform = function (context) {
context.translate(this.x - this.centreX, this.y - this.centreY);
}
Translation.prototype.getCSS = function (scale) {
var x = (this.x - this.centreX) * scale;
var y = (this.y - this.centreY) * scale;
return "translate(" + x + "px, " + y + "px)";
}
Translation.prototype.inverse = function (x, y) {
return new Point(x - (this.x - this.centreX), y - (this.y - this.centreY));
}
Translation.prototype.toString = function () {
return "Translate(" + Eden.edenCodeForValues(this.centreX, this.centreY, this.x, this.y, this.items) + ")";
}
Translation.prototype.getEdenCode = Translation.prototype.toString;
}}$;
func Translate {
${{
var centreX, centreY, x, y, items;
var argNum = arguments.length - 1;
if (argNum == 0) {
eden.error(new Error("Translate: This function requires at least 2 arguments."), "error");
return undefined;
}
items = arguments[argNum];
argNum--;
arg = arguments[argNum];
if (arg instanceof Point) {
x = arg.x;
y = arg.y;
argNum--;
} else if (argNum >= 1) {
y = arg;
argNum--;
x = arguments[argNum];
argNum--;
}
if (argNum >= 0) {
arg = arguments[argNum];
if (arg instanceof Point) {
centreX = arg.x;
centreY = arg.y;
argNum--;
} else if (argNum >= 1) {
centreY = arg;
argNum--;
centreX = arguments[argNum];
argNum--;
}
}
if (argNum >= 0) {
eden.error(new Error("Translate: invalid parameters."), "error");
return undefined;
}
if (typeof(x) !== "number") {
eden.error(new Error("Translate: The destination X coordinate must be a number, not a " + typeof(x)), "error");
return undefined;
}
if (typeof(y) !== "number") {
eden.error(new Error("Translate: The destination Y coordinate must be a number, not a " + typeof(y)), "error");
return undefined;
}
if (centreX === undefined) {
centreX = 0;
}
if (centreY === undefined) {
centreY = 0;
}
return new Translation(centreX, centreY, x, y, items);
}}$;
}