4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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 // Inherit docs from MixedCollection
115 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 // Inherit docs from MixedCollection
126 remove: function(o) {
131 mousedown: me.onMouseDown,
132 mouseup: me.onMouseUp,
133 mouseover: me.onMouseOver,
134 mouseout: me.onMouseOut,
137 return 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.
143 * @return {Object} an object with x, y, width, and height properties.
145 getBBox: function() {
153 maxHeight = -infinity,
155 maxWidth = -infinity,
156 maxWidthBBox, maxHeightBBox;
158 for (; i < len; i++) {
161 bb = sprite.getBBox();
162 minX = Math.min(minX, bb.x);
163 minY = Math.min(minY, bb.y);
164 maxHeight = Math.max(maxHeight, bb.height + bb.y);
165 maxWidth = Math.max(maxWidth, bb.width + bb.x);
172 height: maxHeight - minY,
173 width: maxWidth - minX
177 <span id='Ext-draw-CompositeSprite-method-setAttributes'> /**
178 </span> * Iterates through all sprites calling `setAttributes` on each one. For more information {@link Ext.draw.Sprite}
179 * provides a description of the attributes that can be set with this method.
180 * @param {Object} attrs Attributes to be changed on the sprite.
181 * @param {Boolean} redraw Flag to immediatly draw the change.
182 * @return {Ext.draw.CompositeSprite} this
184 setAttributes: function(attrs, redraw) {
189 for (; i < len; i++) {
190 items[i].setAttributes(attrs, redraw);
195 <span id='Ext-draw-CompositeSprite-method-hide'> /**
196 </span> * Hides all sprites. If the first parameter of the method is true
197 * then a redraw will be forced for each sprite.
198 * @param {Boolean} redraw Flag to immediatly draw the change.
199 * @return {Ext.draw.CompositeSprite} this
201 hide: function(redraw) {
206 for (; i < len; i++) {
207 items[i].hide(redraw);
212 <span id='Ext-draw-CompositeSprite-method-show'> /**
213 </span> * Shows all sprites. If the first parameter of the method is true
214 * then a redraw will be forced for each sprite.
215 * @param {Boolean} redraw Flag to immediatly draw the change.
216 * @return {Ext.draw.CompositeSprite} this
218 show: function(redraw) {
223 for (; i < len; i++) {
224 items[i].show(redraw);
233 surface = me.getSurface(),
237 for (; i < len; i++) {
238 surface.renderItem(items[i]);
244 setStyle: function(obj) {
250 for (; i < len; i++) {
259 addCls: function(obj) {
262 surface = this.getSurface(),
266 for (; i < len; i++) {
267 surface.addCls(items[i], obj);
272 removeCls: function(obj) {
275 surface = this.getSurface(),
279 for (; i < len; i++) {
280 surface.removeCls(items[i], obj);
285 <span id='Ext-draw-CompositeSprite-method-getSurface'> /**
286 </span> * Grab the surface from the items
288 * @return {Ext.draw.Surface} The surface, null if not found
290 getSurface: function(){
291 var first = this.first();
293 return first.surface;
298 <span id='Ext-draw-CompositeSprite-method-destroy'> /**
299 </span> * Destroys the SpriteGroup
303 surface = me.getSurface(),
307 while (me.getCount() > 0) {
310 surface.remove(item);