SpriteDD.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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"><span id='Ext-draw-SpriteDD'>/**
  19. </span> * DD implementation for Panels.
  20. * @private
  21. */
  22. Ext.define('Ext.draw.SpriteDD', {
  23. extend: 'Ext.dd.DragSource',
  24. constructor : function(sprite, cfg){
  25. var me = this,
  26. el = sprite.el;
  27. me.sprite = sprite;
  28. me.el = el;
  29. me.dragData = {el: el, sprite: sprite};
  30. me.callParent([el, cfg]);
  31. me.sprite.setStyle('cursor', 'move');
  32. },
  33. showFrame: Ext.emptyFn,
  34. createFrame : Ext.emptyFn,
  35. getDragEl : function(e){
  36. return this.el;
  37. },
  38. getRegion: function() {
  39. var me = this,
  40. el = me.el,
  41. pos, x1, x2, y1, y2, t, r, b, l, bbox, sprite;
  42. sprite = me.sprite;
  43. bbox = sprite.getBBox();
  44. try {
  45. pos = Ext.Element.getXY(el);
  46. } catch (e) { }
  47. if (!pos) {
  48. return null;
  49. }
  50. x1 = pos[0];
  51. x2 = x1 + bbox.width;
  52. y1 = pos[1];
  53. y2 = y1 + bbox.height;
  54. return new Ext.util.Region(y1, x2, y2, x1);
  55. },
  56. /*
  57. TODO(nico): Cumulative translations in VML are handled
  58. differently than in SVG. While in SVG we specify the translation
  59. relative to the original x, y position attributes, in VML the translation
  60. is a delta between the last position of the object (modified by the last
  61. translation) and the new one.
  62. In VML the translation alters the position
  63. of the object, we should change that or alter the SVG impl.
  64. */
  65. startDrag: function(x, y) {
  66. var me = this,
  67. attr = me.sprite.attr;
  68. me.prev = me.sprite.surface.transformToViewBox(x, y);
  69. },
  70. onDrag: function(e) {
  71. var xy = e.getXY(),
  72. me = this,
  73. sprite = me.sprite,
  74. attr = sprite.attr, dx, dy;
  75. xy = me.sprite.surface.transformToViewBox(xy[0], xy[1]);
  76. dx = xy[0] - me.prev[0];
  77. dy = xy[1] - me.prev[1];
  78. sprite.setAttributes({
  79. translate: {
  80. x: attr.translation.x + dx,
  81. y: attr.translation.y + dy
  82. }
  83. }, true);
  84. me.prev = xy;
  85. },
  86. setDragElPos: function () {
  87. // Disable automatic DOM move in DD that spoils layout of VML engine.
  88. return false;
  89. }
  90. });</pre>
  91. </body>
  92. </html>