//>>built define("dojox/sketch/Figure", [ "dojo/_base/kernel", "dojo/_base/lang", "dojo/_base/connect", "dojo/_base/html", "../gfx", "../xml/DomParser", "./UndoStack" ], function(dojo){ dojo.experimental("dojox.sketch"); var ta=dojox.sketch; ta.tools={}; ta.registerTool=function(type, fn){ ta.tools[type]=fn; }; ta.Figure = function(mixin){ var self=this; this.annCounter=1; this.shapes=[]; this.image=null; this.imageSrc=null; this.size={ w:0, h:0 }; this.surface=null; this.group=null; //node should have tabindex set, otherwise keyboard action does not work this.node=null; this.zoomFactor=1; // multiplier for zooming. this.tools=null; // toolbar reference. this.obj={}; // lookup table for shapes. Not keen on this solution. dojo.mixin(this,mixin); // what is selected. this.selected=[]; this.hasSelections=function(){ return this.selected.length>0 }; this.isSelected=function(obj){ for(var i=0; i-1){ obj.setMode(ta.Annotation.Modes.View); self.selected.splice(idx,1); } return obj; }; this.clearSelections=function(){ for(var i=0; i-1){ self.selected.splice(idx,1,n); } }; // for the drag and drop handlers. this._c=null; // current shape this._ctr=null; // container measurements this._lp=null; // last position this._action=null; this._prevState=null; this._startPoint=null; // test to record a move. // if an object isn't selected and we're dragging anyways. this._ctool=null; // hard code it. this._start=null; this._end=null; this._absEnd=null; this._cshape=null; this._dblclick=function(e){ var o=self._fromEvt(e); if(o){ self.onDblClickShape(o,e); } }; this._keydown=function(e){ var prevent=false; if(e.ctrlKey){ if(e.keyCode===90 || e.keyCode===122){ //ctrl+z self.undo(); prevent = true; } else if(e.keyCode===89 || e.keyCode===121){ //ctrl+y self.redo(); prevent = true; } } if(e.keyCode===46 || e.keyCode===8){ //delete or backspace self._delete(self.selected); prevent = true; } if(prevent){ dojo.stopEvent(e); } }; // drag handlers. this._md=function(e){ //in IE, when clicking into the drawing canvas, the node does not get focused, //do it manually here to force it, otherwise the keydown event listener is //never triggered in IE. if(dojox.gfx.renderer=='vml'){ self.node.focus(); } var o=self._fromEvt(e); self._startPoint={ x:e.pageX, y:e.pageY }; self._ctr=dojo.position(self.node); // figure out the coordinates taking scroll into account var scroll={x:self.node.scrollLeft,y:self.node.scrollTop}; //var win = dojo.window.get(self.node.ownerDocument); //var scroll=dojo.withGlobal(win,dojo._docScroll); self._ctr={x:self._ctr.x-scroll.x, y:self._ctr.y-scroll.y}; var X=e.clientX-self._ctr.x, Y=e.clientY-self._ctr.y; self._lp={ x:X, y:Y }; // capture it separately self._start={ x:X, y:Y }; self._end={ x:X, y:Y }; self._absEnd={ x:X, y:Y }; if(!o){ self.clearSelections(); self._ctool.onMouseDown(e); }else{ if(o.type && o.type()!="Anchor"){ if(!self.isSelected(o)){ self.select(o); self._sameShapeSelected=false; }else{ self._sameShapeSelected=true; } } o.beginEdit(); self._c=o; } }; this._mm=function(e){ if(!self._ctr){ return; } var x=e.clientX-self._ctr.x; var y=e.clientY-self._ctr.y; var dx=x-self._lp.x; var dy=y-self._lp.y; self._absEnd={x:x, y:y}; if(self._c){ //self._c.doChange({dx:dx, dy:dy}); self._c.setBinding({dx:dx/self.zoomFactor, dy:dy/self.zoomFactor}); self._lp={x:x, y:y}; } else { self._end={x:dx, y:dy}; var rect={ x:Math.min(self._start.x,self._absEnd.x), y:Math.min(self._start.y,self._absEnd.y), width:Math.abs(self._start.x-self._absEnd.x), height:Math.abs(self._start.y-self._absEnd.y) } if(rect.width && rect.height){ self._ctool.onMouseMove(e,rect); } } }; this._mu=function(e){ if(self._c){ // record the event. self._c.endEdit(); }else{ self._ctool.onMouseUp(e); } // clear the stuff out. self._c=self._ctr=self._lp=self._action=self._prevState=self._startPoint=null; self._cshape=self._start=self._end=self._absEnd=null; }; this.initUndoStack(); }; var p=ta.Figure.prototype; p.initUndoStack=function(){ this.history=new ta.UndoStack(this); }; p.setTool=function(/*dojox.sketch._Plugin*/t){ this._ctool=t; }; //gridSize: int // if it is greater than 0, all new shapes placed on the drawing will have coordinates // snapped to the gridSize. For example, if gridSize is set to 10, all coordinates // (only including coordinates which specifies the x/y position of shape are affected // by this parameter) will be dividable by 10 p.gridSize=0; p._calCol=function(v){ return this.gridSize?(Math.round(v/this.gridSize)*this.gridSize):v; }; p._delete=function(arr,noundo){ for(var i=0; i-1){ key=key.replace("-boundingBox",""); }else if(key&&key.indexOf("-labelShape")>-1){ key=key.replace("-labelShape",""); } return this.obj[key]; }; p._keyFromEvt=function(e){ var key=e.target.id+""; if(key.length==0){ // ancestor tree until you get to the end (meaning this.surface) var p=e.target.parentNode; var node=this.surface.getEventSource(); while(p && p.id.length==0 && p!=node){ p=p.parentNode; } key=p.id; } return key; }; p._fromEvt=function(e){ return this._get(this._keyFromEvt(e)); }; p.add=function(annotation){ for(var i=0; i-1){ this.shapes.splice(idx, 1); } return annotation; }; p.getAnnotator=function(id){ for(var i=0; i' + '' + ''; for(var i=0; i