-
Notifications
You must be signed in to change notification settings - Fork 822
/
boundary.js
124 lines (110 loc) · 3.17 KB
/
boundary.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright (c) 2016-2020 Walter Bender
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the The GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// You should have received a copy of the GNU Affero General Public
// License along with this library; if not, write to the Free Software
// Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
// The trashcan is an area at the bottom of the screen where stacks of
// blocks can be dragged. Once in the trash area, they are marked as
// trash and hidden. There is a menu button that can be used to
// restore trash.
/*
global createjs, BOUNDARY
*/
/* exported Boundary */
class Boundary {
/**
* @constructor
* @param {Object} stage
*/
constructor(stage) {
this._container = new createjs.Container();
this._stage = stage;
this._stage.addChild(this._container);
this._stage.setChildIndex(this._container, 0);
}
// resizeEvent(scale) {};
/**
* @public
* @param {number} w
* @param {number} h
* @param {number} scale
* @returns {void}
*/
setScale(w, h, scale) {
this.destroy();
this.create(w, h, scale);
}
/**
* @public
* @returns {void}
*/
destroy() {
if (this._container.children.length > 0) {
this._container.removeChild(this._container.children[0]);
}
}
/**
* @public
* @param {number} x
* @param {number} y
* @returns {number}
*/
offScreen(x, y) {
return x < this.x || x > this.x + this.dx || y < this.y || y > this.y + this.dy;
}
/**
* @public
* @param {number} w
* @param {number} h
* @param {number} scale
* @returns {void}
*/
create(w, h, scale) {
this.w = w / scale;
this.x = 55 + 13;
this.dx = this.w - (110 + 26);
this.h = h / scale;
this.y = 55 + 13;
this.dy = this.h - (55 + 26);
const __makeBoundary = () => {
const img = new Image();
img.onload = () => {
const bitmap = new createjs.Bitmap(img);
this._container.addChild(bitmap);
};
img.src =
"data:image/svg+xml;base64," +
window.btoa(
base64Encode(
BOUNDARY.replace("HEIGHT", this.h)
.replace("WIDTH", this.w)
.replace("Y", this.y)
.replace("X", this.x)
.replace("DY", this.dy)
.replace("DX", this.dx)
.replace("stroke_color", "#e08080")
)
);
};
__makeBoundary();
}
/**
* @public
* @returns {void}
*/
hide() {
this._container.visible = false;
}
/**
* @public
* @returns {void}
*/
show() {
this._container.visible = true;
}
}