source: Dev/branches/rest-dojo-ui/client/dojox/drawing/tools/Line.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.5 KB
Line 
1dojo.provide("dojox.drawing.tools.Line");
2
3dojox.drawing.tools.Line = dojox.drawing.util.oo.declare(
4        // summary:
5        //              Class for a drawable Line
6        dojox.drawing.stencil.Line,
7        function(){
8                // summary: constructor
9        },
10        {
11                draws:true,
12                showAngle:true,
13                onTransformEnd: function(/*manager.Anchor*/anchor){
14                        // summary:
15                        //      Overwrites _Base.onTransformEnd
16                        //
17                        this._toggleSelected();
18                        if(this.getRadius()<this.minimumSize){
19                                var p = this.points;
20                                this.setPoints([
21                                        {x:p[0].x, y:p[0].y},
22                                        {x:p[0].x, y:p[0].y}
23                                ]);
24                        }else{
25                                var d = this.data;
26                                var obj = {start:{x:d.x1,y:d.y1},x:d.x2,y:d.y2};
27                                var pt = this.util.snapAngle(obj, this.angleSnap/180);
28                                this.setPoints([
29                                        {x:d.x1, y:d.y1},
30                                        {x:pt.x, y:pt.y}
31                                ]);
32                               
33                                this._isBeingModified = false;
34                                this.onModify(this);
35                        }
36                },
37               
38                onDrag: function(/*EventObject*/obj){
39                        // summary: See stencil._Base.onDrag
40                        //
41                        if(this.created){ return; }
42                        var x1 = obj.start.x,
43                                y1 = obj.start.y,
44                                x2 = obj.x,
45                                y2 = obj.y;
46                       
47                        if(this.keys.shift){
48                                var pt = this.util.snapAngle(obj, 45/180);
49                                x2 = pt.x;
50                                y2 = pt.y;
51                        }
52                       
53                        if(this.keys.alt){
54                                // FIXME:
55                                //      should double the length of the line
56                                // FIXME:
57                                //      if alt dragging past ZERO it seems to work
58                                //      but select/deselect shows bugs
59                                var dx = x2>x1 ? ((x2-x1)/2) : ((x1-x2)/-2);
60                                var dy = y2>y1 ? ((y2-y1)/2) : ((y1-y2)/-2);
61                                x1 -= dx;
62                                x2 -= dx;
63                                y1 -= dy;
64                                y2 -= dy;
65                        }
66                       
67                        this.setPoints([
68                                {x:x1, y:y1},
69                                {x:x2, y:y2}
70                        ]);
71                        this.render();
72                },
73               
74                onUp: function(/*EventObject*/obj){
75                        // summary: See stencil._Base.onUp
76                        //
77                        if(this.created || !this._downOnCanvas){ return; }
78                        this._downOnCanvas = false;
79                        //Default shape on single click
80                        if(!this.shape){
81                                var s = obj.start, e = this.minimumSize*4;
82                                this.setPoints([
83                                        {x:s.x, y:s.y+e},
84                                        {x:s.x, y:s.y}
85                                ]);
86                                this.render();
87                               
88                        }else{
89                                // if too small, need to reset
90                               
91                                if(this.getRadius()<this.minimumSize){
92                                        this.remove(this.shape, this.hit);
93                                        return;
94                                }
95                        }
96                       
97                        var pt = this.util.snapAngle(obj, this.angleSnap/180);
98                        var p = this.points;
99                        this.setPoints([
100                                {x:p[0].x, y:p[0].y},
101                                {x:pt.x, y:pt.y}
102                        ]);
103                       
104                        this.renderedOnce = true;
105                        this.onRender(this);
106                }
107        }
108);
109
110dojox.drawing.tools.Line.setup = {
111        // summary: See stencil._Base ToolsSetup
112        //
113        name:"dojox.drawing.tools.Line",
114        tooltip:"Line Tool",
115        iconClass:"iconLine"
116};
117
118dojox.drawing.register(dojox.drawing.tools.Line.setup, "tool");
Note: See TracBrowser for help on using the repository browser.