forked from enyojs/canvas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Canvas.js
52 lines (52 loc) · 1.14 KB
/
Canvas.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
enyo.kind({
name: "enyo.Canvas",
kind: enyo.Control,
tag: "canvas",
attributes: {
width: 500,
height: 500
},
defaultKind: "enyo.canvas.Control",
generateInnerHtml: function() {
return '';
},
teardownChildren: function() {
},
rendered: function() {
this.renderChildren();
},
/*
addChild and removeChild of Control kind assumes children are Controls.
CanvasControls are not, so we use UiComponent's version, the superkind of Control
*/
addChild: function() {
enyo.UiComponent.prototype.addChild.apply(this, arguments);
},
removeChild: function() {
enyo.UiComponent.prototype.removeChild.apply(this, arguments);
},
renderChildren: function(inContext) {
var ctx = inContext;
var canvas = this.hasNode();
if (!ctx) {
if (canvas.getContext) {
ctx = canvas.getContext('2d');
}
}
if (ctx) {
for (var i=0, c; c=this.children[i]; i++) {
c.render(ctx);
}
}
},
update: function() {
var canvas = this.hasNode();
if (canvas.getContext) {
var ctx = canvas.getContext('2d');
var b = this.getBounds();
// clear canvas
ctx.clearRect(0, 0, b.width, b.height);
this.renderChildren(ctx);
}
}
});