-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbutton.js
More file actions
103 lines (96 loc) · 3.39 KB
/
Copy pathbutton.js
File metadata and controls
103 lines (96 loc) · 3.39 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
92
93
94
95
96
97
98
99
100
101
102
103
/*==============================================================================
Init
==============================================================================*/
$.Button = function( opt ) {
for( var k in opt ) {
this[k] = opt[k];
}
var text = $.text( {
ctx: $.ctxmg,
x: 0,
y: 0,
text: this.title,
hspacing: 1,
vspacing: 0,
halign: 'center',
valign: 'center',
scale: this.scale,
snap: 1,
render: 0
} );
this.width = this.lockedWidth;
this.height = this.lockedHeight;
this.sx = this.x - this.width / 2;
this.sy = this.y - this.height / 2;
this.cx = this.x;
this.cy = this.y;
this.ex = this.x + this.width / 2;
this.ey = this.y + this.height / 2;
this.hovering = 0;
this.ohovering = 0;
};
/*==============================================================================
Update
==============================================================================*/
$.Button.prototype.update = function( i ) {
/*==============================================================================
Check Hover State
==============================================================================*/
if( $.util.pointInRect( $.mouse.sx, $.mouse.sy, this.sx, this.sy, this.width, this.height ) ){
this.hovering = 1;
if( !this.ohovering ) {
$.audio.play( 'hover' );
}
} else {
this.hovering = 0;
}
this.ohovering = this.hovering;
/*==============================================================================
Check Click
==============================================================================*/
if( this.hovering && $.mouse.down ) {
$.audio.play( 'click' );
this.action();
}
};
/*==============================================================================
Render
==============================================================================*/
$.Button.prototype.render = function( i ) {
if( this.hovering ) {
$.ctxmg.fillStyle = 'hsla(0, 0%, 10%, 1)';
$.ctxmg.fillRect( Math.floor( this.sx ), Math.floor( this.sy ), this.width, this.height );
$.ctxmg.strokeStyle = 'hsla(0, 0%, 0%, 1)';
$.ctxmg.strokeRect( Math.floor( this.sx ) + 0.5, Math.floor( this.sy ) + 0.5, this.width - 1, this.height - 1, 1 );
$.ctxmg.strokeStyle = 'hsla(0, 0%, 100%, 0.2)';
$.ctxmg.strokeRect( Math.floor( this.sx ) + 1.5, Math.floor( this.sy ) + 1.5, this.width - 3, this.height - 3, 1 );
} else {
$.ctxmg.fillStyle = 'hsla(0, 0%, 0%, 1)';
$.ctxmg.fillRect( Math.floor( this.sx ), Math.floor( this.sy ), this.width, this.height );
$.ctxmg.strokeStyle = 'hsla(0, 0%, 0%, 1)';
$.ctxmg.strokeRect( Math.floor( this.sx ) + 0.5, Math.floor( this.sy ) + 0.5, this.width - 1, this.height - 1, 1 );
$.ctxmg.strokeStyle = 'hsla(0, 0%, 100%, 0.15)';
$.ctxmg.strokeRect( Math.floor( this.sx ) + 1.5, Math.floor( this.sy ) + 1.5, this.width - 3, this.height - 3, 1 );
}
$.ctxmg.beginPath();
$.text( {
ctx: $.ctxmg,
x: this.cx,
y: this.cy,
text: this.title,
hspacing: 1,
vspacing: 0,
halign: 'center',
valign: 'center',
scale: this.scale,
snap: 1,
render: true
} );
$.ctxmg.fillStyle = 'hsla(0, 0%, 100%, 0.7)';
if( this.hovering ) {
$.ctxmg.fillStyle = 'hsla(0, 0%, 100%, 1)';
}
$.ctxmg.fill();
$.ctxmg.fillStyle = 'hsla(0, 0%, 100%, 0.07)';
$.ctxmg.fillRect( Math.floor( this.sx ) + 2, Math.floor( this.sy ) + 2, this.width - 4, Math.floor( ( this.height - 4 ) / 2 ) );
};