Anchor.js 1.9 KB

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