Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/html/lib/canvas/CanvasControl.js
blob: ce16446d9b6bca83c00d9fa4569819ec42479d6c (plain)
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
/**
	The base kind for items that live inside an
	<a href="#enyo.Canvas">enyo.Canvas</a> 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_
	method and use that for your drawing code.
*/
enyo.kind({
	name: "enyo.canvas.Control",
	kind: enyo.UiComponent,
	defaultKind: "enyo.canvas.Control",
	published: {
		//* Structure with l (left), t (top), w (width), and h (height) members.
		//* The default constructor sets those properties to random values.
		bounds: null
	},
	events: {
		//* Event providing hook to render this control. The event structure 
		//* includes a _context_ member holding the active canvas context.
		onRender: ""
	},
	//* @protected
	constructor: function() {
		this.bounds = {l: enyo.irand(400), t: enyo.irand(400), w: enyo.irand(100), h: enyo.irand(100)};
		this.inherited(arguments);
	},
	importProps: function(inProps) {
		this.inherited(arguments);
		if (inProps.bounds) {
			enyo.mixin(this.bounds, inProps.bounds);
			delete inProps.bounds;
		}
	},
	renderSelf: function(inContext) {
		this.doRender({context: inContext});
	},
	render: function(inContext) {
		if (this.children.length) {
			this.renderChildren(inContext);
		} else {
			this.renderSelf(inContext);
		}
	},
	renderChildren: function(inContext) {
		for (var i=0, c; c=this.children[i]; i++) {
			c.render(inContext);
		}
	}
});