root / trunk / web / dojo / dojox / drawing / tools / Rect.js @ 10
History | View | Annotate | Download (1.45 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.Rect"]){ |
||
| 9 | dojo._hasResource["dojox.drawing.tools.Rect"]=true; |
||
| 10 | dojo.provide("dojox.drawing.tools.Rect");
|
||
| 11 | dojox.drawing.tools.Rect=dojox.drawing.util.oo.declare(dojox.drawing.stencil.Rect,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; |
||
| 20 | y-=h; |
||
| 21 | w*=2;
|
||
| 22 | h*=2;
|
||
| 23 | x=Math.max(x,0);
|
||
| 24 | y=Math.max(y,0);
|
||
| 25 | } |
||
| 26 | this.setPoints([{x:x,y:y},{x:x+w,y:y},{x:x+w,y:y+h},{x:x,y:y+h}]); |
||
| 27 | this.render();
|
||
| 28 | },onUp:function(_2){ |
||
| 29 | if(this.created||!this._downOnCanvas){ |
||
| 30 | return;
|
||
| 31 | } |
||
| 32 | this._downOnCanvas=false; |
||
| 33 | if(!this.shape){ |
||
| 34 | var s=_2.start;
|
||
| 35 | var e=this.minimumSize*4; |
||
| 36 | this.setPoints([{x:s.x,y:s.y},{x:s.x+e,y:s.y},{x:s.x+e,y:s.y+e},{x:s.x,y:s.y+e}]); |
||
| 37 | this.render();
|
||
| 38 | }else{
|
||
| 39 | var o=this.data; |
||
| 40 | if(o.width<this.minimumSize&&o.height<this.minimumSize){ |
||
| 41 | this.remove(this.shape,this.hit); |
||
| 42 | return;
|
||
| 43 | } |
||
| 44 | } |
||
| 45 | this.onRender(this); |
||
| 46 | }}); |
||
| 47 | dojox.drawing.tools.Rect.setup={name:"dojox.drawing.tools.Rect",tooltip:"<span class=\"drawingTipTitle\">Rectangle Tool</span><br/>"+"<span class=\"drawingTipDesc\">SHIFT - constrain to square</span>",iconClass:"iconRect"};
|
||
| 48 | dojox.drawing.register(dojox.drawing.tools.Rect.setup,"tool");
|
||
| 49 | } |