-
Notifications
You must be signed in to change notification settings - Fork 3
/
simpleCanvas.js
executable file
·68 lines (55 loc) · 1.74 KB
/
simpleCanvas.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
dojo.provide("simpleCanvas");
dojo.declare("simpleCanvas", null, {
id:undefined,
canvas_dom:undefined,
width:undefined,
height:undefined,
context:undefined,
fillColor:undefined,
constructor:function(args){
//Take arguments and mix them in.
dojo.safeMixin(this, args);
//Instantiate ID, Dom Node, and Context
if(this.id != undefined){
this.canvas_dom = dojo.byId(this.id);
this.context = this.canvas_dom.getContext("2d");
}
else if (this.canvas_dom != undefined){
this.id = this.canvas_dom.id;
this.context = this.canvas_dom.getContext("2d");
}
//Do Work.
if(this.id && this.canvas_dom && this.context){
if(this.height && this.width){
this.canvas_dom.height = this.height;
this.canvas_dom.width = this.width;
}
else{
this.height = this.canvas_dom.height;
this.width = this.canvas_dom.width;
}
if(this.fillColor){
this.fillCanvas(this.fillColor);
}
else{
this.fillCanvas("rgba(0,0,0,1)");
}
}
else{
console.log("Canvas Instantiation Failed.");
}
},
clear:function(){
this.canvas_dom.width = this.canvas_dom.width;
},
fill:function(rgba){
this.context.fillStyle = rgba;
},
fillRect:function(x,y,w,h){
this.context.fillRect(x,y,w,h);
},
fillCanvas:function(color){
this.fill(color);
this.context.fillRect(0,0,this.width,this.height);
},
});