| 1 |
define(["dojo", "dojo/_base/array", "../util/oo", "./_Base", "../manager/_registry"], |
| 2 |
function(lang, array, oo, Base, registry){ |
| 3 |
|
| 4 |
var Path = oo.declare( |
| 5 |
Base, |
| 6 |
function(options){ |
| 7 |
}, |
| 8 |
{ |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
type:"dojox.drawing.stencil.Path", |
| 13 |
closePath: true, |
| 14 |
baseRender:true, |
| 15 |
closeRadius:10, |
| 16 |
closeColor:{r:255,g:255,b:0,a:.5}, |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
_create: function(shp, sty){ |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
this.remove(this[shp]); |
| 36 |
if(!this.points.length){ return; } |
| 37 |
|
| 38 |
if(dojox.gfx.renderer=="svg"){ |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
var strAr = []; |
| 43 |
array.forEach(this.points, function(o, i){ |
| 44 |
if(!o.skip){ |
| 45 |
if(i==0){ |
| 46 |
strAr.push("M " + o.x +" "+ o.y); |
| 47 |
}else{ |
| 48 |
var cmd = (o.t || "") + " "; |
| 49 |
if(o.x===undefined){ |
| 50 |
strAr.push(cmd); |
| 51 |
}else{ |
| 52 |
strAr.push(cmd + o.x +" "+ o.y); |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
}, this); |
| 57 |
if(this.closePath){ |
| 58 |
strAr.push("Z"); |
| 59 |
} |
| 60 |
|
| 61 |
this.stringPath = strAr.join(" "); |
| 62 |
|
| 63 |
this[shp] = this.container.createPath(strAr.join(" ")).setStroke(sty); |
| 64 |
this.closePath && this[shp].setFill(sty.fill); |
| 65 |
|
| 66 |
}else{ |
| 67 |
|
| 68 |
this[shp] = this.container.createPath({}).setStroke(sty); |
| 69 |
|
| 70 |
this.closePath && this[shp].setFill(sty.fill); |
| 71 |
|
| 72 |
array.forEach(this.points, function(o, i){ |
| 73 |
if(!o.skip){ |
| 74 |
if(i==0 || o.t=="M"){ |
| 75 |
this[shp].moveTo(o.x, o.y); |
| 76 |
}else if(o.t=="Z"){ |
| 77 |
this.closePath && this[shp].closePath(); |
| 78 |
}else{ |
| 79 |
this[shp].lineTo(o.x, o.y); |
| 80 |
} |
| 81 |
} |
| 82 |
}, this); |
| 83 |
|
| 84 |
this.closePath && this[shp].closePath(); |
| 85 |
} |
| 86 |
|
| 87 |
this._setNodeAtts(this[shp]); |
| 88 |
}, |
| 89 |
|
| 90 |
render: function(){ |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
this.onBeforeRender(this); |
| 97 |
this.renderHit && this._create("hit", this.style.currentHit); |
| 98 |
this._create("shape", this.style.current); |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
}, |
| 104 |
getBounds: function(absolute){ |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
var minx = 10000, miny = 10000, maxx = 0, maxy = 0; |
| 109 |
array.forEach(this.points, function(p){ |
| 110 |
if(p.x!==undefined && !isNaN(p.x)){ |
| 111 |
minx = Math.min(minx, p.x); |
| 112 |
miny = Math.min(miny, p.y); |
| 113 |
maxx = Math.max(maxx, p.x); |
| 114 |
maxy = Math.max(maxy, p.y); |
| 115 |
} |
| 116 |
}); |
| 117 |
|
| 118 |
return { |
| 119 |
x1:minx, |
| 120 |
y1:miny, |
| 121 |
x2:maxx, |
| 122 |
y2:maxy, |
| 123 |
x:minx, |
| 124 |
y:miny, |
| 125 |
w:maxx-minx, |
| 126 |
h:maxy-miny |
| 127 |
}; |
| 128 |
}, |
| 129 |
|
| 130 |
checkClosePoint: function(firstPt, currPt, remove){ |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
var dist = this.util.distance(firstPt.x, firstPt.y, currPt.x, currPt.y); |
| 141 |
if(this.points.length>1){ |
| 142 |
if(dist<this.closeRadius && !this.closeGuide && !remove){ |
| 143 |
var c = { |
| 144 |
cx:firstPt.x, |
| 145 |
cy:firstPt.y, |
| 146 |
rx:this.closeRadius, |
| 147 |
ry:this.closeRadius |
| 148 |
} |
| 149 |
this.closeGuide = this.container.createEllipse(c) |
| 150 |
.setFill(this.closeColor); |
| 151 |
|
| 152 |
}else if(remove || dist > this.closeRadius && this.closeGuide){ |
| 153 |
this.remove(this.closeGuide); |
| 154 |
this.closeGuide = null; |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
return dist < this.closeRadius; |
| 159 |
} |
| 160 |
} |
| 161 |
); |
| 162 |
|
| 163 |
lang.setObject("dojox.drawing.stencil.Path", Path); |
| 164 |
registry.register({ |
| 165 |
name:"dojox.drawing.stencil.Path" |
| 166 |
}, "stencil"); |
| 167 |
|
| 168 |
return Path; |
| 169 |
}); |