-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModal.js
50 lines (44 loc) · 920 Bytes
/
Modal.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
class Modal {
constructor() {
this.active = true;
}
closeHandler() {
if (mouseIsPressed) {
if (mouseX < (width / 2 + 80) + 10 && mouseX > (width / 2 + 80) - 10) {
if (mouseY < (height / 2 - 75) + 5.5 && mouseY > (height / 2 - 75) - 17.5) {
this.closeModal();
}
}
}
}
show() {
this.closeHandler();
// outline box
rectMode(CORNER)
noFill();
strokeWeight(5)
rect(width / 2 - 100, height / 2 - 100, 200, 200, 20);
// x to close
strokeWeight(4)
fill(0, 0, 0)
textFont(this.font)
textAlign("center")
textSize(24)
text("x", width / 2 + 80, height / 2 - 75)
// text
rectMode(CENTER)
strokeWeight(4)
fill(0, 0, 0)
textFont(this.font)
textAlign("center")
textSize(20)
text(this.text,
width / 2 + 5, // x1
height / 2 + 70, // x2
width / (this.text.length / 5), // width?
height / 2 - 100); // height?
}
hide() {
this.active = false;
}
}