source: Dev/branches/rest-dojo-ui/client/dojox/drawing/annotations/Angle.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

  • Property svn:executable set to *
File size: 2.9 KB
Line 
1dojo.provide("dojox.drawing.annotations.Angle");
2
3dojox.drawing.annotations.Angle = dojox.drawing.util.oo.declare(
4        // summary:
5        //      When initiated, an HTML box will hover near the Stencil,
6        //      displaying it's angle while drawn or modified. Currently
7        //      only works with Vector, Line, Arrow, and Axes.
8        // description:
9        //      Annotation is positioned with dojox.drawing.util.positioning.angle
10        //      That method should be overwritten for custom placement.
11        //      Called internally. To initiaize:
12        //      TODO: currently always on
13        //
14        function(/*Object*/options){
15                // arguments:
16                //      options: Object
17                //              One key value: the stencil that called this.
18                //
19                this.stencil = options.stencil;
20                this.util = options.stencil.util;
21                this.mouse = options.stencil.mouse;
22
23                this.stencil.connectMult([
24                        ["onDrag", this, "showAngle"],
25                        ["onUp", this, "hideAngle"],
26                        ["onTransformBegin", this, "showAngle"],
27                        ["onTransform", this, "showAngle"],
28                        ["onTransformEnd", this, "hideAngle"]
29                ]);
30        },
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 = dojox.drawing.util.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);
Note: See TracBrowser for help on using the repository browser.