dojox.sketch.Figure
dojo.require("dojox.sketch.Figure");
defined in dojox/sketch/Figure.js
Usage
function () (view source)
var self=this; var annCounter=1; this.shapes=[]; this.image=null; this.imageSrc=null; this.size={ w:0, h:0 }; this.surface=null; this.group=null; this.node=null; this.zoomFactor=1; // multiplier for zooming. this.tools=null; // toolbar reference. this.nextKey=function(){ return annCounter++; }; this.obj={}; // lookup table for shapes. Not keen on this solution. this.initUndoStack(); // what is selected. this.selected=[]; this.hasSelections=function(){ return this.selected.length>0 }; this.isSelected=function(obj){ for(var i=0; i<self.selected.length; i++){ if(self.selected[i]==obj) return true; } return false; }; this.select=function(obj){ // TODO: deal with multiple vs. single selections. if(!self.isSelected(obj)){ // force single select self.clearSelections(); self.selected=[ obj ]; } // force a bbox update, regardless obj.setMode(ta.Annotation.Modes.View); obj.setMode(ta.Annotation.Modes.Edit); }; this.deselect=function(obj){ var idx=-1; for(var i=0; i<self.selected.length; i++){ if(self.selected[i]==obj){ idx=i; break; } } if(idx>-1){ obj.setMode(ta.Annotation.Modes.View); self.selected.splice(idx,1); } return obj; }; this.clearSelections=function(){ for(var i=0; i<self.selected.length; i++) self.selected[i].setMode(ta.Annotation.Modes.View); self.selected=[]; }; this.replaceSelection=function(n, o){ if(!self.isSelected(o)){ self.select(n); return; } var idx=-1; for(var i=0; i<self.selected.length; i++){ if(self.selected[i]==o){ idx=i; break; } } if(idx>-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._click=function(e){ if(self._c){ dojo.stopEvent(e); return; } var o=self._fromEvt(e); if(!o){ self.clearSelections(); dojo.stopEvent(e); } else if(!o.setMode){ // skip me. } else self.select(o); }; 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){ //ctrl+z self.undo(); prevent = true; }else if(e.keyCode==89){ //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){ var o=self._fromEvt(e); self._startPoint={ x:e.pageX, y:e.pageY }; var win = dijit.getDocumentWindow(self.node.ownerDocument); // figure out the coordinates within the iframe self._ctr=dojo._abs(self.node); 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"){ self.select(o); } 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:Math.round(dx/self.zoomFactor), dy:Math.round(dy/|>self.zoomFactor)}); self._c.setBinding({dx:Math.round(dx/self.zoomFactor), dy:Math.round(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) } 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._delete=function(arr,noundo){ for(var i=0; i<arr.length; i++){ //var before=arr[i].serialize(); if(!noundo){ arr[i].remove(); } arr[i].setMode(ta.Annotation.Modes.View); arr[i].destroy(); self.remove(arr[i]); self._remove(arr[i]); } arr.splice(0,arr.length); };
FunctionsBack to top
Only private and/or inherited functions are available.











