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-Component'>/**
19 </span> * @class Ext.draw.Component
20 * @extends Ext.Component
22 * The Draw Component is a surface in which sprites can be rendered. The Draw Component
23 * manages and holds a `Surface` instance: an interface that has
24 * an SVG or VML implementation depending on the browser capabilities and where
25 * Sprites can be appended.
26 * {@img Ext.draw.Component/Ext.draw.Component.png Ext.draw.Component component}
27 * One way to create a draw component is:
29 * var drawComponent = Ext.create('Ext.draw.Component', {
40 * Ext.create('Ext.Window', {
44 * items: [drawComponent]
47 * In this case we created a draw component and added a sprite to it.
48 * The *type* of the sprite is *circle* so if you run this code you'll see a yellow-ish
49 * circle in a Window. When setting `viewBox` to `false` we are responsible for setting the object's position and
50 * dimensions accordingly.
52 * You can also add sprites by using the surface's add method:
54 * drawComponent.surface.add({
62 * For more information on Sprites, the core elements added to a draw component's surface,
63 * refer to the Ext.draw.Sprite documentation.
65 Ext.define('Ext.draw.Component', {
67 /* Begin Definitions */
71 extend: 'Ext.Component',
75 'Ext.layout.component.Draw'
80 <span id='Ext-draw-Component-cfg-enginePriority'> /**
81 </span> * @cfg {Array} enginePriority
82 * Defines the priority order for which Surface implementation to use. The first
83 * one supported by the current environment will be used.
85 enginePriority: ['Svg', 'Vml'],
87 baseCls: Ext.baseCSSPrefix + 'surface',
89 componentLayout: 'draw',
91 <span id='Ext-draw-Component-cfg-viewBox'> /**
92 </span> * @cfg {Boolean} viewBox
93 * Turn on view box support which will scale and position items in the draw component to fit to the component while
94 * maintaining aspect ratio. Note that this scaling can override other sizing settings on yor items. Defaults to true.
98 <span id='Ext-draw-Component-cfg-autoSize'> /**
99 </span> * @cfg {Boolean} autoSize
100 * Turn on autoSize support which will set the bounding div's size to the natural size of the contents. Defaults to false.
104 <span id='Ext-draw-Component-cfg-gradients'> /**
105 </span> * @cfg {Array} gradients (optional) Define a set of gradients that can be used as `fill` property in sprites.
106 * The gradients array is an array of objects with the following properties:
109 * <li><strong>id</strong> - string - The unique name of the gradient.</li>
110 * <li><strong>angle</strong> - number, optional - The angle of the gradient in degrees.</li>
111 * <li><strong>stops</strong> - object - An object with numbers as keys (from 0 to 100) and style objects
112 * as values</li>
118 <pre><code>
145 </code></pre>
147 Then the sprites can use `gradientId` and `gradientId2` by setting the fill attributes to those ids, for example:
149 <pre><code>
150 sprite.setAttributes({
151 fill: 'url(#gradientId)'
153 </code></pre>
157 initComponent: function() {
158 this.callParent(arguments);
170 <span id='Ext-draw-Component-method-onRender'> /**
173 * Create the Surface on initial render
175 onRender: function() {
177 viewBox = me.viewBox,
178 autoSize = me.autoSize,
179 bbox, items, width, height, x, y;
180 me.callParent(arguments);
184 items = me.surface.items;
186 if (viewBox || autoSize) {
187 bbox = items.getBBox();
189 height = bbox.height;
193 me.surface.setViewBox(x, y, width, height);
197 me.autoSizeSurface();
203 autoSizeSurface: function() {
205 items = me.surface.items,
206 bbox = items.getBBox(),
208 height = bbox.height;
209 items.setAttributes({
212 //Opera has a slight offset in the y axis.
213 y: -bbox.y + (+Ext.isOpera)
217 me.setSize(width, height);
218 me.surface.setSize(width, height);
221 me.surface.setSize(width, height);
223 me.el.setSize(width, height);
226 <span id='Ext-draw-Component-method-createSurface'> /**
227 </span> * Create the Surface instance. Resolves the correct Surface implementation to
228 * instantiate based on the 'enginePriority' config. Once the Surface instance is
229 * created you can use the handle to that instance to add sprites. For example:
231 <pre><code>
232 drawComponent.surface.add(sprite);
233 </code></pre>
235 createSurface: function() {
236 var surface = Ext.draw.Surface.create(Ext.apply({}, {
240 }, this.initialConfig));
241 this.surface = surface;
243 function refire(eventName) {
245 this.fireEvent(eventName, e);
251 mouseup: refire('mouseup'),
252 mousedown: refire('mousedown'),
253 mousemove: refire('mousemove'),
254 mouseenter: refire('mouseenter'),
255 mouseleave: refire('mouseleave'),
256 click: refire('click')
261 <span id='Ext-draw-Component-method-onDestroy'> /**
264 * Clean up the Surface instance on component destruction
266 onDestroy: function() {
267 var surface = this.surface;
271 this.callParent(arguments);