1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-draw.CompositeSprite'>/**
2 </span> * @class Ext.draw.CompositeSprite
3 * @extends Ext.util.MixedCollection
5 * A composite Sprite handles a group of sprites with common methods to a sprite
6 * such as `hide`, `show`, `setAttributes`. These methods are applied to the set of sprites
9 * CompositeSprite extends {@link Ext.util.MixedCollection} so you can use the same methods
10 * in `MixedCollection` to iterate through sprites, add and remove elements, etc.
12 * In order to create a CompositeSprite, one has to provide a handle to the surface where it is
15 * var group = Ext.create('Ext.draw.CompositeSprite', {
16 * surface: drawComponent.surface
19 * Then just by using `MixedCollection` methods it's possible to add {@link Ext.draw.Sprite}s:
25 * And then apply common Sprite methods to them:
27 * group.setAttributes({
31 Ext.define('Ext.draw.CompositeSprite', {
33 /* Begin Definitions */
35 extend: 'Ext.util.MixedCollection',
37 animate: 'Ext.util.Animate'
41 isCompositeSprite: true,
42 constructor: function(config) {
45 config = config || {};
46 Ext.apply(me, config);
55 me.id = Ext.id(null, 'ext-sprite-group-');
60 onClick: function(e) {
61 this.fireEvent('click', e);
65 onMouseUp: function(e) {
66 this.fireEvent('mouseup', e);
70 onMouseDown: function(e) {
71 this.fireEvent('mousedown', e);
75 onMouseOver: function(e) {
76 this.fireEvent('mouseover', e);
80 onMouseOut: function(e) {
81 this.fireEvent('mouseout', e);
84 attachEvents: function(o) {
89 mousedown: me.onMouseDown,
90 mouseup: me.onMouseUp,
91 mouseover: me.onMouseOver,
92 mouseout: me.onMouseOut,
97 <span id='Ext-draw.CompositeSprite-method-add'> /** Add a Sprite to the Group */
98 </span> add: function(key, o) {
99 var result = this.callParent(arguments);
100 this.attachEvents(result);
104 insert: function(index, key, o) {
105 return this.callParent(arguments);
108 <span id='Ext-draw.CompositeSprite-method-remove'> /** Remove a Sprite from the Group */
109 </span> remove: function(o) {
114 mousedown: me.onMouseDown,
115 mouseup: me.onMouseUp,
116 mouseover: me.onMouseOver,
117 mouseout: me.onMouseOut,
120 me.callParent(arguments);
123 <span id='Ext-draw.CompositeSprite-method-getBBox'> /**
124 </span> * Returns the group bounding box.
125 * Behaves like {@link Ext.draw.Sprite} getBBox method.
127 getBBox: function() {
135 maxHeight = -infinity,
137 maxWidth = -infinity,
138 maxWidthBBox, maxHeightBBox;
140 for (; i < len; i++) {
143 bb = sprite.getBBox();
144 minX = Math.min(minX, bb.x);
145 minY = Math.min(minY, bb.y);
146 maxHeight = Math.max(maxHeight, bb.height + bb.y);
147 maxWidth = Math.max(maxWidth, bb.width + bb.x);
154 height: maxHeight - minY,
155 width: maxWidth - minX
159 <span id='Ext-draw.CompositeSprite-method-setAttributes'> /**
160 </span> * Iterates through all sprites calling
161 * `setAttributes` on each one. For more information
162 * {@link Ext.draw.Sprite} provides a description of the
163 * attributes that can be set with this method.
165 setAttributes: function(attrs, redraw) {
170 for (; i < len; i++) {
171 items[i].setAttributes(attrs, redraw);
176 <span id='Ext-draw.CompositeSprite-method-hide'> /**
177 </span> * Hides all sprites. If the first parameter of the method is true
178 * then a redraw will be forced for each sprite.
180 hide: function(attrs) {
185 for (; i < len; i++) {
191 <span id='Ext-draw.CompositeSprite-method-show'> /**
192 </span> * Shows all sprites. If the first parameter of the method is true
193 * then a redraw will be forced for each sprite.
195 show: function(attrs) {
200 for (; i < len; i++) {
210 surface = me.getSurface(),
214 for (; i < len; i++) {
215 surface.renderItem(items[i]);
221 setStyle: function(obj) {
227 for (; i < len; i++) {
236 addCls: function(obj) {
239 surface = this.getSurface(),
243 for (; i < len; i++) {
244 surface.addCls(items[i], obj);
249 removeCls: function(obj) {
252 surface = this.getSurface(),
256 for (; i < len; i++) {
257 surface.removeCls(items[i], obj);
262 <span id='Ext-draw.CompositeSprite-method-getSurface'> /**
263 </span> * Grab the surface from the items
265 * @return {Ext.draw.Surface} The surface, null if not found
267 getSurface: function(){
268 var first = this.first();
270 return first.surface;
275 <span id='Ext-draw.CompositeSprite-method-destroy'> /**
276 </span> * Destroys the SpriteGroup
280 surface = me.getSurface(),
284 while (me.getCount() > 0) {
287 surface.remove(item);
293 </pre></pre></body></html>