Debian Codegraph @

dojox/drawing/tools/Rect.js

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