-
Notifications
You must be signed in to change notification settings - Fork 0
/
playbackButton.js
127 lines (119 loc) · 3.05 KB
/
playbackButton.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
125
126
127
//displays and handles clicks on the playback button.
function PlaybackButton() {
this.x = width / 2 - 10;
this.y = height - 40;
this.width = 20;
this.height = 20;
//flag to determine whether to play or pause after button click and
//to determine which icon to draw
this.playing = false;
this.draw = function () {
if (this.playing) {
//pause button
rect(this.x, this.y, this.width / 2 - 2, this.height);
rect(
this.x + (this.width / 2 + 2),
this.y,
this.width / 2 - 2,
this.height
);
//skip button
triangle(
this.x + 40,
this.y,
this.x + this.width + 40,
this.y + this.height / 2,
this.x + 40,
this.y + this.height
);
rect(this.x + 40 + this.width, this.y, 5, this.height);
//rewind button
triangle(
this.x - 40 + this.width,
this.y,
this.x - 40,
this.y + this.height / 2,
this.x - 40 + this.width,
this.y + this.height
);
rect(this.x - 45, this.y, 5, this.height);
} else {
//play button
triangle(
this.x,
this.y,
this.x + this.width,
this.y + this.height / 2,
this.x,
this.y + this.height
);
//skip button
triangle(
this.x + 40,
this.y,
this.x + this.width + 40,
this.y + this.height / 2,
this.x + 40,
this.y + this.height
);
rect(this.x + 40 + this.width, this.y, 5, this.height);
//rewind button
triangle(
this.x - 40 + this.width,
this.y,
this.x - 40,
this.y + this.height / 2,
this.x - 40 + this.width,
this.y + this.height
);
rect(this.x - 45, this.y, 5, this.height);
}
};
//checks for clicks on the button, starts or pauses playabck.
//@returns true if clicked false otherwise.
this.hitCheck = function (keycode = undefined) {
if (
(mouseX > this.x &&
mouseX < this.x + this.width &&
mouseY > this.y &&
mouseY < this.y + this.height) ||
keycode == 32
) {
this.playing = !this.playing;
return true;
}
return false;
};
//checks for clicks on the skip button, skips to start of next track;
//@returns true if clicked false otherwise.
this.hitCheckSkip = function () {
if (
mouseX > this.x + 40 &&
mouseX < this.x + this.width + 40 &&
mouseY > this.y &&
mouseY < this.y + this.height
) {
if (this.playing == false) {
this.playing = !this.playing;
}
return true;
}
return false;
};
//checks for clicks on the rewind button, rewinds to start of track before;
//@returns true if clicked false otherwise.
this.hitCheckRewind = function () {
if (
mouseX > this.x - 40 &&
mouseX < this.x + this.width - 40 &&
mouseY > this.y &&
mouseY < this.y + this.height
) {
if (this.playing == false) {
this.playing = !this.playing;
}
return true;
}
return false;
};
}