]>
git.proxmox.com Git - sencha-touch.git/blob - src/src/draw/sprite/Instancing.js
2 * @class Ext.draw.sprite.Instancing
3 * @extends Ext.draw.sprite.Sprite
5 * Sprite that represents multiple instances based on the given template.
7 Ext
.define("Ext.draw.sprite.Instancing", {
8 extend
: "Ext.draw.sprite.Sprite",
9 alias
: 'sprite.instancing',
14 * @cfg {Object} [template=null] The sprite template used by all instances.
19 constructor: function (config
) {
21 this.callSuper([config
]);
22 if (config
&& config
.template
) {
23 this.setTemplate(config
.template
);
27 applyTemplate: function (template
) {
28 if (!(template
instanceof Ext
.draw
.sprite
.Sprite
)) {
29 template
= Ext
.create(template
.xclass
|| "sprite." + template
.type
, template
);
31 template
.setParent(this);
32 template
.attr
.children
= [];
39 * Creates a new sprite instance.
41 * @param {Object} config The configuration of the instance.
42 * @param {Object} [data]
43 * @param {Boolean} [bypassNormalization] 'true' to bypass attribute normalization.
44 * @param {Boolean} [avoidCopy] 'true' to avoid copying.
45 * @return {Object} The attributes of the instance.
47 createInstance: function (config
, data
, bypassNormalization
, avoidCopy
) {
48 var template
= this.getTemplate(),
49 originalAttr
= template
.attr
,
50 attr
= Ext
.Object
.chain(originalAttr
);
51 template
.topModifier
.prepareAttributes(attr
);
53 template
.setAttributes(config
, bypassNormalization
, avoidCopy
);
55 this.instances
.push(attr
);
56 template
.attr
= originalAttr
;
58 originalAttr
.children
.push(attr
);
67 getBBox: function () { return null; },
70 * Returns the bounding box for the instance at the given index.
72 * @param {Number} index The index of the instance.
73 * @param {Boolean} [isWithoutTransform] 'true' to not apply sprite transforms to the bounding box.
74 * @return {Object} The bounding box for the instance.
76 getBBoxFor: function (index
, isWithoutTransform
) {
77 var template
= this.getTemplate(),
78 originalAttr
= template
.attr
,
80 template
.attr
= this.instances
[index
];
81 bbox
= template
.getBBox(isWithoutTransform
);
82 template
.attr
= originalAttr
;
86 render: function (surface
, ctx
, clipRegion
, region
) {
89 template
= me
.getTemplate(),
90 originalAttr
= template
.attr
,
91 instances
= me
.instances
,
95 template
.preRender(surface
, ctx
, clipRegion
, region
);
96 template
.useAttributes(ctx
, region
);
97 for (i
= 0; i
< ln
; i
++) {
98 if (instances
[i
].dirtyZIndex
) {
102 for (i
= 0; i
< ln
; i
++) {
103 if (instances
[i
].hidden
) {
107 template
.attr
= instances
[i
];
108 template
.applyTransformations();
109 template
.useAttributes(ctx
, region
);
110 template
.render(surface
, ctx
, clipRegion
, region
);
113 template
.attr
= originalAttr
;
117 * Sets the attributes for the instance at the given index.
119 * @param {Number} index the index of the instance
120 * @param {Object} changes the attributes to change
121 * @param {Boolean} [bypassNormalization] 'true' to avoid attribute normalization
123 setAttributesFor: function (index
, changes
, bypassNormalization
) {
124 var template
= this.getTemplate(),
125 originalAttr
= template
.attr
,
126 attr
= this.instances
[index
];
127 template
.attr
= attr
;
129 if (bypassNormalization
) {
130 changes
= Ext
.apply({}, changes
);
132 changes
= template
.self
.def
.normalize(changes
);
134 template
.topModifier
.pushDown(attr
, changes
);
135 template
.updateDirtyFlags(attr
);
137 template
.attr
= originalAttr
;
141 destroy: function () {
143 this.instances
.length
= 0;
144 this.instances
= null;
145 if (this.getTemplate()) {
146 this.getTemplate().destroy();