Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / drawing / annotations / BoxShadow.js @ 10

History | View | Annotate | Download (5.27 KB)

1 9 andrej.cim
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6
7
8
if(!dojo._hasResource["dojox.drawing.annotations.BoxShadow"]){
9
dojo._hasResource["dojox.drawing.annotations.BoxShadow"]=true;
10
dojo.provide("dojox.drawing.annotations.BoxShadow");
11
dojox.drawing.annotations.BoxShadow=dojox.drawing.util.oo.declare(function(_1){
12
this.stencil=_1.stencil;
13
this.util=_1.stencil.util;
14
this.mouse=_1.stencil.mouse;
15
this.style=_1.stencil.style;
16
var _2={size:6,mult:4,alpha:0.05,place:"BR",color:"#646464"};
17
delete _1.stencil;
18
this.options=dojo.mixin(_2,_1);
19
this.options.color=new dojo.Color(this.options.color);
20
this.options.color.a=this.options.alpha;
21
switch(this.stencil.shortType){
22
case "image":
23
case "rect":
24
this.method="createForRect";
25
break;
26
case "ellipse":
27
this.method="createForEllipse";
28
break;
29
case "line":
30
this.method="createForLine";
31
break;
32
case "path":
33
this.method="createForPath";
34
break;
35
case "vector":
36
this.method="createForZArrow";
37
break;
38
default:
39
console.warn("A shadow cannot be made for Stencil type ",this.stencil.type);
40
}
41
if(this.method){
42
this.render();
43
this.stencil.connectMult([[this.stencil,"onTransform",this,"onTransform"],this.method=="createForZArrow"?[this.stencil,"render",this,"render"]:[this.stencil,"render",this,"onRender"],[this.stencil,"onDelete",this,"destroy"]]);
44
}
45
},{showing:true,render:function(){
46
if(this.container){
47
this.container.removeShape();
48
}
49
this.container=this.stencil.container.createGroup();
50
this.container.moveToBack();
51
var o=this.options,_3=o.size,_4=o.mult,d=this.method=="createForPath"?this.stencil.points:this.stencil.data,r=d.r||1,p=o.place,c=o.color;
52
this[this.method](o,_3,_4,d,r,p,c);
53
},hide:function(){
54
if(this.showing){
55
this.showing=false;
56
this.container.removeShape();
57
}
58
},show:function(){
59
if(!this.showing){
60
this.showing=true;
61
this.stencil.container.add(this.container);
62
}
63
},createForPath:function(o,_5,_6,_7,r,p,c){
64
var sh=_5*_6/4,_8=/B/.test(p)?sh:/T/.test(p)?sh*-1:0,_9=/R/.test(p)?sh:/L/.test(p)?sh*-1:0;
65
var _a=true;
66
for(var i=1;i<=_5;i++){
67
var _b=i*_6;
68
if(dojox.gfx.renderer=="svg"){
69
var _c=[];
70
dojo.forEach(_7,function(o,i){
71
if(i==0){
72
_c.push("M "+(o.x+_9)+" "+(o.y+_8));
73
}else{
74
var _d=o.t||"L ";
75
_c.push(_d+(o.x+_9)+" "+(o.y+_8));
76
}
77
},this);
78
if(_a){
79
_c.push("Z");
80
}
81
this.container.createPath(_c.join(", ")).setStroke({width:_b,color:c,cap:"round"});
82
}else{
83
var _e=this.container.createPath({}).setStroke({width:_b,color:c,cap:"round"});
84
dojo.forEach(this.points,function(o,i){
85
if(i==0||o.t=="M"){
86
_e.moveTo(o.x+_9,o.y+_8);
87
}else{
88
if(o.t=="Z"){
89
_a&&_e.closePath();
90
}else{
91
_e.lineTo(o.x+_9,o.y+_8);
92
}
93
}
94
},this);
95
_a&&_e.closePath();
96
}
97
}
98
},createForLine:function(o,_f,_10,d,r,p,c){
99
var sh=_f*_10/4,shy=/B/.test(p)?sh:/T/.test(p)?sh*-1:0,shx=/R/.test(p)?sh:/L/.test(p)?sh*-1:0;
100
for(var i=1;i<=_f;i++){
101
var _11=i*_10;
102
this.container.createLine({x1:d.x1+shx,y1:d.y1+shy,x2:d.x2+shx,y2:d.y2+shy}).setStroke({width:_11,color:c,cap:"round"});
103
}
104
},createForEllipse:function(o,_12,_13,d,r,p,c){
105
var sh=_12*_13/8,shy=/B/.test(p)?sh:/T/.test(p)?sh*-1:0,shx=/R/.test(p)?sh*0.8:/L/.test(p)?sh*-0.8:0;
106
for(var i=1;i<=_12;i++){
107
var _14=i*_13;
108
this.container.createEllipse({cx:d.cx+shx,cy:d.cy+shy,rx:d.rx-sh,ry:d.ry-sh,r:r}).setStroke({width:_14,color:c});
109
}
110
},createForRect:function(o,_15,_16,d,r,p,c){
111
var sh=_15*_16/2,shy=/B/.test(p)?sh:/T/.test(p)?0:sh/2,shx=/R/.test(p)?sh:/L/.test(p)?0:sh/2;
112
for(var i=1;i<=_15;i++){
113
var _17=i*_16;
114
this.container.createRect({x:d.x+shx,y:d.y+shy,width:d.width-sh,height:d.height-sh,r:r}).setStroke({width:_17,color:c});
115
}
116
},arrowPoints:function(){
117
var d=this.stencil.data;
118
var _18=this.stencil.getRadius();
119
var _19=this.style.zAngle+30;
120
var pt=this.util.pointOnCircle(d.x1,d.y1,_18*0.75,_19);
121
var obj={start:{x:d.x1,y:d.y1},x:pt.x,y:pt.y};
122
var _19=this.util.angle(obj);
123
var _1a=this.util.length(obj);
124
var al=this.style.arrows.length;
125
var aw=this.style.arrows.width/3;
126
if(_1a<al){
127
al=_1a/2;
128
}
129
var p1=this.util.pointOnCircle(obj.x,obj.y,-al,_19-aw);
130
var p2=this.util.pointOnCircle(obj.x,obj.y,-al,_19+aw);
131
return [{x:obj.x,y:obj.y},p1,p2];
132
},createForZArrow:function(o,_1b,_1c,pts,r,p,c){
133
if(this.stencil.data.cosphi<1||!this.stencil.points[0]){
134
return;
135
}
136
var sh=_1b*_1c/4,shy=/B/.test(p)?sh:/T/.test(p)?sh*-1:0,shx=/R/.test(p)?sh:/L/.test(p)?sh*-1:0;
137
var _1d=true;
138
for(var i=1;i<=_1b;i++){
139
var _1e=i*_1c;
140
pts=this.arrowPoints();
141
if(!pts){
142
return;
143
}
144
if(dojox.gfx.renderer=="svg"){
145
var _1f=[];
146
dojo.forEach(pts,function(o,i){
147
if(i==0){
148
_1f.push("M "+(o.x+shx)+" "+(o.y+shy));
149
}else{
150
var cmd=o.t||"L ";
151
_1f.push(cmd+(o.x+shx)+" "+(o.y+shy));
152
}
153
},this);
154
if(_1d){
155
_1f.push("Z");
156
}
157
this.container.createPath(_1f.join(", ")).setStroke({width:_1e,color:c,cap:"round"}).setFill(c);
158
}else{
159
var pth=this.container.createPath({}).setStroke({width:_1e,color:c,cap:"round"});
160
dojo.forEach(pts,function(o,i){
161
if(i==0||o.t=="M"){
162
pth.moveTo(o.x+shx,o.y+shy);
163
}else{
164
if(o.t=="Z"){
165
_1d&&pth.closePath();
166
}else{
167
pth.lineTo(o.x+shx,o.y+shy);
168
}
169
}
170
},this);
171
_1d&&pth.closePath();
172
}
173
var sp=this.stencil.points;
174
this.container.createLine({x1:sp[0].x,y1:sp[0].y,x2:pts[0].x,y2:pts[0].y}).setStroke({width:_1e,color:c,cap:"round"});
175
}
176
},onTransform:function(){
177
this.render();
178
},onRender:function(){
179
this.container.moveToBack();
180
},destroy:function(){
181
if(this.container){
182
this.container.removeShape();
183
}
184
}});
185
}