Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Incognito-old
Path: blob/main/static/src/gs/public/radius-raid/js/button.js
1324 views
1
/*==============================================================================
2
Init
3
==============================================================================*/
4
$.Button = function( opt ) {
5
for( var k in opt ) {
6
this[k] = opt[k];
7
}
8
var text = $.text( {
9
ctx: $.ctxmg,
10
x: 0,
11
y: 0,
12
text: this.title,
13
hspacing: 1,
14
vspacing: 0,
15
halign: 'center',
16
valign: 'center',
17
scale: this.scale,
18
snap: 1,
19
render: 0
20
} );
21
this.width = this.lockedWidth;
22
this.height = this.lockedHeight;
23
24
this.sx = this.x - this.width / 2;
25
this.sy = this.y - this.height / 2;
26
this.cx = this.x;
27
this.cy = this.y;
28
this.ex = this.x + this.width / 2;
29
this.ey = this.y + this.height / 2;
30
this.hovering = 0;
31
this.ohovering = 0;
32
};
33
34
/*==============================================================================
35
Update
36
==============================================================================*/
37
$.Button.prototype.update = function( i ) {
38
/*==============================================================================
39
Check Hover State
40
==============================================================================*/
41
if( $.util.pointInRect( $.mouse.sx, $.mouse.sy, this.sx, this.sy, this.width, this.height ) ){
42
this.hovering = 1;
43
if( !this.ohovering ) {
44
$.audio.play( 'hover' );
45
}
46
} else {
47
this.hovering = 0;
48
}
49
this.ohovering = this.hovering;
50
51
/*==============================================================================
52
Check Click
53
==============================================================================*/
54
if( this.hovering && $.mouse.down ) {
55
$.audio.play( 'click' );
56
this.action();
57
}
58
};
59
60
/*==============================================================================
61
Render
62
==============================================================================*/
63
$.Button.prototype.render = function( i ) {
64
if( this.hovering ) {
65
$.ctxmg.fillStyle = 'hsla(0, 0%, 10%, 1)';
66
$.ctxmg.fillRect( Math.floor( this.sx ), Math.floor( this.sy ), this.width, this.height );
67
$.ctxmg.strokeStyle = 'hsla(0, 0%, 0%, 1)';
68
$.ctxmg.strokeRect( Math.floor( this.sx ) + 0.5, Math.floor( this.sy ) + 0.5, this.width - 1, this.height - 1, 1 );
69
$.ctxmg.strokeStyle = 'hsla(0, 0%, 100%, 0.2)';
70
$.ctxmg.strokeRect( Math.floor( this.sx ) + 1.5, Math.floor( this.sy ) + 1.5, this.width - 3, this.height - 3, 1 );
71
} else {
72
$.ctxmg.fillStyle = 'hsla(0, 0%, 0%, 1)';
73
$.ctxmg.fillRect( Math.floor( this.sx ), Math.floor( this.sy ), this.width, this.height );
74
$.ctxmg.strokeStyle = 'hsla(0, 0%, 0%, 1)';
75
$.ctxmg.strokeRect( Math.floor( this.sx ) + 0.5, Math.floor( this.sy ) + 0.5, this.width - 1, this.height - 1, 1 );
76
$.ctxmg.strokeStyle = 'hsla(0, 0%, 100%, 0.15)';
77
$.ctxmg.strokeRect( Math.floor( this.sx ) + 1.5, Math.floor( this.sy ) + 1.5, this.width - 3, this.height - 3, 1 );
78
}
79
80
$.ctxmg.beginPath();
81
$.text( {
82
ctx: $.ctxmg,
83
x: this.cx,
84
y: this.cy,
85
text: this.title,
86
hspacing: 1,
87
vspacing: 0,
88
halign: 'center',
89
valign: 'center',
90
scale: this.scale,
91
snap: 1,
92
render: true
93
} );
94
95
$.ctxmg.fillStyle = 'hsla(0, 0%, 100%, 0.7)';
96
if( this.hovering ) {
97
$.ctxmg.fillStyle = 'hsla(0, 0%, 100%, 1)';
98
}
99
$.ctxmg.fill();
100
101
$.ctxmg.fillStyle = 'hsla(0, 0%, 100%, 0.07)';
102
$.ctxmg.fillRect( Math.floor( this.sx ) + 2, Math.floor( this.sy ) + 2, this.width - 4, Math.floor( ( this.height - 4 ) / 2 ) );
103
};
104