root / trunk / web / dojo / dojox / drawing / tools / Line.js
History | View | Annotate | Download (1.84 KB)
1 |
/*
|
---|---|
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.Line"]){ |
9 |
dojo._hasResource["dojox.drawing.tools.Line"]=true; |
10 |
dojo.provide("dojox.drawing.tools.Line");
|
11 |
dojox.drawing.tools.Line=dojox.drawing.util.oo.declare(dojox.drawing.stencil.Line,function(){
|
12 |
},{draws:true,showAngle:true,onTransformEnd:function(_1){ |
13 |
this._toggleSelected();
|
14 |
if(this.getRadius()<this.minimumSize){ |
15 |
var p=this.points; |
16 |
this.setPoints([{x:p[0].x,y:p[0].y},{x:p[0].x,y:p[0].y}]); |
17 |
}else{
|
18 |
var d=this.data; |
19 |
var _2={start:{x:d.x1,y:d.y1},x:d.x2,y:d.y2}; |
20 |
var pt=this.util.snapAngle(_2,this.angleSnap/180); |
21 |
this.setPoints([{x:d.x1,y:d.y1},{x:pt.x,y:pt.y}]); |
22 |
this._isBeingModified=false; |
23 |
this.onModify(this); |
24 |
} |
25 |
},onDrag:function(_3){ |
26 |
if(this.created){ |
27 |
return;
|
28 |
} |
29 |
var x1=_3.start.x,y1=_3.start.y,x2=_3.x,y2=_3.y;
|
30 |
if(this.keys.shift){ |
31 |
var pt=this.util.snapAngle(_3,45/180); |
32 |
x2=pt.x; |
33 |
y2=pt.y; |
34 |
} |
35 |
if(this.keys.alt){ |
36 |
var dx=x2>x1?((x2-x1)/2):((x1-x2)/-2); |
37 |
var dy=y2>y1?((y2-y1)/2):((y1-y2)/-2); |
38 |
x1-=dx; |
39 |
x2-=dx; |
40 |
y1-=dy; |
41 |
y2-=dy; |
42 |
} |
43 |
this.setPoints([{x:x1,y:y1},{x:x2,y:y2}]); |
44 |
this.render();
|
45 |
},onUp:function(_4){ |
46 |
if(this.created||!this._downOnCanvas){ |
47 |
return;
|
48 |
} |
49 |
this._downOnCanvas=false; |
50 |
if(!this.shape){ |
51 |
var s=_4.start,e=this.minimumSize*4; |
52 |
this.setPoints([{x:s.x,y:s.y+e},{x:s.x,y:s.y}]); |
53 |
this.render();
|
54 |
}else{
|
55 |
if(this.getRadius()<this.minimumSize){ |
56 |
this.remove(this.shape,this.hit); |
57 |
return;
|
58 |
} |
59 |
} |
60 |
var pt=this.util.snapAngle(_4,this.angleSnap/180); |
61 |
var p=this.points; |
62 |
this.setPoints([{x:p[0].x,y:p[0].y},{x:pt.x,y:pt.y}]); |
63 |
this.renderedOnce=true; |
64 |
this.onRender(this); |
65 |
}}); |
66 |
dojox.drawing.tools.Line.setup={name:"dojox.drawing.tools.Line",tooltip:"Line Tool",iconClass:"iconLine"}; |
67 |
dojox.drawing.register(dojox.drawing.tools.Line.setup,"tool");
|
68 |
} |