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