| 1 |
define([ |
| 2 |
"dojo/_base/kernel", |
| 3 |
"dojo/_base/lang", |
| 4 |
"../gfx" |
| 5 |
], function(dojo){ |
| 6 |
dojo.getObject("sketch", true, dojox); |
| 7 |
|
| 8 |
dojox.sketch.Anchor=function(an, id, isControl){ |
| 9 |
var self=this; |
| 10 |
var size=4; |
| 11 |
var rect=null; |
| 12 |
|
| 13 |
this.type=function(){ return "Anchor"; }; |
| 14 |
this.annotation=an; |
| 15 |
|
| 16 |
this.id=id; |
| 17 |
this._key="anchor-" + dojox.sketch.Anchor.count++; |
| 18 |
this.shape=null; |
| 19 |
this.isControl=(isControl!=null)?isControl:true; |
| 20 |
|
| 21 |
this.beginEdit=function(){ |
| 22 |
this.annotation.beginEdit(dojox.sketch.CommandTypes.Modify); |
| 23 |
}; |
| 24 |
this.endEdit=function(){ |
| 25 |
this.annotation.endEdit(); |
| 26 |
}; |
| 27 |
this.zoom=function(pct){ |
| 28 |
if(this.shape){ |
| 29 |
var rs=Math.floor(size/pct); |
| 30 |
var width=dojox.gfx.renderer=='vml'?1:1/pct |
| 31 |
this.shape.setShape({ x:an[id].x-rs, y:an[id].y-rs, width:rs*2, height:rs*2 }).setStroke({ color:"black", width:width }); |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
this.setBinding=function(pt){ |
| 43 |
an[id]={ x: an[id].x+pt.dx, y:an[id].y+pt.dy }; |
| 44 |
an.draw(); |
| 45 |
an.drawBBox(); |
| 46 |
}; |
| 47 |
this.setUndo=function(){ an.setUndo(); }; |
| 48 |
|
| 49 |
this.enable=function(){ |
| 50 |
if(!an.shape){ return; } |
| 51 |
an.figure._add(this); |
| 52 |
rect={ x:an[id].x-size, y:an[id].y-size, width:size*2, height:size*2 }; |
| 53 |
this.shape=an.shape.createRect(rect) |
| 54 |
|
| 55 |
.setFill([255,255,255,0.35]); |
| 56 |
this.shape.getEventSource().setAttribute("id", self._key); |
| 57 |
this.shape.getEventSource().setAttribute("shape-rendering", "crispEdges"); |
| 58 |
this.zoom(an.figure.zoomFactor); |
| 59 |
}; |
| 60 |
this.disable=function(){ |
| 61 |
an.figure._remove(this); |
| 62 |
if(an.shape){ an.shape.remove(this.shape); } |
| 63 |
this.shape=null; |
| 64 |
rect=null; |
| 65 |
}; |
| 66 |
}; |
| 67 |
dojox.sketch.Anchor.count=0; |
| 68 |
return dojox.sketch.Anchor; |
| 69 |
}); |