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-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.
27 * One way to create a draw component is:
30 * var drawComponent = Ext.create('Ext.draw.Component', {
41 * Ext.create('Ext.Window', {
45 * items: [drawComponent]
48 * In this case we created a draw component and added a sprite to it.
49 * The *type* of the sprite is *circle* so if you run this code you'll see a yellow-ish
50 * circle in a Window. When setting `viewBox` to `false` we are responsible for setting the object's position and
51 * dimensions accordingly.
53 * You can also add sprites by using the surface's add method:
55 * drawComponent.surface.add({
63 * For more information on Sprites, the core elements added to a draw component's surface,
64 * refer to the Ext.draw.Sprite documentation.
66 Ext.define('Ext.draw.Component', {
68 /* Begin Definitions */
72 extend: 'Ext.Component',
76 'Ext.layout.component.Draw'
81 <span id='Ext-draw-Component-cfg-enginePriority'> /**
82 </span> * @cfg {String[]} enginePriority
83 * Defines the priority order for which Surface implementation to use. The first
84 * one supported by the current environment will be used.
86 enginePriority: ['Svg', 'Vml'],
88 baseCls: Ext.baseCSSPrefix + 'surface',
90 componentLayout: 'draw',
92 <span id='Ext-draw-Component-cfg-viewBox'> /**
93 </span> * @cfg {Boolean} viewBox
94 * Turn on view box support which will scale and position items in the draw component to fit to the component while
95 * maintaining aspect ratio. Note that this scaling can override other sizing settings on yor items. Defaults to true.
99 <span id='Ext-draw-Component-cfg-autoSize'> /**
100 </span> * @cfg {Boolean} autoSize
101 * Turn on autoSize support which will set the bounding div's size to the natural size of the contents. Defaults to false.
105 <span id='Ext-draw-Component-cfg-gradients'> /**
106 </span> * @cfg {Object[]} gradients (optional) Define a set of gradients that can be used as `fill` property in sprites.
107 * The gradients array is an array of objects with the following properties:
109 * - `id` - string - The unique name of the gradient.
110 * - `angle` - number, optional - The angle of the gradient in degrees.
111 * - `stops` - object - An object with numbers as keys (from 0 to 100) and style objects as values
142 * Then the sprites can use `gradientId` and `gradientId2` by setting the fill attributes to those ids, for example:
144 * sprite.setAttributes({
145 * fill: 'url(#gradientId)'
148 initComponent: function() {
149 this.callParent(arguments);
161 <span id='Ext-draw-Component-method-onRender'> /**
164 * Create the Surface on initial render
166 onRender: function() {
168 viewBox = me.viewBox,
169 autoSize = me.autoSize,
170 bbox, items, width, height, x, y;
171 me.callParent(arguments);
173 if (me.createSurface() !== false) {
174 items = me.surface.items;
176 if (viewBox || autoSize) {
177 bbox = items.getBBox();
179 height = bbox.height;
183 me.surface.setViewBox(x, y, width, height);
187 me.autoSizeSurface();
194 autoSizeSurface: function() {
196 items = me.surface.items,
197 bbox = items.getBBox(),
199 height = bbox.height;
200 items.setAttributes({
203 //Opera has a slight offset in the y axis.
204 y: -bbox.y + (+Ext.isOpera)
208 me.setSize(width, height);
209 me.surface.setSize(width, height);
212 me.surface.setSize(width, height);
214 me.el.setSize(width, height);
217 <span id='Ext-draw-Component-method-createSurface'> /**
218 </span> * Create the Surface instance. Resolves the correct Surface implementation to
219 * instantiate based on the 'enginePriority' config. Once the Surface instance is
220 * created you can use the handle to that instance to add sprites. For example:
222 * drawComponent.surface.add(sprite);
224 createSurface: function() {
225 var surface = Ext.draw.Surface.create(Ext.apply({}, {
229 }, this.initialConfig));
231 // In case we cannot create a surface, return false so we can stop
234 this.surface = surface;
237 function refire(eventName) {
239 this.fireEvent(eventName, e);
245 mouseup: refire('mouseup'),
246 mousedown: refire('mousedown'),
247 mousemove: refire('mousemove'),
248 mouseenter: refire('mouseenter'),
249 mouseleave: refire('mouseleave'),
250 click: refire('click')
255 <span id='Ext-draw-Component-method-onDestroy'> /**
258 * Clean up the Surface instance on component destruction
260 onDestroy: function() {
261 var surface = this.surface;
265 this.callParent(arguments);