|
0 |
function launch(prefix, containerId) {
|
|
1 |
var deps = [
|
|
2 |
"element-factory.js",
|
|
3 |
"animation.js",
|
|
4 |
"sprite-manager.js",
|
|
5 |
];
|
|
6 |
var loaded = 0;
|
|
7 |
for (var i = 0; i < deps.length; i++) {
|
|
8 |
var elem = document.createElement('script');
|
|
9 |
elem.src = prefix + deps[i];
|
|
10 |
elem.onload = function() {
|
|
11 |
if (++loaded == deps.length) {
|
|
12 |
var container = document.getElementById(containerId);
|
|
13 |
var t = new TheFrame();
|
|
14 |
var instructions = yoob.makeParagraph(container,
|
|
15 |
"<small>Note 1. Green things can be dragged. " +
|
|
16 |
"Note 2. Due to technical limitations, " +
|
|
17 |
"things cannot be dragged off of the computer screen</small>"
|
|
18 |
);
|
|
19 |
var canvas = yoob.makeCanvas(container, 800, 450);
|
|
20 |
canvas.style.display = "block";
|
|
21 |
canvas.width = document.documentElement.clientWidth - canvas.offsetLeft * 2;
|
|
22 |
//canvas.height = document.documentElement.clientHeight - canvas.offsetTop - 5;
|
|
23 |
var pleaseWait = yoob.makeParagraph(container,
|
|
24 |
"Please wait, loading..."
|
|
25 |
);
|
|
26 |
// PREFIXME
|
|
27 |
t.init(canvas, 'the-frame.png', function() {
|
|
28 |
pleaseWait.style.display = "none";
|
|
29 |
});
|
|
30 |
}
|
|
31 |
};
|
|
32 |
document.body.appendChild(elem);
|
|
33 |
}
|
|
34 |
}
|
|
35 |
|
0 | 36 |
Corner = function() {
|
1 | |
this.isDraggable = true;
|
2 | |
this.draw = function(ctx) {
|
3 | |
ctx.fillStyle = "green";
|
4 | |
ctx.fillRect(this.x, this.y, this.w, this.h);
|
5 | |
};
|
|
37 |
this.isDraggable = true;
|
|
38 |
this.draw = function(ctx) {
|
|
39 |
ctx.fillStyle = "green";
|
|
40 |
ctx.fillRect(this.x, this.y, this.w, this.h);
|
|
41 |
};
|
6 | 42 |
};
|
7 | |
Corner.prototype = new yoob.Sprite();
|
8 | 43 |
|
9 | 44 |
TheFrame = function() {
|
10 | 45 |
var request;
|
|
80 | 115 |
};
|
81 | 116 |
|
82 | 117 |
this.init = function(c, imgUrl, callback) {
|
83 | |
canvas = c;
|
84 | |
ctx = canvas.getContext("2d");
|
85 | |
manager.init(canvas);
|
86 | |
var mkHandle = function(x, y, w, h) {
|
87 | |
var d = new Corner();
|
88 | |
d.init(x, y, w, h);
|
89 | |
manager.addSprite(d);
|
90 | |
};
|
91 | |
var $this = this;
|
92 | |
img.onload = function() {
|
93 | |
callback();
|
94 | |
// at this point, canvas.width is OK, so we can:
|
95 | |
mkHandle(30, 30, 30, 30);
|
96 | |
mkHandle(canvas.width - 60, 30, 30, 30);
|
97 | |
mkHandle(canvas.width - 60, canvas.height - 60, 30, 30);
|
98 | |
mkHandle(30, canvas.height - 60, 30, 30);
|
99 | |
getFontHeight();
|
100 | |
$this.draw();
|
101 | |
$this.animation = (new yoob.Animation()).init({
|
102 | |
object: $this
|
103 | |
});
|
104 | |
$this.animation.start();
|
105 | |
}
|
106 | |
img.src = imgUrl;
|
|
118 |
Corner.prototype = new yoob.Sprite();
|
|
119 |
|
|
120 |
canvas = c;
|
|
121 |
ctx = canvas.getContext("2d");
|
|
122 |
manager.init(canvas);
|
|
123 |
var mkHandle = function(x, y, w, h) {
|
|
124 |
var d = new Corner();
|
|
125 |
d.init(x, y, w, h);
|
|
126 |
manager.addSprite(d);
|
|
127 |
};
|
|
128 |
var $this = this;
|
|
129 |
img.onload = function() {
|
|
130 |
callback();
|
|
131 |
// at this point, canvas.width is OK, so we can:
|
|
132 |
mkHandle(30, 30, 30, 30);
|
|
133 |
mkHandle(canvas.width - 60, 30, 30, 30);
|
|
134 |
mkHandle(canvas.width - 60, canvas.height - 60, 30, 30);
|
|
135 |
mkHandle(30, canvas.height - 60, 30, 30);
|
|
136 |
getFontHeight();
|
|
137 |
$this.draw();
|
|
138 |
$this.animation = (new yoob.Animation()).init({
|
|
139 |
object: $this
|
|
140 |
});
|
|
141 |
$this.animation.start();
|
|
142 |
}
|
|
143 |
img.src = imgUrl;
|
107 | 144 |
};
|
108 | 145 |
};
|