4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-draw-CompositeSprite'>/**
19 </span> * @class Ext.draw.CompositeSprite
20 * @extends Ext.util.MixedCollection
22 * A composite Sprite handles a group of sprites with common methods to a sprite
23 * such as `hide`, `show`, `setAttributes`. These methods are applied to the set of sprites
26 * CompositeSprite extends {@link Ext.util.MixedCollection} so you can use the same methods
27 * in `MixedCollection` to iterate through sprites, add and remove elements, etc.
29 * In order to create a CompositeSprite, one has to provide a handle to the surface where it is
32 * var group = Ext.create('Ext.draw.CompositeSprite', {
33 * surface: drawComponent.surface
36 * Then just by using `MixedCollection` methods it's possible to add {@link Ext.draw.Sprite}s:
42 * And then apply common Sprite methods to them:
44 * group.setAttributes({
48 Ext.define('Ext.draw.CompositeSprite', {
50 /* Begin Definitions */
52 extend: 'Ext.util.MixedCollection',
54 animate: 'Ext.util.Animate'
58 isCompositeSprite: true,
59 constructor: function(config) {
62 config = config || {};
63 Ext.apply(me, config);
72 me.id = Ext.id(null, 'ext-sprite-group-');
77 onClick: function(e) {
78 this.fireEvent('click', e);
82 onMouseUp: function(e) {
83 this.fireEvent('mouseup', e);
87 onMouseDown: function(e) {
88 this.fireEvent('mousedown', e);
92 onMouseOver: function(e) {
93 this.fireEvent('mouseover', e);
97 onMouseOut: function(e) {
98 this.fireEvent('mouseout', e);
101 attachEvents: function(o) {
106 mousedown: me.onMouseDown,
107 mouseup: me.onMouseUp,
108 mouseover: me.onMouseOver,
109 mouseout: me.onMouseOut,
114 <span id='Ext-draw-CompositeSprite-method-add'> /** Add a Sprite to the Group */
115 </span> add: function(key, o) {
116 var result = this.callParent(arguments);
117 this.attachEvents(result);
121 insert: function(index, key, o) {
122 return this.callParent(arguments);
125 <span id='Ext-draw-CompositeSprite-method-remove'> /** Remove a Sprite from the Group */
126 </span> remove: function(o) {
131 mousedown: me.onMouseDown,
132 mouseup: me.onMouseUp,
133 mouseover: me.onMouseOver,
134 mouseout: me.onMouseOut,
137 me.callParent(arguments);
140 <span id='Ext-draw-CompositeSprite-method-getBBox'> /**
141 </span> * Returns the group bounding box.
142 * Behaves like {@link Ext.draw.Sprite} getBBox method.
144 getBBox: function() {
152 maxHeight = -infinity,
154 maxWidth = -infinity,
155 maxWidthBBox, maxHeightBBox;
157 for (; i < len; i++) {
160 bb = sprite.getBBox();
161 minX = Math.min(minX, bb.x);
162 minY = Math.min(minY, bb.y);
163 maxHeight = Math.max(maxHeight, bb.height + bb.y);
164 maxWidth = Math.max(maxWidth, bb.width + bb.x);
171 height: maxHeight - minY,
172 width: maxWidth - minX
176 <span id='Ext-draw-CompositeSprite-method-setAttributes'> /**
177 </span> * Iterates through all sprites calling
178 * `setAttributes` on each one. For more information
179 * {@link Ext.draw.Sprite} provides a description of the
180 * attributes that can be set with this method.
182 setAttributes: function(attrs, redraw) {
187 for (; i < len; i++) {
188 items[i].setAttributes(attrs, redraw);
193 <span id='Ext-draw-CompositeSprite-method-hide'> /**
194 </span> * Hides all sprites. If the first parameter of the method is true
195 * then a redraw will be forced for each sprite.
197 hide: function(redraw) {
202 for (; i < len; i++) {
203 items[i].hide(redraw);
208 <span id='Ext-draw-CompositeSprite-method-show'> /**
209 </span> * Shows all sprites. If the first parameter of the method is true
210 * then a redraw will be forced for each sprite.
212 show: function(redraw) {
217 for (; i < len; i++) {
218 items[i].show(redraw);
227 surface = me.getSurface(),
231 for (; i < len; i++) {
232 surface.renderItem(items[i]);
238 setStyle: function(obj) {
244 for (; i < len; i++) {
253 addCls: function(obj) {
256 surface = this.getSurface(),
260 for (; i < len; i++) {
261 surface.addCls(items[i], obj);
266 removeCls: function(obj) {
269 surface = this.getSurface(),
273 for (; i < len; i++) {
274 surface.removeCls(items[i], obj);
279 <span id='Ext-draw-CompositeSprite-method-getSurface'> /**
280 </span> * Grab the surface from the items
282 * @return {Ext.draw.Surface} The surface, null if not found
284 getSurface: function(){
285 var first = this.first();
287 return first.surface;
292 <span id='Ext-draw-CompositeSprite-method-destroy'> /**
293 </span> * Destroys the SpriteGroup
297 surface = me.getSurface(),
301 while (me.getCount() > 0) {
304 surface.remove(item);