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.Component'>/**
2 </span> * @class Ext.draw.Component
3 * @extends Ext.Component
5 * The Draw Component is a surface in which sprites can be rendered. The Draw Component
6 * manages and holds a `Surface` instance: an interface that has
7 * an SVG or VML implementation depending on the browser capabilities and where
8 * Sprites can be appended.
9 * {@img Ext.draw.Component/Ext.draw.Component.png Ext.draw.Component component}
10 * One way to create a draw component is:
12 * var drawComponent = Ext.create('Ext.draw.Component', {
23 * Ext.create('Ext.Window', {
27 * items: [drawComponent]
30 * In this case we created a draw component and added a sprite to it.
31 * The *type* of the sprite is *circle* so if you run this code you'll see a yellow-ish
32 * circle in a Window. When setting `viewBox` to `false` we are responsible for setting the object's position and
33 * dimensions accordingly.
35 * You can also add sprites by using the surface's add method:
37 * drawComponent.surface.add({
45 * For more information on Sprites, the core elements added to a draw component's surface,
46 * refer to the Ext.draw.Sprite documentation.
48 Ext.define('Ext.draw.Component', {
50 /* Begin Definitions */
54 extend: 'Ext.Component',
58 'Ext.layout.component.Draw'
63 <span id='Ext-draw.Component-cfg-enginePriority'> /**
64 </span> * @cfg {Array} enginePriority
65 * Defines the priority order for which Surface implementation to use. The first
66 * one supported by the current environment will be used.
68 enginePriority: ['Svg', 'Vml'],
70 baseCls: Ext.baseCSSPrefix + 'surface',
72 componentLayout: 'draw',
74 <span id='Ext-draw.Component-cfg-viewBox'> /**
75 </span> * @cfg {Boolean} viewBox
76 * Turn on view box support which will scale and position items in the draw component to fit to the component while
77 * maintaining aspect ratio. Note that this scaling can override other sizing settings on yor items. Defaults to true.
81 <span id='Ext-draw.Component-cfg-autoSize'> /**
82 </span> * @cfg {Boolean} autoSize
83 * Turn on autoSize support which will set the bounding div's size to the natural size of the contents. Defaults to false.
87 <span id='Ext-draw.Component-cfg-gradients'> /**
88 </span> * @cfg {Array} gradients (optional) Define a set of gradients that can be used as `fill` property in sprites.
89 * The gradients array is an array of objects with the following properties:
92 * <li><strong>id</strong> - string - The unique name of the gradient.</li>
93 * <li><strong>angle</strong> - number, optional - The angle of the gradient in degrees.</li>
94 * <li><strong>stops</strong> - object - An object with numbers as keys (from 0 to 100) and style objects
95 * as values</li>
101 <pre><code>
128 </code></pre>
130 Then the sprites can use `gradientId` and `gradientId2` by setting the fill attributes to those ids, for example:
132 <pre><code>
133 sprite.setAttributes({
134 fill: 'url(#gradientId)'
136 </code></pre>
140 initComponent: function() {
141 this.callParent(arguments);
153 <span id='Ext-draw.Component-method-onRender'> /**
156 * Create the Surface on initial render
158 onRender: function() {
160 viewBox = me.viewBox,
161 autoSize = me.autoSize,
162 bbox, items, width, height, x, y;
163 me.callParent(arguments);
167 items = me.surface.items;
169 if (viewBox || autoSize) {
170 bbox = items.getBBox();
172 height = bbox.height;
176 me.surface.setViewBox(x, y, width, height);
180 me.autoSizeSurface();
186 autoSizeSurface: function() {
188 items = me.surface.items,
189 bbox = items.getBBox(),
191 height = bbox.height;
192 items.setAttributes({
195 //Opera has a slight offset in the y axis.
196 y: -bbox.y + (+Ext.isOpera)
200 me.setSize(width, height);
203 me.surface.setSize(width, height);
205 me.el.setSize(width, height);
208 <span id='Ext-draw.Component-method-createSurface'> /**
209 </span> * Create the Surface instance. Resolves the correct Surface implementation to
210 * instantiate based on the 'enginePriority' config. Once the Surface instance is
211 * created you can use the handle to that instance to add sprites. For example:
213 <pre><code>
214 drawComponent.surface.add(sprite);
215 </code></pre>
217 createSurface: function() {
218 var surface = Ext.draw.Surface.create(Ext.apply({}, {
222 }, this.initialConfig));
223 this.surface = surface;
225 function refire(eventName) {
227 this.fireEvent(eventName, e);
233 mouseup: refire('mouseup'),
234 mousedown: refire('mousedown'),
235 mousemove: refire('mousemove'),
236 mouseenter: refire('mouseenter'),
237 mouseleave: refire('mouseleave'),
238 click: refire('click')
243 <span id='Ext-draw.Component-method-onDestroy'> /**
246 * Clean up the Surface instance on component destruction
248 onDestroy: function() {
249 var surface = this.surface;
253 this.callParent(arguments);
257 </pre></pre></body></html>