Rect.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // wrapped by build app
  2. define("dojox/drawing/tools/Rect", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.drawing.tools.Rect");
  4. dojox.drawing.tools.Rect = dojox.drawing.util.oo.declare(
  5. // summary:
  6. // Class for a drawable rectangle
  7. //
  8. dojox.drawing.stencil.Rect,
  9. function(){
  10. // summary: constructor
  11. },
  12. {
  13. draws:true,
  14. onDrag: function(/*EventObject*/obj){
  15. // summary: See stencil._Base.onDrag
  16. //
  17. var s = obj.start, e = obj;
  18. var x = s.x < e.x ? s.x : e.x,
  19. y = s.y < e.y ? s.y : e.y,
  20. w = s.x < e.x ? e.x-s.x : s.x-e.x,
  21. h = s.y < e.y ? e.y-s.y : s.y-e.y;
  22. if(this.keys.shift){ w = h = Math.max(w,h); }
  23. if(this.keys.alt){
  24. x-=w; y-=h; w*=2; h*=2;
  25. x = Math.max(x, 0);
  26. y = Math.max(y, 0);
  27. }
  28. this.setPoints ([
  29. {x:x, y:y}, // TL
  30. {x:x+w, y:y}, // TR
  31. {x:x+w, y:y+h}, // BR
  32. {x:x, y:y+h} // BL
  33. ]);
  34. this.render();
  35. },
  36. onUp: function(/*EventObject*/obj){
  37. // summary: See stencil._Base.onUp
  38. //
  39. if(this.created || !this._downOnCanvas){ return; }
  40. this._downOnCanvas = false;
  41. //Default shape on single click
  42. if(!this.shape){
  43. var s = obj.start;
  44. var e = this.minimumSize*4;
  45. this.setPoints([
  46. {x:s.x, y:s.y},
  47. {x:s.x+e, y:s.y},
  48. {x:s.x+e, y:s.y+e},
  49. {x:s.x, y:s.y+e}
  50. ]);
  51. this.render();
  52. }else{
  53. // if too small, need to reset
  54. var o = this.data;
  55. if(o.width<this.minimumSize && o.height < this.minimumSize){
  56. this.remove(this.shape, this.hit);
  57. return;
  58. }
  59. }
  60. this.onRender(this);
  61. }
  62. }
  63. );
  64. dojox.drawing.tools.Rect.setup = {
  65. // summary: See stencil._Base ToolsSetup
  66. //
  67. name:"dojox.drawing.tools.Rect",
  68. tooltip:'<span class="drawingTipTitle">Rectangle Tool</span><br/>'
  69. + '<span class="drawingTipDesc">SHIFT - constrain to square</span>',
  70. iconClass:"iconRect"
  71. };
  72. dojox.drawing.register(dojox.drawing.tools.Rect.setup, "tool");
  73. });