1 | dojo.provide("dojox.drawing.stencil.Rect"); |
---|
2 | |
---|
3 | |
---|
4 | dojox.drawing.stencil.Rect = dojox.drawing.util.oo.declare( |
---|
5 | // summary: |
---|
6 | // Creates a dojox.gfx rectangle based on data or points provided. |
---|
7 | // |
---|
8 | dojox.drawing.stencil._Base, |
---|
9 | function(options){ |
---|
10 | // summary: |
---|
11 | // constructor |
---|
12 | if(this.points.length){ |
---|
13 | //this.render(); |
---|
14 | } |
---|
15 | }, |
---|
16 | { |
---|
17 | type:"dojox.drawing.stencil.Rect", |
---|
18 | anchorType: "group", |
---|
19 | baseRender:true, |
---|
20 | |
---|
21 | dataToPoints: function(/*Object*/d){ |
---|
22 | //summary: |
---|
23 | // Converts data to points. |
---|
24 | d = d || this.data; |
---|
25 | this.points = [ |
---|
26 | {x:d.x, y:d.y}, // TL |
---|
27 | {x:d.x + d.width, y:d.y}, // TR |
---|
28 | {x:d.x + d.width, y:d.y + d.height}, // BR |
---|
29 | {x:d.x, y:d.y + d.height} // BL |
---|
30 | ]; |
---|
31 | return this.points; |
---|
32 | }, |
---|
33 | |
---|
34 | pointsToData: function(/*Array*/p){ |
---|
35 | // summary: |
---|
36 | // Converts points to data |
---|
37 | p = p || this.points; |
---|
38 | var s = p[0]; |
---|
39 | var e = p[2]; |
---|
40 | this.data = { |
---|
41 | x: s.x, |
---|
42 | y: s.y, |
---|
43 | width: e.x-s.x, |
---|
44 | height: e.y-s.y, |
---|
45 | r:this.data.r || 0 |
---|
46 | }; |
---|
47 | return this.data; |
---|
48 | |
---|
49 | }, |
---|
50 | |
---|
51 | _create: function(/*String*/shp, /*StencilData*/d, /*Object*/sty){ |
---|
52 | // summary: |
---|
53 | // Creates a dojox.gfx.shape based on passed arguments. |
---|
54 | // Can be called many times by implementation to create |
---|
55 | // multiple shapes in one stencil. |
---|
56 | // |
---|
57 | //console.log("render rect", d) |
---|
58 | //console.log("rect sty:", sty) |
---|
59 | this.remove(this[shp]); |
---|
60 | this[shp] = this.container.createRect(d) |
---|
61 | .setStroke(sty) |
---|
62 | .setFill(sty.fill); |
---|
63 | |
---|
64 | this._setNodeAtts(this[shp]); |
---|
65 | }, |
---|
66 | |
---|
67 | render: function(){ |
---|
68 | // summary: |
---|
69 | // Renders the 'hit' object (the shape used for an expanded |
---|
70 | // hit area and for highlighting) and the'shape' (the actual |
---|
71 | // display object). |
---|
72 | // |
---|
73 | this.onBeforeRender(this); |
---|
74 | this.renderHit && this._create("hit", this.data, this.style.currentHit); |
---|
75 | this._create("shape", this.data, this.style.current); |
---|
76 | } |
---|
77 | } |
---|
78 | ); |
---|
79 | |
---|
80 | dojox.drawing.register({ |
---|
81 | name:"dojox.drawing.stencil.Rect" |
---|
82 | }, "stencil"); |
---|