Ellipse.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.Ellipse"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.drawing.tools.Ellipse"] = true;
  8. dojo.provide("dojox.drawing.tools.Ellipse");
  9. dojox.drawing.tools.Ellipse = dojox.drawing.util.oo.declare(
  10. // summary:
  11. // A drawable Ellipse.
  12. //
  13. dojox.drawing.stencil.Ellipse,
  14. function(){
  15. // summary: constructor
  16. },
  17. {
  18. draws:true,
  19. onDrag: function(/*EventObject*/obj){
  20. // summary: See stencil._Base.onDrag
  21. //
  22. var s = obj.start, e = obj;
  23. var x = s.x < e.x ? s.x : e.x,
  24. y = s.y < e.y ? s.y : e.y,
  25. w = s.x < e.x ? e.x-s.x : s.x-e.x,
  26. h = s.y < e.y ? e.y-s.y : s.y-e.y;
  27. if(this.keys.shift){ w = h = Math.max(w,h); }
  28. if(!this.keys.alt){ // ellipse is normally on center
  29. x+=w/2; y+=h/2; w/=2; h/=2;
  30. } else{
  31. if(y - h < 0){ h = y; }
  32. if(x - w < 0){ w = x; }
  33. }
  34. this.points = [
  35. {x:x-w, y:y-h}, // TL
  36. {x:x+w, y:y-h}, // TR
  37. {x:x+w, y:y+h}, // BR
  38. {x:x-w, y:y+h} // BL
  39. ];
  40. this.render();
  41. },
  42. onUp: function(/*EventObject*/obj){
  43. // summary: See stencil._Base.onUp
  44. //
  45. if(this.created || !this._downOnCanvas){ return; }
  46. this._downOnCanvas = false;
  47. //Default shape on single click
  48. if(!this.shape){
  49. var s = obj.start, e = this.minimumSize*2;
  50. this.data = {
  51. cx: s.x+e,
  52. cy: s.y+e,
  53. rx: e,
  54. ry: e
  55. };
  56. this.dataToPoints();
  57. this.render();
  58. }else{
  59. // if too small, need to reset
  60. var o = this.pointsToData();
  61. console.log("Create a default shape here, pt to data: ",o);
  62. if(o.rx*2<this.minimumSize && o.ry*2 < this.minimumSize){
  63. this.remove(this.shape, this.hit);
  64. return;
  65. }
  66. }
  67. this.onRender(this);
  68. }
  69. }
  70. );
  71. dojox.drawing.tools.Ellipse.setup = {
  72. // summary: See stencil._Base ToolsSetup
  73. //
  74. name:"dojox.drawing.tools.Ellipse",
  75. tooltip:"Ellipse Tool",
  76. iconClass:"iconEllipse"
  77. };
  78. dojox.drawing.register(dojox.drawing.tools.Ellipse.setup, "tool");
  79. }