-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext.js
More file actions
63 lines (60 loc) · 1.77 KB
/
Copy pathtext.js
File metadata and controls
63 lines (60 loc) · 1.77 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
class Text
{
constructor(text, position, size, color, font)
{
this.text = text;
this.position = position;
this.size = size || 20 * SCALE;
this.color = color || "white";
this.font = font || "monaco";
this.x = 0;
this.y = 0;
this.lineSpace = 3 * SCALE;
}
length()
{
canvas.userInterface.font = this.size + "px " + this.font;
return canvas.userInterface.measureText(this.text).width;
}
getCoordinates()
{
let margin = 20 * SCALE;
//let lineMargin = (lineNumber-1) * (size + TEXT.lineSpacing);
if (typeof this.position == "string")
{
if (this.position.includes("top"))
{
this.y = POSITIONS.screen.top + margin + this.size;
}
else if (this.position.includes("bottom"))
{
this.y = POSITIONS.screen.bottom - margin;
}
if (this.position.includes("right"))
{
this.x = POSITIONS.screen.right - margin - this.length();
}
else if (this.position.includes("left"))
{
this.x = POSITIONS.screen.left + margin;
}
if (this.position == "middle")
{
this.x = POSITIONS.screen.middleX - this.length()/2;
this.y = POSITIONS.screen.middleY;
}
}
else
{
this.x = this.position.x;
this.y = this.position.y;
}
}
display()
{
this.getCoordinates();
canvas.userInterface.font = this.size + "px " + TEXT.font;
canvas.userInterface.fillStyle = this.color;
canvas.userInterface.fillText(this.text, this.x, this.y)
}
}