-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactiveObject.js
More file actions
68 lines (67 loc) · 1.78 KB
/
Copy pathactiveObject.js
File metadata and controls
68 lines (67 loc) · 1.78 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
function activeObjectRect (Stage,Name) {
this.Stage = Stage;
this.Name = Name;
this.text = 'emptyString';
this.fillColor = '#ffffff' // default white
this.PosX = 0;
this.PosY = 0;
this.height = 100;
this.width = 100;
this.action = function (){alert('default action:'+this.Name);return false;};
this.whoAmI = function (){return this.Name;};
this.refresh = function () {this.Stage.rewriteCanvas();}
this.setFillColor = function ( htmlColor ){
this.fillColor = htmlColor;
return this;
};
this.setTopLeft = function ( x,y ){
this.PosX = x;
this.PosY = y;
return this;
}
this.setHeightAndWidth = function ( height, width ){
this.height = height;
this.width = width;
return this;
}
this.click = function ( PosX,PosY ){
if( PosX > this.PosX
&& PosX < (this.PosX+this.width)
&& PosY > this.PosY
&& PosY < (this.PosY+this.height)
){
this.action();
return true;
}else{
return false;
}
};
this.extendContext = function(){
this.Stage.context.fillStyle = this.fillColor;
this.Stage.context.fillRect(this.PosX,
this.PosY,
this.width,
this.height
);
};
this.addToStage = function (){
// this.Stage.printActiveObjectsNames();
ElementNumber = this.Stage.getElementNumberByName(this.Name);
if (ElementNumber != 'unkown' && ElementNumber >= 0){
this.Stage.activeObjects[ElementNumber] = this;
}else{
this.Stage.activeObjects.push(this);
}
return this;
};
this.removeFromStage = function(){
tempArray = new Array();
for (var i = 0; i < this.Stage.activeObjects.length; i++) {
if( this.Stage.activeObjects[i] != this ) {
tempArray.push(this.Stage.activeObjects[i]);
}
};
this.Stage.activeObjects = tempArray;
this.Stage.rewriteCanvas();
};
}