Line.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.drawing.tools.Line"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.drawing.tools.Line"] = true;
  8. dojo.provide("dojox.drawing.tools.Line");
  9. dojox.drawing.tools.Line = dojox.drawing.util.oo.declare(
  10. // summary:
  11. // Class for a drawable Line
  12. dojox.drawing.stencil.Line,
  13. function(){
  14. // summary: constructor
  15. },
  16. {
  17. draws:true,
  18. showAngle:true,
  19. onTransformEnd: function(/*manager.Anchor*/anchor){
  20. // summary:
  21. // Overwrites _Base.onTransformEnd
  22. //
  23. this._toggleSelected();
  24. if(this.getRadius()<this.minimumSize){
  25. var p = this.points;
  26. this.setPoints([
  27. {x:p[0].x, y:p[0].y},
  28. {x:p[0].x, y:p[0].y}
  29. ]);
  30. }else{
  31. var d = this.data;
  32. var obj = {start:{x:d.x1,y:d.y1},x:d.x2,y:d.y2};
  33. var pt = this.util.snapAngle(obj, this.angleSnap/180);
  34. this.setPoints([
  35. {x:d.x1, y:d.y1},
  36. {x:pt.x, y:pt.y}
  37. ]);
  38. this._isBeingModified = false;
  39. this.onModify(this);
  40. }
  41. },
  42. onDrag: function(/*EventObject*/obj){
  43. // summary: See stencil._Base.onDrag
  44. //
  45. if(this.created){ return; }
  46. var x1 = obj.start.x,
  47. y1 = obj.start.y,
  48. x2 = obj.x,
  49. y2 = obj.y;
  50. if(this.keys.shift){
  51. var pt = this.util.snapAngle(obj, 45/180);
  52. x2 = pt.x;
  53. y2 = pt.y;
  54. }
  55. if(this.keys.alt){
  56. // FIXME:
  57. // should double the length of the line
  58. // FIXME:
  59. // if alt dragging past ZERO it seems to work
  60. // but select/deselect shows bugs
  61. var dx = x2>x1 ? ((x2-x1)/2) : ((x1-x2)/-2);
  62. var dy = y2>y1 ? ((y2-y1)/2) : ((y1-y2)/-2);
  63. x1 -= dx;
  64. x2 -= dx;
  65. y1 -= dy;
  66. y2 -= dy;
  67. }
  68. this.setPoints([
  69. {x:x1, y:y1},
  70. {x:x2, y:y2}
  71. ]);
  72. this.render();
  73. },
  74. onUp: function(/*EventObject*/obj){
  75. // summary: See stencil._Base.onUp
  76. //
  77. if(this.created || !this._downOnCanvas){ return; }
  78. this._downOnCanvas = false;
  79. //Default shape on single click
  80. if(!this.shape){
  81. var s = obj.start, e = this.minimumSize*4;
  82. this.setPoints([
  83. {x:s.x, y:s.y+e},
  84. {x:s.x, y:s.y}
  85. ]);
  86. this.render();
  87. }else{
  88. // if too small, need to reset
  89. if(this.getRadius()<this.minimumSize){
  90. this.remove(this.shape, this.hit);
  91. return;
  92. }
  93. }
  94. var pt = this.util.snapAngle(obj, this.angleSnap/180);
  95. var p = this.points;
  96. this.setPoints([
  97. {x:p[0].x, y:p[0].y},
  98. {x:pt.x, y:pt.y}
  99. ]);
  100. this.renderedOnce = true;
  101. this.onRender(this);
  102. }
  103. }
  104. );
  105. dojox.drawing.tools.Line.setup = {
  106. // summary: See stencil._Base ToolsSetup
  107. //
  108. name:"dojox.drawing.tools.Line",
  109. tooltip:"Line Tool",
  110. iconClass:"iconLine"
  111. };
  112. dojox.drawing.register(dojox.drawing.tools.Line.setup, "tool");
  113. }