Ellipse.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // wrapped by build app
  2. define("dojox/drawing/tools/Ellipse", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.drawing.tools.Ellipse");
  4. dojox.drawing.tools.Ellipse = dojox.drawing.util.oo.declare(
  5. // summary:
  6. // A drawable Ellipse.
  7. //
  8. dojox.drawing.stencil.Ellipse,
  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){ // ellipse is normally on center
  24. x+=w/2; y+=h/2; w/=2; h/=2;
  25. } else{
  26. if(y - h < 0){ h = y; }
  27. if(x - w < 0){ w = x; }
  28. }
  29. this.points = [
  30. {x:x-w, y:y-h}, // TL
  31. {x:x+w, y:y-h}, // TR
  32. {x:x+w, y:y+h}, // BR
  33. {x:x-w, y:y+h} // BL
  34. ];
  35. this.render();
  36. },
  37. onUp: function(/*EventObject*/obj){
  38. // summary: See stencil._Base.onUp
  39. //
  40. if(this.created || !this._downOnCanvas){ return; }
  41. this._downOnCanvas = false;
  42. //Default shape on single click
  43. if(!this.shape){
  44. var s = obj.start, e = this.minimumSize*2;
  45. this.data = {
  46. cx: s.x+e,
  47. cy: s.y+e,
  48. rx: e,
  49. ry: e
  50. };
  51. this.dataToPoints();
  52. this.render();
  53. }else{
  54. // if too small, need to reset
  55. var o = this.pointsToData();
  56. console.log("Create a default shape here, pt to data: ",o);
  57. if(o.rx*2<this.minimumSize && o.ry*2 < this.minimumSize){
  58. this.remove(this.shape, this.hit);
  59. return;
  60. }
  61. }
  62. this.onRender(this);
  63. }
  64. }
  65. );
  66. dojox.drawing.tools.Ellipse.setup = {
  67. // summary: See stencil._Base ToolsSetup
  68. //
  69. name:"dojox.drawing.tools.Ellipse",
  70. tooltip:"Ellipse Tool",
  71. iconClass:"iconEllipse"
  72. };
  73. dojox.drawing.register(dojox.drawing.tools.Ellipse.setup, "tool");
  74. });