-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainerManager.js
More file actions
91 lines (82 loc) · 2.19 KB
/
containerManager.js
File metadata and controls
91 lines (82 loc) · 2.19 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
class ContainerManager {
constructor(expression, symbolProps){
this.init(expression, symbolProps);
}
init(expression, symbolProps) {
this.symbolProps = symbolProps;
this.arrayInfixContainer = new ArrayContainer(
new Array(...expression),
100,
100,
{
width: 30,
height: 30,
}
);
this.stackContainer = new StackContainer(
new Array(...expression),
this.arrayInfixContainer.x +
this.arrayInfixContainer.width +
this.arrayInfixContainer.padding * expression.length +
symbolProps.width * 3,
0 +
this.symbolProps.height * (expression.length + 4) +
this.arrayInfixContainer.padding * expression.length,
symbolProps
);
this.arrayPostfixContainer = new ArrayContainer(
new Array(...expression),
100,
250,
{
width: 30,
height: 30,
},
false
);
this.ELEMENT = [
...this.arrayInfixContainer.nowElements,
...this.arrayInfixContainer.elementMoved,
];
this.dustbin = new Dustbin(250, 400, 60, 60);
this.dustbin.loadImage("empty_recycle_bin.png");
}
draw(ctx) {
const image = new Image();
image.src = "empty_recycle_bin.png";
image.onload = (ev) => {
ctx.drawImage(image, 250, 400, 60, 60);
};
this.arrayInfixContainer.draw(ctx);
this.stackContainer.draw(ctx);
this.arrayPostfixContainer.draw(ctx);
this.dustbin.draw(ctx);
}
update(ctx) {
this.ELEMENT = [
...this.arrayInfixContainer.nowElements,
...this.arrayInfixContainer.elementMoved,
];
this.#drawSymbols(ctx);
}
#drawSymbols(ctx) {
for (let i = 0; i < this.ELEMENT.length; i++) {
ctx.beginPath();
ctx.font = "20px Georgia";
const x = this.ELEMENT[i].x;
const y = this.ELEMENT[i].y;
ctx.fillRect(
x - this.symbolProps.width / 2,
y - this.symbolProps.height / 2,
this.symbolProps.width,
this.symbolProps.height
);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "yellow";
ctx.fillText(this.ELEMENT[i].label, x, y);
ctx.fillStyle = "black";
ctx.stroke();
}
}
}