/
CanvasControl.js
115 lines (102 loc) · 2.12 KB
/
CanvasControl.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
(function (enyo, scope) {
/**
* Fires when this control is to be rendered.
*
* @event enyo.canvas.Control#event:onRender
* @param {Context} context - The active canvas context.
* @public
*/
/**
* {@link enyo.canvas.Control} is the base kind for items that live inside an
* {@link enyo.Canvas} control.
*
* If you're using this kind directly, you may implement an `onRender` event
* handler in the owner to handle drawing into the canvas.
*
* If you're deriving a new kind based on this one, override the
* [renderSelf()]{@link enyo.canvas.Control#renderSelf} method and use that for
* your drawing code.
*
*
* @class enyo.canvas.Control
* @extends enyo.UiComponent
* @public
*/
enyo.kind(
/** @lends enyo.canvas.Control.prototype */ {
/**
* @private
*/
name: 'enyo.canvas.Control',
/**
* @private
*/
kind: 'enyo.UiComponent',
/**
* @private
*/
defaultKind: 'enyo.canvas.Control',
/**
* @lends enyo.canvas.Control.prototype
* @private
*/
published: {
/**
* Object with members `l` (left), `t` (top), `w` (width), and `h` (height).
* The default constructor sets these properties to random values.
*
* @type {Object}
* @public
*/
bounds: null
},
/**
* @private
*/
events: {
onRender: ''
},
/**
* @private
*/
constructor: function () {
this.bounds = {l: enyo.irand(400), t: enyo.irand(400), w: enyo.irand(100), h: enyo.irand(100)};
this.inherited(arguments);
},
/**
* @private
*/
importProps: function (props) {
this.inherited(arguments);
if (props && props.bounds) {
enyo.mixin(this.bounds, props.bounds);
delete props.bounds;
}
},
/**
* @fires enyo.canvas.Control#event:onRender
* @protected
*/
renderSelf: function (context) {
this.doRender({context: context});
},
/**
* @private
*/
render: function (context) {
if (this.children.length) {
this.renderChildren(context);
} else {
this.renderSelf(context);
}
},
/**
* @private
*/
renderChildren: function (context) {
for (var i=0, c; (c=this.children[i]); i++) {
c.render(context);
}
}
});
})(enyo, this);