1 | dojo.provide("dojox.drawing.tools.Ellipse"); |
---|
2 | |
---|
3 | dojox.drawing.tools.Ellipse = dojox.drawing.util.oo.declare( |
---|
4 | // summary: |
---|
5 | // A drawable Ellipse. |
---|
6 | // |
---|
7 | dojox.drawing.stencil.Ellipse, |
---|
8 | function(){ |
---|
9 | // summary: constructor |
---|
10 | }, |
---|
11 | { |
---|
12 | draws:true, |
---|
13 | onDrag: function(/*EventObject*/obj){ |
---|
14 | // summary: See stencil._Base.onDrag |
---|
15 | // |
---|
16 | var s = obj.start, e = obj; |
---|
17 | var x = s.x < e.x ? s.x : e.x, |
---|
18 | y = s.y < e.y ? s.y : e.y, |
---|
19 | w = s.x < e.x ? e.x-s.x : s.x-e.x, |
---|
20 | h = s.y < e.y ? e.y-s.y : s.y-e.y; |
---|
21 | |
---|
22 | if(this.keys.shift){ w = h = Math.max(w,h); } |
---|
23 | if(!this.keys.alt){ // ellipse is normally on center |
---|
24 | x+=w/2; y+=h/2; w/=2; h/=2; |
---|
25 | } else{ |
---|
26 | if(y - h < 0){ h = y; } |
---|
27 | if(x - w < 0){ w = x; } |
---|
28 | } |
---|
29 | |
---|
30 | this.points = [ |
---|
31 | {x:x-w, y:y-h}, // TL |
---|
32 | {x:x+w, y:y-h}, // TR |
---|
33 | {x:x+w, y:y+h}, // BR |
---|
34 | {x:x-w, 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 | //Default shape on single click |
---|
45 | if(!this.shape){ |
---|
46 | var s = obj.start, e = this.minimumSize*2; |
---|
47 | this.data = { |
---|
48 | cx: s.x+e, |
---|
49 | cy: s.y+e, |
---|
50 | rx: e, |
---|
51 | ry: e |
---|
52 | }; |
---|
53 | this.dataToPoints(); |
---|
54 | this.render(); |
---|
55 | }else{ |
---|
56 | // if too small, need to reset |
---|
57 | var o = this.pointsToData(); |
---|
58 | console.log("Create a default shape here, pt to data: ",o); |
---|
59 | if(o.rx*2<this.minimumSize && o.ry*2 < this.minimumSize){ |
---|
60 | this.remove(this.shape, this.hit); |
---|
61 | return; |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | this.onRender(this); |
---|
66 | |
---|
67 | } |
---|
68 | } |
---|
69 | ); |
---|
70 | |
---|
71 | dojox.drawing.tools.Ellipse.setup = { |
---|
72 | // summary: See stencil._Base ToolsSetup |
---|
73 | // |
---|
74 | name:"dojox.drawing.tools.Ellipse", |
---|
75 | tooltip:"Ellipse Tool", |
---|
76 | iconClass:"iconEllipse" |
---|
77 | }; |
---|
78 | |
---|
79 | dojox.drawing.register(dojox.drawing.tools.Ellipse.setup, "tool"); |
---|