Line.js 2.6 KB

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