root / trunk / web / dojo / dojox / drawing / tools / Path.js
History | View | Annotate | Download (3.49 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.Path"]){ |
||
9 | dojo._hasResource["dojox.drawing.tools.Path"]=true; |
||
10 | dojo.provide("dojox.drawing.tools.Path");
|
||
11 | dojox.drawing.tools.Path=dojox.drawing.util.oo.declare(dojox.drawing.stencil.Path,function(){
|
||
12 | this.pathMode=""; |
||
13 | this.currentPathMode=""; |
||
14 | this._started=false; |
||
15 | this.oddEvenClicks=0; |
||
16 | },{draws:true,onDown:function(_1){ |
||
17 | if(!this._started){ |
||
18 | this.onStartPath(_1);
|
||
19 | } |
||
20 | },makeSubPath:function(_2){ |
||
21 | if(_2){
|
||
22 | if(this.currentPathMode=="Q"){ |
||
23 | this.points.push({x:this.points[0].x,y:this.points[0].y}); |
||
24 | } |
||
25 | this.points.push({t:"Z"}); |
||
26 | this.render();
|
||
27 | } |
||
28 | this.currentPathMode=""; |
||
29 | this.pathMode="M"; |
||
30 | },onStartPath:function(_3){ |
||
31 | this._started=true; |
||
32 | this.revertRenderHit=this.renderHit; |
||
33 | this.renderHit=false; |
||
34 | this.closePath=false; |
||
35 | this.mouse.setEventMode("PathEdit"); |
||
36 | this.closePoint={x:_3.x,y:_3.y}; |
||
37 | this._kc1=this.connect(this.keys,"onEsc",this,function(){ |
||
38 | this.onCompletePath(false); |
||
39 | }); |
||
40 | this._kc2=this.connect(this.keys,"onKeyUp",this,function(_4){ |
||
41 | switch(_4.letter){
|
||
42 | case "c": |
||
43 | this.onCompletePath(true); |
||
44 | break;
|
||
45 | case "l": |
||
46 | this.pathMode="L"; |
||
47 | break;
|
||
48 | case "m": |
||
49 | this.makeSubPath(false); |
||
50 | break;
|
||
51 | case "q": |
||
52 | this.pathMode="Q"; |
||
53 | break;
|
||
54 | case "s": |
||
55 | this.pathMode="S"; |
||
56 | break;
|
||
57 | case "z": |
||
58 | this.makeSubPath(true); |
||
59 | break;
|
||
60 | } |
||
61 | }); |
||
62 | },onCompletePath:function(_5){ |
||
63 | this.remove(this.closeGuide,this.guide); |
||
64 | var _6=this.getBounds(); |
||
65 | if(_6.w<this.minimumSize&&_6.h<this.minimumSize){ |
||
66 | this.remove(this.hit,this.shape,this.closeGuide); |
||
67 | this._started=false; |
||
68 | this.mouse.setEventMode(""); |
||
69 | this.setPoints([]);
|
||
70 | return;
|
||
71 | } |
||
72 | if(_5){
|
||
73 | if(this.currentPathMode=="Q"){ |
||
74 | this.points.push({x:this.points[0].x,y:this.points[0].y}); |
||
75 | } |
||
76 | this.closePath=true; |
||
77 | } |
||
78 | this.renderHit=this.revertRenderHit; |
||
79 | this.renderedOnce=true; |
||
80 | this.onRender(this); |
||
81 | this.disconnect([this._kc1,this._kc2]); |
||
82 | this.mouse.setEventMode(""); |
||
83 | this.render();
|
||
84 | },onUp:function(_7){ |
||
85 | if(!this._started||!_7.withinCanvas){ |
||
86 | return;
|
||
87 | } |
||
88 | if(this.points.length>2&&this.closeRadius>this.util.distance(_7.x,_7.y,this.closePoint.x,this.closePoint.y)){ |
||
89 | this.onCompletePath(true); |
||
90 | }else{
|
||
91 | var p={x:_7.x,y:_7.y}; |
||
92 | this.oddEvenClicks++;
|
||
93 | if(this.currentPathMode!=this.pathMode){ |
||
94 | if(this.pathMode=="Q"){ |
||
95 | p.t="Q";
|
||
96 | this.oddEvenClicks=0; |
||
97 | }else{
|
||
98 | if(this.pathMode=="L"){ |
||
99 | p.t="L";
|
||
100 | }else{
|
||
101 | if(this.pathMode=="M"){ |
||
102 | p.t="M";
|
||
103 | this.closePoint={x:_7.x,y:_7.y}; |
||
104 | } |
||
105 | } |
||
106 | } |
||
107 | this.currentPathMode=this.pathMode; |
||
108 | } |
||
109 | this.points.push(p);
|
||
110 | if(this.points.length>1){ |
||
111 | this.remove(this.guide); |
||
112 | this.render();
|
||
113 | } |
||
114 | } |
||
115 | },createGuide:function(_8){ |
||
116 | if(!this.points.length){ |
||
117 | return;
|
||
118 | } |
||
119 | var _9=[].concat(this.points); |
||
120 | var pt={x:_8.x,y:_8.y}; |
||
121 | if(this.currentPathMode=="Q"&&this.oddEvenClicks%2){ |
||
122 | pt.t="L";
|
||
123 | } |
||
124 | this.points.push(pt);
|
||
125 | this.render();
|
||
126 | this.points=_9;
|
||
127 | var _a=this.util.distance(_8.x,_8.y,this.closePoint.x,this.closePoint.y); |
||
128 | if(this.points.length>1){ |
||
129 | if(_a<this.closeRadius&&!this.closeGuide){ |
||
130 | var c={cx:this.closePoint.x,cy:this.closePoint.y,rx:this.closeRadius,ry:this.closeRadius}; |
||
131 | this.closeGuide=this.container.createEllipse(c).setFill(this.closeColor); |
||
132 | }else{
|
||
133 | if(_a>this.closeRadius&&this.closeGuide){ |
||
134 | this.remove(this.closeGuide); |
||
135 | this.closeGuide=null; |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 | },onMove:function(_b){ |
||
140 | if(!this._started){ |
||
141 | return;
|
||
142 | } |
||
143 | this.createGuide(_b);
|
||
144 | },onDrag:function(_c){ |
||
145 | if(!this._started){ |
||
146 | return;
|
||
147 | } |
||
148 | this.createGuide(_c);
|
||
149 | }}); |
||
150 | dojox.drawing.tools.Path.setup={name:"dojox.drawing.tools.Path",tooltip:"Path Tool",iconClass:"iconLine"}; |
||
151 | dojox.drawing.register(dojox.drawing.tools.Path.setup,"tool");
|
||
152 | } |