-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsc_app_button.js
More file actions
85 lines (84 loc) · 2.37 KB
/
sc_app_button.js
File metadata and controls
85 lines (84 loc) · 2.37 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
/*******
* Classe SC_Buttons.js de control
*******/
function SC_Button(params){
this.x= params.x;
this.y= params.y;
this.r= params.r;
this.hidden= false;
this.bgcolor= params.clr;
this.offset= 0;
this.zoneEvt= params.zoneEvt;
const localKill= SC.evt("localKill");
const sustain= (params.sustain)?
SC.repeatForever(
SC.await(this.zoneEvt)
, SC.kill(localKill
, SC.generate(this.zoneEvt, null, SC.forever)
)
)
: SC.nothing();
SC.tools.addProgram(
SC.cube(this
, SC.par(
SC.generate(params.e_disp, this, SC.forever)
, SC.filter(params.s_md, this.zoneEvt, "filterStart", SC.forever)
, SC.filter(params.s_ts, this.zoneEvt, "filterStart", SC.forever)
, SC.filter(params.s_tm, this.zoneEvt, "filterStart", SC.forever)
, SC.filter(params.s_tm, localKill, "filterMove", SC.forever)
, SC.filter(params.s_te, localKill, "filterEnd", SC.forever)
, SC.filter(params.s_tc, localKill, "filterEnd", SC.forever)
, SC.filter(params.s_mu, localKill, "filterEnd", SC.forever)
, SC.filter(params.s_mm, localKill, "filterMove", SC.forever)
, sustain
)
)
);
};
(function(){
const proto= SC_Button.prototype;
proto.filterStart= function(touch){
const rx= this.x-touch.pageX;
const ry= this.y-touch.pageY;
const r= Math.sqrt(rx*rx+ry*ry);
if(r<this.r){
this.id= touch.id;
return "zone1";
}
};
proto.inside= function(touch){
const rx= this.x-touch.x;
const ry= this.y-touch.y;
const r= Math.sqrt(rx*rx+ry*ry);
return r<this.r;
};
proto.filterMove= function(touch){
if(this.id!=touch.id){
return;
}
const rx= this.x-touch.pageX;
const ry= this.y-touch.pageY;
const r= Math.sqrt(rx*rx+ry*ry);
if(r>this.r){
return "zone1";
}
};
proto.filterEnd= function(touch){
if(touch.id==this.id){
return "zone1";
}
};
proto.draw= function(ctx, view){
if(this.hidden){ return; }
const theCtx= ctx.save();
ctx.strokeStyle= "black";
ctx.fillStyle= this.bgcolor;
ctx.beginPath();
ctx.arc(this.x,this.y+this.offset,this.r, 0,2*Math.PI, false);
ctx.fill();
ctx.arc(this.x,this.y+this.offset,this.r, 0,2*Math.PI, false);
ctx.stroke();
ctx.closePath();
ctx.restore(theCtx);
};
})();