root / trunk / web / dojo / dojox / drawing / tools / Ellipse.js @ 13
History | View | Annotate | Download (1.36 KB)
| 1 | 9 | andrej.cim | /*
|
|---|---|---|---|
| 2 | Copyright (c) 2004-2010, 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 | |||
| 7 | |||
| 8 | if(!dojo._hasResource["dojox.drawing.tools.Ellipse"]){ |
||
| 9 | dojo._hasResource["dojox.drawing.tools.Ellipse"]=true; |
||
| 10 | dojo.provide("dojox.drawing.tools.Ellipse");
|
||
| 11 | dojox.drawing.tools.Ellipse=dojox.drawing.util.oo.declare(dojox.drawing.stencil.Ellipse,function(){
|
||
| 12 | },{draws:true,onDrag:function(_1){
|
||
| 13 | var s=_1.start,e=_1;
|
||
| 14 | var x=s.x<e.x?s.x:e.x,y=s.y<e.y?s.y:e.y,w=s.x<e.x?e.x-s.x:s.x-e.x,h=s.y<e.y?e.y-s.y:s.y-e.y;
|
||
| 15 | if(this.keys.shift){ |
||
| 16 | w=h=Math.max(w,h); |
||
| 17 | } |
||
| 18 | if(!this.keys.alt){ |
||
| 19 | x+=w/2;
|
||
| 20 | y+=h/2;
|
||
| 21 | w/=2;
|
||
| 22 | h/=2;
|
||
| 23 | }else{
|
||
| 24 | if(y-h<0){ |
||
| 25 | h=y; |
||
| 26 | } |
||
| 27 | if(x-w<0){ |
||
| 28 | w=x; |
||
| 29 | } |
||
| 30 | } |
||
| 31 | this.points=[{x:x-w,y:y-h},{x:x+w,y:y-h},{x:x+w,y:y+h},{x:x-w,y:y+h}]; |
||
| 32 | this.render();
|
||
| 33 | },onUp:function(_2){ |
||
| 34 | if(this.created||!this._downOnCanvas){ |
||
| 35 | return;
|
||
| 36 | } |
||
| 37 | this._downOnCanvas=false; |
||
| 38 | if(!this.shape){ |
||
| 39 | var s=_2.start,e=this.minimumSize*2; |
||
| 40 | this.data={cx:s.x+e,cy:s.y+e,rx:e,ry:e}; |
||
| 41 | this.dataToPoints();
|
||
| 42 | this.render();
|
||
| 43 | }else{
|
||
| 44 | var o=this.pointsToData(); |
||
| 45 | if(o.rx*2<this.minimumSize&&o.ry*2<this.minimumSize){ |
||
| 46 | this.remove(this.shape,this.hit); |
||
| 47 | return;
|
||
| 48 | } |
||
| 49 | } |
||
| 50 | this.onRender(this); |
||
| 51 | }}); |
||
| 52 | dojox.drawing.tools.Ellipse.setup={name:"dojox.drawing.tools.Ellipse",tooltip:"Ellipse Tool",iconClass:"iconEllipse"};
|
||
| 53 | dojox.drawing.register(dojox.drawing.tools.Ellipse.setup,"tool");
|
||
| 54 | } |