-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuttons.js
52 lines (42 loc) · 1.5 KB
/
buttons.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
function ImageCircleBtn(x, y, radius, image, onTouchEvent) {
this.isUnder = function(touchPos) {
var d = (touchPos.x - x) * (touchPos.x - x) + (touchPos.y - y) * (touchPos.y - y);
return (d <= (radius * radius));
};
this.onTouch = onTouchEvent;
this.draw = function(graphicsDevice) {
graphicsDevice.drawImage(image, x - radius, y - radius, 2 * radius, 2 * radius);
};
}
function ImageRectangleBtn(x, y, height, width, image, text, onTouchEvent) {
this.onTouch = onTouchEvent;
this.isUnder = function(touchPos) {
return (x <= touchPos.x && touchPos.x <= x + width) && (y <= touchPos.y && touchPos.y <= y + height);
};
this.draw = function(graphicsDevice) {
graphicsDevice.drawImage(image, x, y, width, height);
graphicsDevice.fillText(text,
x + 30,
y + 30,
20,
"Arial",
'rgba(0, 0, 0, 1.0)');
};
}
function RectangleBtn(x, y, height, width, borderWidth, text, fontSize, onTouchEvent) {
this.onTouch = onTouchEvent;
this.text = text;
this.isUnder = function(touchPos) {
return (x <= touchPos.x && touchPos.x <= x + width) && (y <= touchPos.y && touchPos.y <= y + height);
};
this.draw = function(graphicsDevice) {
graphicsDevice.strokeRect(x, y, width, height, 'rgba(0, 0, 0)', borderWidth);
graphicsDevice.fillText(this.text,
x,
y + width / 5,
fontSize,
"Arial",
'rgba(0, 0, 0, 1.0)',
borderWidth);
};
}