Anchor.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Copyright (c) 2004-2012, 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. if(!dojo._hasResource["dojox.sketch.Anchor"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.sketch.Anchor"] = true;
  8. dojo.provide("dojox.sketch.Anchor");
  9. dojo.require("dojox.gfx");
  10. (function(){
  11. var ta=dojox.sketch;
  12. ta.Anchor=function(an, id, isControl){
  13. var self=this;
  14. var size=4; // .5 * size of anchor.
  15. var rect=null;
  16. this.type=function(){ return "Anchor"; };
  17. this.annotation=an;
  18. this.id=id;
  19. this._key="anchor-" + ta.Anchor.count++;
  20. this.shape=null;
  21. this.isControl=(isControl!=null)?isControl:true;
  22. this.beginEdit=function(){
  23. this.annotation.beginEdit(ta.CommandTypes.Modify);
  24. };
  25. this.endEdit=function(){
  26. this.annotation.endEdit();
  27. };
  28. this.zoom=function(pct){
  29. if(this.shape){
  30. var rs=Math.floor(size/pct);
  31. var width=dojox.gfx.renderer=='vml'?1:1/pct
  32. 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
  33. }
  34. }
  35. /*this.doChange=function(pt){
  36. if(this.isControl){
  37. this.shape.applyTransform(pt);
  38. } else{
  39. an.transform.dx+=pt.dx;
  40. an.transform.dy+=pt.dy;
  41. }
  42. };*/
  43. this.setBinding=function(pt){
  44. an[id]={ x: an[id].x+pt.dx, y:an[id].y+pt.dy };
  45. an.draw();
  46. an.drawBBox();
  47. };
  48. this.setUndo=function(){ an.setUndo(); };
  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. //.setStroke({ color:"black", width:1 })
  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. ta.Anchor.count=0;
  68. })();
  69. }