1 | dojo.provide("dojox.drawing.tools.Rect"); |
---|
2 | |
---|
3 | dojox.drawing.tools.Rect = dojox.drawing.util.oo.declare( |
---|
4 | // summary: |
---|
5 | // Class for a drawable rectangle |
---|
6 | // |
---|
7 | dojox.drawing.stencil.Rect, |
---|
8 | function(){ |
---|
9 | // summary: constructor |
---|
10 | }, |
---|
11 | { |
---|
12 | draws:true, |
---|
13 | |
---|
14 | onDrag: function(/*EventObject*/obj){ |
---|
15 | // summary: See stencil._Base.onDrag |
---|
16 | // |
---|
17 | var s = obj.start, e = obj; |
---|
18 | var x = s.x < e.x ? s.x : e.x, |
---|
19 | y = s.y < e.y ? s.y : e.y, |
---|
20 | w = s.x < e.x ? e.x-s.x : s.x-e.x, |
---|
21 | h = s.y < e.y ? e.y-s.y : s.y-e.y; |
---|
22 | |
---|
23 | if(this.keys.shift){ w = h = Math.max(w,h); } |
---|
24 | |
---|
25 | if(this.keys.alt){ |
---|
26 | x-=w; y-=h; w*=2; h*=2; |
---|
27 | x = Math.max(x, 0); |
---|
28 | y = Math.max(y, 0); |
---|
29 | } |
---|
30 | this.setPoints ([ |
---|
31 | {x:x, y:y}, // TL |
---|
32 | {x:x+w, y:y}, // TR |
---|
33 | {x:x+w, y:y+h}, // BR |
---|
34 | {x:x, y:y+h} // BL |
---|
35 | ]); |
---|
36 | this.render(); |
---|
37 | }, |
---|
38 | |
---|
39 | onUp: function(/*EventObject*/obj){ |
---|
40 | // summary: See stencil._Base.onUp |
---|
41 | // |
---|
42 | if(this.created || !this._downOnCanvas){ return; } |
---|
43 | this._downOnCanvas = false; |
---|
44 | |
---|
45 | //Default shape on single click |
---|
46 | if(!this.shape){ |
---|
47 | var s = obj.start; |
---|
48 | var e = this.minimumSize*4; |
---|
49 | this.setPoints([ |
---|
50 | {x:s.x, y:s.y}, |
---|
51 | {x:s.x+e, y:s.y}, |
---|
52 | {x:s.x+e, y:s.y+e}, |
---|
53 | {x:s.x, y:s.y+e} |
---|
54 | ]); |
---|
55 | this.render(); |
---|
56 | }else{ |
---|
57 | |
---|
58 | // if too small, need to reset |
---|
59 | var o = this.data; |
---|
60 | if(o.width<this.minimumSize && o.height < this.minimumSize){ |
---|
61 | this.remove(this.shape, this.hit); |
---|
62 | return; |
---|
63 | } |
---|
64 | } |
---|
65 | this.onRender(this); |
---|
66 | |
---|
67 | } |
---|
68 | } |
---|
69 | ); |
---|
70 | |
---|
71 | dojox.drawing.tools.Rect.setup = { |
---|
72 | // summary: See stencil._Base ToolsSetup |
---|
73 | // |
---|
74 | name:"dojox.drawing.tools.Rect", |
---|
75 | tooltip:'<span class="drawingTipTitle">Rectangle Tool</span><br/>' |
---|
76 | + '<span class="drawingTipDesc">SHIFT - constrain to square</span>', |
---|
77 | iconClass:"iconRect" |
---|
78 | }; |
---|
79 | dojox.drawing.register(dojox.drawing.tools.Rect.setup, "tool"); |
---|