Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / docs / source / SpriteDD.html
1 <!DOCTYPE html>
2 <html>
3 <head>
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; }
10   </style>
11   <script type="text/javascript">
12     function highlight() {
13       document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
14     }
15   </script>
16 </head>
17 <body onload="prettyPrint(); highlight();">
18   <pre class="prettyprint lang-js">// private - DD implementation for Panels
19 Ext.define('Ext.draw.SpriteDD', {
20     extend: 'Ext.dd.DragSource',
21
22     constructor : function(sprite, cfg){
23         var me = this,
24             el = sprite.el;
25         me.sprite = sprite;
26         me.el = el;
27         me.dragData = {el: el, sprite: sprite};
28         me.callParent([el, cfg]);
29         me.sprite.setStyle('cursor', 'move');
30     },
31
32     showFrame: Ext.emptyFn,
33     createFrame : Ext.emptyFn,
34
35     getDragEl : function(e){
36         return this.el;
37     },
38     
39     getRegion: function() {
40         var me = this,
41             el = me.el,
42             pos, x1, x2, y1, y2, t, r, b, l, bbox, sprite;
43         
44         sprite = me.sprite;
45         bbox = sprite.getBBox();
46         
47         try {
48             pos = Ext.Element.getXY(el);
49         } catch (e) { }
50
51         if (!pos) {
52             return null;
53         }
54
55         x1 = pos[0];
56         x2 = x1 + bbox.width;
57         y1 = pos[1];
58         y2 = y1 + bbox.height;
59         
60         return Ext.create('Ext.util.Region', y1, x2, y2, x1);
61     },
62
63     /*
64       TODO(nico): Cumulative translations in VML are handled
65       differently than in SVG. While in SVG we specify the translation
66       relative to the original x, y position attributes, in VML the translation
67       is a delta between the last position of the object (modified by the last
68       translation) and the new one.
69       
70       In VML the translation alters the position
71       of the object, we should change that or alter the SVG impl.
72     */
73      
74     startDrag: function(x, y) {
75         var me = this,
76             attr = me.sprite.attr;
77         me.prev = me.sprite.surface.transformToViewBox(x, y);
78     },
79
80     onDrag: function(e) {
81         var xy = e.getXY(),
82             me = this,
83             sprite = me.sprite,
84             attr = sprite.attr, dx, dy;
85         xy = me.sprite.surface.transformToViewBox(xy[0], xy[1]);
86         dx = xy[0] - me.prev[0];
87         dy = xy[1] - me.prev[1];
88         sprite.setAttributes({
89             translate: {
90                 x: attr.translation.x + dx,
91                 y: attr.translation.y + dy
92             }
93         }, true);
94         me.prev = xy;
95     },
96
97     setDragElPos: function () {
98         // Disable automatic DOM move in DD that spoils layout of VML engine.
99         return false;
100     }
101 });</pre>
102 </body>
103 </html>