source: Dev/trunk/src/client/dojox/drawing/tools/Ellipse.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1define(["dojo/_base/lang", "../util/oo", "../manager/_registry", "../stencil/Ellipse"],
2function(lang, oo, registry, StencilEllipse){
3
4//dojox.drawing.tools.Ellipse =
5var Ellipse = oo.declare(
6        StencilEllipse,
7        function(){
8                // summary:
9                //              constructor
10        },
11        {
12                // summary:
13                //              A drawable Ellipse.
14
15                draws:true,
16                onDrag: function(/*EventObject*/obj){
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                        if(!this.keys.alt){ // ellipse is normally on center
25                                x+=w/2; y+=h/2; w/=2; h/=2;
26                        } else{
27                                if(y - h < 0){ h = y; }
28                                if(x - w < 0){ w = x; }
29                        }
30                       
31                        this.points = [
32                                {x:x-w, y:y-h},         // TL
33                                {x:x+w, y:y-h},         // TR
34                                {x:x+w, y:y+h},         // BR
35                                {x:x-w, y:y+h}          // BL
36                        ];
37                        this.render();
38                },
39               
40                onUp: function(/*EventObject*/obj){
41                        if(this.created || !this._downOnCanvas){ return; }
42                        this._downOnCanvas = false;
43                        //Default shape on single click
44                        if(!this.shape){
45                                var s = obj.start, e = this.minimumSize*2;
46                                this.data = {
47                                        cx: s.x+e,
48                                        cy: s.y+e,
49                                        rx: e,
50                                        ry: e
51                                };
52                                this.dataToPoints();
53                                this.render();
54                        }else{
55                        // if too small, need to reset
56                                var o = this.pointsToData();
57                                console.log("Create a default shape here, pt to data: ",o);
58                                if(o.rx*2<this.minimumSize && o.ry*2 < this.minimumSize){
59                                        this.remove(this.shape, this.hit);
60                                        return;
61                                }
62                        }
63                       
64                        this.onRender(this);
65                       
66                }
67        }
68);
69
70lang.setObject("dojox.drawing.tools.Ellipse", Ellipse);
71Ellipse.setup = {
72        name:"dojox.drawing.tools.Ellipse",
73        tooltip:"Ellipse Tool",
74        iconClass:"iconEllipse"
75};
76
77registry.register(Ellipse.setup, "tool");
78
79return Ellipse;
80});
Note: See TracBrowser for help on using the repository browser.