Changeset 14429 for dojox/trunk/sketch
- Timestamp:
- 07/14/08 09:26:50 (4 months ago)
- Location:
- dojox/trunk/sketch
- Files:
-
- 11 modified
-
Anchor.js (modified) (3 diffs)
-
Annotation.js (modified) (11 diffs)
-
DoubleArrowAnnotation.js (modified) (7 diffs)
-
Figure.js (modified) (19 diffs)
-
LeadAnnotation.js (modified) (4 diffs)
-
PreexistingAnnotation.js (modified) (3 diffs)
-
SingleArrowAnnotation.js (modified) (9 diffs)
-
tests/annotation.svg (modified) (1 diff)
-
tests/test_full.html (modified) (1 diff)
-
UnderlineAnnotation.js (modified) (3 diffs)
-
UndoStack.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
dojox/trunk/sketch/Anchor.js
r12204 r14429 24 24 }; 25 25 this.doChange=function(pt){ 26 if(this.isControl) this.shape.applyTransform(pt); 27 else{ 26 if(this.isControl){ 27 this.shape.applyTransform(pt); 28 } else{ 28 29 an.transform.dx+=pt.dx; 29 30 an.transform.dy+=pt.dy; … … 38 39 39 40 this.enable=function(){ 40 if(!an.shape) return;41 if(!an.shape){ return; } 41 42 an.figure._add(this); 42 43 rect={ x:an[id].x-size, y:an[id].y-size, width:size*2, height:size*2 }; … … 49 50 this.disable=function(){ 50 51 an.figure._remove(this); 51 if(an.shape) an.shape.remove(this.shape);52 if(an.shape){ an.shape.remove(this.shape); } 52 53 this.shape=null; 53 54 rect=null; -
dojox/trunk/sketch/Annotation.js
r12244 r14429 11 11 // }, 12 12 onMouseMove: function(e,rect){ 13 if(this._cshape){14 this._cshape.setShape(rect);15 } else {16 this._cshape=this.figure.surface.createRect(rect)17 .setStroke({color:"#999", width:1, style:"ShortDot"})18 .setFill([255,255,255,0.7]);19 this._cshape.getEventSource().setAttribute("shape-rendering","crispEdges");20 }13 if(this._cshape){ 14 this._cshape.setShape(rect); 15 } else { 16 this._cshape=this.figure.surface.createRect(rect) 17 .setStroke({color:"#999", width:1, style:"ShortDot"}) 18 .setFill([255,255,255,0.7]); 19 this._cshape.getEventSource().setAttribute("shape-rendering","crispEdges"); 20 } 21 21 }, 22 22 onMouseUp: function(e){ … … 36 36 } 37 37 } 38 if(this._cshape) f.surface.remove(this._cshape); 38 if(this._cshape){ 39 f.surface.remove(this._cshape); 40 } 39 41 }, 40 42 _create: function(start,end){ … … 44 46 var _=f.nextKey(); 45 47 var a=new (this.annotation)(f, "annotation-"+_); 46 a.transform={dx:start.x/f.zoomFactor, dy:start.y/f.zoomFactor}; 47 a.end={ x:end.x/f.zoomFactor, y:end.y/f.zoomFactor }; 48 a.transform={ 49 dx:start.x/f.zoomFactor, 50 dy:start.y/f.zoomFactor 51 }; 52 a.end={ 53 x:end.x/f.zoomFactor, 54 y:end.y/f.zoomFactor 55 }; 48 56 if(a.control){ 49 a.control={ x:Math.round((end.x/2)/f.zoomFactor),y:Math.round((end.y/2)/f.zoomFactor) }; 57 a.control={ 58 x:Math.round((end.x/2)/f.zoomFactor), 59 y:Math.round((end.y/2)/f.zoomFactor) 60 }; 50 61 } 51 62 f.onBeforeCreateShape(a); … … 56 67 } 57 68 }); 69 58 70 ta.Annotation=function(figure, id){ 59 71 // for editing stuff. … … 71 83 }; 72 84 73 if(this.figure) this.figure.add(this); 74 }; 85 if(this.figure){ 86 this.figure.add(this); 87 } 88 }; 89 75 90 var p=ta.Annotation.prototype; 76 91 p.constructor=ta.Annotation; 77 92 p.type=function(){ return ''; }; 78 93 p.getType=function(){ return ta.Annotation; }; 79 80 94 p.remove=function(){ 81 95 this.figure.history.add(ta.CommandTypes.Delete, this, this.serialize()); … … 99 113 this.figure.history.add(ta.CommandTypes.Create,this); 100 114 } 101 p.onDblClick=function(e vent){115 p.onDblClick=function(e){ 102 116 var l=prompt('Set new text:',this.property('label')); 103 117 if(l!==false){ … … 133 147 p.calculate={ 134 148 slope:function(p1, p2){ 135 if(!(p1.x-p2.x)) return 0;149 if(!(p1.x-p2.x)){ return 0; } 136 150 return ((p1.y-p2.y)/(p1.x-p2.x)); 137 151 }, 138 152 dx:function(p1, p2, dy){ 139 153 var s=this.slope(p1,p2); 140 if(s==0) return s;154 if(s==0){ return s; } 141 155 return dy/s; 142 156 }, 143 dy:function(p1, p2, dx){ return this.slope(p1,p2)*dx; } 157 dy:function(p1, p2, dx){ 158 return this.slope(p1,p2)*dx; 159 } 144 160 }; 145 161 p.drawBBox=function(){ … … 153 169 this.boundingBox.getEventSource().setAttribute("shape-rendering","crispEdges"); 154 170 this.figure._add(this); 155 } else this.boundingBox.setShape(r); 171 } else { 172 this.boundingBox.setShape(r); 173 } 156 174 }; 157 175 p.setBinding=function(pt){ … … 165 183 }; 166 184 p.setMode=function(m){ 167 if(this.mode==m) return;185 if(this.mode==m){ return; } 168 186 this.mode=m; 169 187 var method="disable"; 170 if(m==ta.Annotation.Modes.Edit) method="enable";188 if(m==ta.Annotation.Modes.Edit){ method="enable"; } 171 189 if(method=="enable"){ 172 190 // draw the bounding box … … 175 193 } else { 176 194 if(this.boundingBox){ 177 if(this.shape) this.shape.remove(this.boundingBox);195 if(this.shape){ this.shape.remove(this.boundingBox); } 178 196 this.boundingBox=null; 179 197 } 180 198 } 181 for(var p in this.anchors){ this.anchors[p][method](); } 199 for(var p in this.anchors){ 200 this.anchors[p][method](); 201 } 182 202 }; 183 203 // p.writeProperties=function(){ … … 215 235 ta.Annotation.register=function(name){ 216 236 var cls=ta[name+'Annotation']; 217 ta.registerTool(name, function(p){dojo.mixin(p,{shape: name,annotation:cls});return new ta.AnnotationTool(p)}); 237 ta.registerTool(name, function(p){ 238 dojo.mixin(p, { 239 shape: name, 240 annotation:cls 241 }); 242 return new ta.AnnotationTool(p); 243 }); 218 244 }; 219 245 })(); -
dojox/trunk/sketch/DoubleArrowAnnotation.js
r12263 r14429 42 42 var opp=this.start.y-this.control.y; 43 43 var adj=this.start.x-this.control.x; 44 if(!adj) adj=1;44 if(!adj){ adj=1; } 45 45 this.startRotation=Math.atan(opp/adj); 46 46 47 opp=this.control.y-this.end.y; 47 48 adj=this.control.x-this.end.x; 48 if(!adj) adj=1;49 if(!adj){ adj=1; } 49 50 this.endRotation=Math.atan(opp/adj); 50 51 }; … … 54 55 55 56 // figure out the pull of the curve and place accordingly 56 if(this.control.y<this.end.y) offset*=-1; 57 else offset+=this.textYOffset; 58 var ab={x:((this.control.x-this.start.x)*.5)+this.start.x, y:((this.control.y-this.start.y)*.5)+this.start.y}; 59 var bc={x:((this.end.x-this.control.x)*.5)+this.control.x, y:((this.end.y-this.control.y)*.5)+this.control.y}; 60 this.textPosition={x:((bc.x-ab.x)*.5)+ab.x, y:(((bc.y-ab.y)*.5)+ab.y)+offset}; 57 if(this.control.y<this.end.y){ offset*=-1; } 58 else { offset+=this.textYOffset; } 59 var ab={ 60 x:((this.control.x-this.start.x)*.5)+this.start.x, 61 y:((this.control.y-this.start.y)*.5)+this.start.y 62 }; 63 var bc={ 64 x:((this.end.x-this.control.x)*.5)+this.control.x, 65 y:((this.end.y-this.control.y)*.5)+this.control.y 66 }; 67 this.textPosition={ 68 x:((bc.x-ab.x)*.5)+ab.x, 69 y:(((bc.y-ab.y)*.5)+ab.y)+offset 70 }; 61 71 }; 62 72 63 73 p.apply=function(obj){ 64 if(!obj) return;65 if(obj.documentElement) obj=obj.documentElement;74 if(!obj){ return; } 75 if(obj.documentElement){ obj=obj.documentElement; } 66 76 this.readCommonAttrs(obj); 67 77 68 78 for(var i=0; i<obj.childNodes.length; i++){ 69 79 var c=obj.childNodes[i]; 70 if(c.localName=="text") this.property('label',c.childNodes.length?c.childNodes[0].nodeValue:'');80 if(c.localName=="text"){ this.property('label',c.childNodes.length?c.childNodes[0].nodeValue:''); } 71 81 else if(c.localName=="path"){ 72 82 // the line … … 95 105 // rotation matrix 96 106 var rot=this.startRotation; 97 if(this.control.x<this.start.x) rot+=Math.PI;107 if(this.control.x<this.start.x){ rot+=Math.PI; } 98 108 var startRot=dojox.gfx.matrix.rotate(rot); 99 109 100 110 rot=this.endRotation; 101 if(this.control.x>=this.end.x) rot+=Math.PI;111 if(this.control.x>=this.end.x){ rot+=Math.PI; } 102 112 var endRot=dojox.gfx.matrix.rotateAt(rot, this.end.x, this.end.y); 103 113 … … 105 115 this.shape=this.figure.group.createGroup(); 106 116 this.shape.getEventSource().setAttribute("id", this.id); 107 if(this.transform.dx||this.transform.dy) this.shape.setTransform(this.transform);108 this.pathShape=this.shape.createPath( 109 "M"+this.start.x+" "+this.start.y+"Q"+this.control.x+" "+this.control.y+" "+this.end.x+" "+this.end.y + " l0,0"110 ).setStroke(this.property('stroke'));117 if(this.transform.dx||this.transform.dy){ this.shape.setTransform(this.transform); } 118 119 this.pathShape=this.shape.createPath("M"+this.start.x+" "+this.start.y+"Q"+this.control.x+" "+this.control.y+" "+this.end.x+" "+this.end.y + " l0,0") 120 .setStroke(this.property('stroke')); 111 121 112 122 this.startArrowGroup=this.shape.createGroup().setTransform({ dx:this.start.x, dy:this.start.y }); 113 123 this.startArrowGroup.applyTransform(startRot); 114 124 // console.log('startArrow',this.property('fill')); 115 this.startArrow=this.startArrowGroup.createPath("M0,0 l20,-5 -3,5 3,5 Z").setFill(this.property('fill')); 125 this.startArrow=this.startArrowGroup.createPath("M0,0 l20,-5 -3,5 3,5 Z") 126 .setFill(this.property('fill')); 116 127 117 128 this.endArrowGroup=this.shape.createGroup().setTransform(endRot); 118 this.endArrow=this.endArrowGroup.createPath( 119 "M" + this.end.x + "," + this.end.y + " l-20,-5 3,5 -3,5 Z"120 ).setFill(this.property('fill')); 129 this.endArrow=this.endArrowGroup.createPath("M" + this.end.x + "," + this.end.y + " l-20,-5 3,5 -3,5 Z") 130 .setFill(this.property('fill')); 131 121 132 this.labelShape=this.shape.createText({ 122 x:this.textPosition.x, y:this.textPosition.y, text:this.property('label'), align:this.textAlign 123 }).setFont(font).setFill(this.property('fill')); 133 x:this.textPosition.x, 134 y:this.textPosition.y, 135 text:this.property('label'), 136 align:this.textAlign 137 }) 138 .setFont(font) 139 .setFill(this.property('fill')); 124 140 }; 125 141 p.destroy=function(){ 126 if(!this.shape) return;142 if(!this.shape){ return; } 127 143 this.startArrowGroup.remove(this.startArrow); 128 144 this.endArrowGroup.remove(this.endArrow); … … 138 154 this._rot(); 139 155 this._pos(); 156 140 157 // rotation matrix 141 158 var rot=this.startRotation; 142 if(this.control.x<this.start.x) rot+=Math.PI;159 if(this.control.x<this.start.x){ rot+=Math.PI; } 143 160 var startRot=dojox.gfx.matrix.rotate(rot); 144 161 rot=this.endRotation; 145 if(this.control.x>=this.end.x) rot+=Math.PI;162 if(this.control.x>=this.end.x){ rot+=Math.PI; } 146 163 var endRot=dojox.gfx.matrix.rotateAt(rot, this.end.x, this.end.y); 147 164 148 165 this.shape.setTransform(this.transform); 149 this.pathShape.setShape( 150 "M"+this.start.x+" "+this.start.y+" Q"+this.control.x+" "+this.control.y+" "+this.end.x+" "+this.end.y + " l0,0" 151 ).setStroke(this.property('stroke')); 166 this.pathShape.setShape("M"+this.start.x+" "+this.start.y+" Q"+this.control.x+" "+this.control.y+" "+this.end.x+" "+this.end.y + " l0,0") 167 .setStroke(this.property('stroke')); 152 168 this.startArrowGroup.setTransform({ dx:this.start.x, dy:this.start.y }); 153 169 this.startArrowGroup.applyTransform(startRot); … … 155 171 156 172 this.endArrowGroup.setTransform(endRot); 157 this.endArrow.setShape( 158 "M" + this.end.x + "," + this.end.y + " l-20,-5 3,5 -3,5 Z" 159 ).setFill(this.property('fill')); 160 this.labelShape.setShape({x:this.textPosition.x, y:this.textPosition.y, text:this.property('label')}).setFill(this.property('fill')); 161 }; 173 this.endArrow.setShape("M" + this.end.x + "," + this.end.y + " l-20,-5 3,5 -3,5 Z") 174 .setFill(this.property('fill')); 175 this.labelShape.setShape({ 176 x:this.textPosition.x, 177 y:this.textPosition.y, 178 text:this.property('label') 179 }) 180 .setFill(this.property('fill')); 181 }; 182 162 183 p.getBBox=function(){ 163 184 var x=Math.min(this.start.x, this.control.x, this.end.x); … … 167 188 return { x:x, y:y, width:w, height:h }; 168 189 }; 190 169 191 p.serialize=function(){ 170 192 var s=this.property('stroke'); -
dojox/trunk/sketch/Figure.js
r13496 r14429 35 35 this.isSelected=function(obj){ 36 36 for(var i=0; i<self.selected.length; i++){ 37 if(self.selected[i]==obj) return true;37 if(self.selected[i]==obj){ return true; } 38 38 } 39 39 return false; … … 65 65 }; 66 66 this.clearSelections=function(){ 67 for(var i=0; i<self.selected.length; i++) 67 for(var i=0; i<self.selected.length; i++){ 68 68 self.selected[i].setMode(ta.Annotation.Modes.View); 69 } 69 70 self.selected=[]; 70 71 }; … … 77 78 for(var i=0; i<self.selected.length; i++){ 78 79 if(self.selected[i]==o){ 79 idx=i; break; 80 idx=i; 81 break; 80 82 } 81 83 } … … 111 113 } else if(!o.setMode){ 112 114 // skip me. 113 } else self.select(o); 114 }; 115 } else { 116 self.select(o); 117 } 118 }; 119 115 120 this._dblclick=function(e){ 116 121 var o=self._fromEvt(e); … … 123 128 var prevent=false; 124 129 if(e.ctrlKey){ 125 if(e.keyCode==90){ //ctrl+z 126 self.undo(); 127 prevent = true; 128 }else if(e.keyCode==89){ //ctrl+y 129 self.redo(); 130 prevent = true; 131 } 130 if(e.keyCode==90){ //ctrl+z 131 self.undo(); 132 prevent = true; 133 } 134 else if(e.keyCode==89){ //ctrl+y 135 self.redo(); 136 prevent = true; 137 } 132 138 } 133 139 … … 147 153 self._startPoint={ x:e.pageX, y:e.pageY }; 148 154 var win = dijit.getDocumentWindow(self.node.ownerDocument); 155 149 156 // figure out the coordinates within the iframe 150 157 self._ctr=dojo._abs(self.node); … … 170 177 }; 171 178 this._mm=function(e){ 172 if(!self._ctr) return;179 if(!self._ctr){ return; } 173 180 var x=e.clientX-self._ctr.x; 174 181 var y=e.clientY-self._ctr.y; … … 180 187 self._c.setBinding({dx:Math.round(dx/self.zoomFactor), dy:Math.round(dy/self.zoomFactor)}); 181 188 self._lp={x:x, y:y}; 182 } 183 else { 189 } else { 184 190 self._end={x:dx, y:dy}; 185 191 var rect={ … … 222 228 var p=ta.Figure.prototype; 223 229 p.initUndoStack=function(){ 224 this.history=new ta.UndoStack(this);230 this.history=new ta.UndoStack(this); 225 231 }; 226 232 p.setTool=function(/*dojox.sketch._Plugin*/t){ … … 255 261 this._cons.push(dojo.connect(this.surface.getEventSource().ownerDocument, 'onkeydown', this._keydown)); 256 262 257 // rect hack. Fcuking VML >263 // rect hack. Fcuking VML. 258 264 this.group.createRect({ x:0, y:0, width:this.size.w, height:this.size.h }); 259 265 this.image=this.group.createImage({ width:this.size.w, height:this.size.h, src:this.imageSrc }); 260 266 }; 267 261 268 p.destroy=function(isLoading){ 262 if(!this.node){ 263 return; 264 } 269 if(!this.node){ return; } 265 270 if(!isLoading){ 266 if(this.history) this.history.destroy();271 if(this.history){ this.history.destroy(); } 267 272 if(this._subscribed){ 268 273 dojo.unsubscribe(this._subscribed); … … 270 275 } 271 276 } 272 dojo.forEach(this._cons, dojo.disconnect);277 dojo.forEach(this._cons, dojo.disconnect); 273 278 this._cons=[]; 274 279 … … 278 283 this.shapes=[]; 279 284 }; 285 280 286 p.draw=function(){ }; 281 287 p.zoom=function(pct){ … … 316 322 }; 317 323 p._get=function(key){ 318 if(key&&key.indexOf("bounding")>-1) key=key.replace("-boundingBox",""); 324 if(key&&key.indexOf("bounding")>-1){ 325 key=key.replace("-boundingBox",""); 326 } 319 327 return this.obj[key]; 320 328 }; … … 348 356 } 349 357 } 350 if(idx>-1) this.shapes.splice(idx, 1);358 if(idx>-1){ this.shapes.splice(idx, 1); } 351 359 return annotation; 352 360 }; … … 363 371 // convert an existing annotation to a different kind of annotation 364 372 var ctor=t+"Annotation"; 365 if(!ta[ctor]) return; 366 var type=ann.type(), id=ann.id, label=ann.label, mode=ann.mode, 367 tokenId=ann.tokenId; 373 if(!ta[ctor]){ return; } 374 var type=ann.type(), id=ann.id, label=ann.label, mode=ann.mode, tokenId=ann.tokenId; 368 375 var start, end, control, transform; 369 376 switch(type){ … … 401 408 n.transform={dx:transform.dx+start.x, dy:transform.dy+start.y }; 402 409 } else { 403 if(n.transform) n.transform=transform;404 if(n.start) n.start=start;405 } 406 if(n.end) n.end=end;407 if(n.control) n.control=control;410