[483] | 1 | define(["dojo", "../util/oo", "../util/positioning"], |
---|
| 2 | function(dojo, oo, positioning){ |
---|
| 3 | |
---|
| 4 | //dojox.drawing.annotations.Angle = |
---|
| 5 | return oo.declare( |
---|
| 6 | function(/*Object*/ options){ |
---|
| 7 | // options: Object |
---|
| 8 | // One key value: the stencil that called this. |
---|
| 9 | |
---|
| 10 | this.stencil = options.stencil; |
---|
| 11 | this.util = options.stencil.util; |
---|
| 12 | this.mouse = options.stencil.mouse; |
---|
| 13 | |
---|
| 14 | this.stencil.connectMult([ |
---|
| 15 | ["onDrag", this, "showAngle"], |
---|
| 16 | ["onUp", this, "hideAngle"], |
---|
| 17 | ["onTransformBegin", this, "showAngle"], |
---|
| 18 | ["onTransform", this, "showAngle"], |
---|
| 19 | ["onTransformEnd", this, "hideAngle"] |
---|
| 20 | ]); |
---|
| 21 | }, |
---|
| 22 | { |
---|
| 23 | // summary: |
---|
| 24 | // When initiated, an HTML box will hover near the Stencil, |
---|
| 25 | // displaying it's angle while drawn or modified. Currently |
---|
| 26 | // only works with Vector, Line, Arrow, and Axes. |
---|
| 27 | // description: |
---|
| 28 | // Annotation is positioned with dojox.drawing.util.positioning.angle |
---|
| 29 | // That method should be overwritten for custom placement. |
---|
| 30 | // Called internally. |
---|
| 31 | |
---|
| 32 | type:"dojox.drawing.tools.custom", |
---|
| 33 | angle:0, |
---|
| 34 | |
---|
| 35 | showAngle: function(){ |
---|
| 36 | // summary: |
---|
| 37 | // Called to display angle |
---|
| 38 | |
---|
| 39 | if(!this.stencil.selected && this.stencil.created){ return; } |
---|
| 40 | if(this.stencil.getRadius() < this.stencil.minimumSize){ |
---|
| 41 | this.hideAngle(); |
---|
| 42 | return; |
---|
| 43 | } |
---|
| 44 | var node = this.getAngleNode(); |
---|
| 45 | var d = this.stencil.pointsToData(); |
---|
| 46 | var pt = positioning.angle({x:d.x1,y:d.y1},{x:d.x2,y:d.y2}); |
---|
| 47 | var sc = this.mouse.scrollOffset(); |
---|
| 48 | var mx = this.stencil.getTransform(); |
---|
| 49 | var dx = mx.dx / this.mouse.zoom; |
---|
| 50 | var dy = mx.dy / this.mouse.zoom; |
---|
| 51 | pt.x /= this.mouse.zoom; |
---|
| 52 | pt.y /= this.mouse.zoom; |
---|
| 53 | |
---|
| 54 | // adding _offX & _offY since this is HTML |
---|
| 55 | // and we are from the page corner, not |
---|
| 56 | // the canvas corner |
---|
| 57 | var x = this.stencil._offX + pt.x - sc.left + dx; |
---|
| 58 | var y = this.stencil._offY + pt.y - sc.top + dy; |
---|
| 59 | dojo.style(node, { |
---|
| 60 | left: x + "px", |
---|
| 61 | top: y + "px", |
---|
| 62 | align:pt.align |
---|
| 63 | }); |
---|
| 64 | |
---|
| 65 | var angle=this.stencil.getAngle(); |
---|
| 66 | if(this.stencil.style.zAxis && this.stencil.shortType=="vector"){ |
---|
| 67 | node.innerHTML = this.stencil.data.cosphi > 0 ? "out of" : "into"; |
---|
| 68 | }else if(this.stencil.shortType=="line"){ |
---|
| 69 | node.innerHTML = this.stencil.style.zAxis?"out of":Math.ceil(angle%180); |
---|
| 70 | }else{ |
---|
| 71 | node.innerHTML = Math.ceil(angle); |
---|
| 72 | } |
---|
| 73 | }, |
---|
| 74 | |
---|
| 75 | getAngleNode: function(){ |
---|
| 76 | // summary: |
---|
| 77 | // Gets or creates HTMLNode used for display |
---|
| 78 | if(!this._angleNode){ |
---|
| 79 | this._angleNode = dojo.create("span", null, dojo.body()); |
---|
| 80 | dojo.addClass(this._angleNode, "textAnnotation"); |
---|
| 81 | dojo.style(this._angleNode, "opacity", 1); |
---|
| 82 | } |
---|
| 83 | return this._angleNode; //HTMLNode |
---|
| 84 | }, |
---|
| 85 | |
---|
| 86 | hideAngle: function(){ |
---|
| 87 | // summary: |
---|
| 88 | // Turns display off. |
---|
| 89 | |
---|
| 90 | if(this._angleNode && dojo.style(this._angleNode, "opacity")>0.9){ |
---|
| 91 | |
---|
| 92 | dojo.fadeOut({node:this._angleNode, |
---|
| 93 | duration:500, |
---|
| 94 | onEnd: function(node){ |
---|
| 95 | dojo.destroy(node); |
---|
| 96 | } |
---|
| 97 | }).play(); |
---|
| 98 | this._angleNode = null; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | ); |
---|
| 104 | }); |
---|