Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / gfx / gradient.js @ 11

History | View | Annotate | Download (2.36 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.gfx.gradient"]){
9
dojo._hasResource["dojox.gfx.gradient"]=true;
10
dojo.provide("dojox.gfx.gradient");
11
dojo.require("dojox.gfx.matrix");
12
(function(){
13
var d=dojo,m=dojox.gfx.matrix,C=d.Color;
14
dojox.gfx.gradient.rescale=function(_1,_2,to){
15
var _3=_1.length,_4=(to<_2),_5;
16
if(_4){
17
var _6=_2;
18
_2=to;
19
to=_6;
20
}
21
if(!_3){
22
return [];
23
}
24
if(to<=_1[0].offset){
25
_5=[{offset:0,color:_1[0].color},{offset:1,color:_1[0].color}];
26
}else{
27
if(_2>=_1[_3-1].offset){
28
_5=[{offset:0,color:_1[_3-1].color},{offset:1,color:_1[_3-1].color}];
29
}else{
30
var _7=to-_2,_8,_9,i;
31
_5=[];
32
if(_2<0){
33
_5.push({offset:0,color:new C(_1[0].color)});
34
}
35
for(i=0;i<_3;++i){
36
_8=_1[i];
37
if(_8.offset>=_2){
38
break;
39
}
40
}
41
if(i){
42
_9=_1[i-1];
43
_5.push({offset:0,color:d.blendColors(new C(_9.color),new C(_8.color),(_2-_9.offset)/(_8.offset-_9.offset))});
44
}else{
45
_5.push({offset:0,color:new C(_8.color)});
46
}
47
for(;i<_3;++i){
48
_8=_1[i];
49
if(_8.offset>=to){
50
break;
51
}
52
_5.push({offset:(_8.offset-_2)/_7,color:new C(_8.color)});
53
}
54
if(i<_3){
55
_9=_1[i-1];
56
_5.push({offset:1,color:d.blendColors(new C(_9.color),new C(_8.color),(to-_9.offset)/(_8.offset-_9.offset))});
57
}else{
58
_5.push({offset:1,color:new C(_1[_3-1].color)});
59
}
60
}
61
}
62
if(_4){
63
_5.reverse();
64
for(i=0,_3=_5.length;i<_3;++i){
65
_8=_5[i];
66
_8.offset=1-_8.offset;
67
}
68
}
69
return _5;
70
};
71
function _a(x,y,_b,_c,_d,_e){
72
var r=m.multiplyPoint(_b,x,y),p=m.multiplyPoint(_c,r);
73
return {r:r,p:p,o:m.multiplyPoint(_d,p).x/_e};
74
};
75
function _f(a,b){
76
return a.o-b.o;
77
};
78
dojox.gfx.gradient.project=function(_10,_11,tl,rb,ttl,trb){
79
_10=_10||m.identity;
80
var f1=m.multiplyPoint(_10,_11.x1,_11.y1),f2=m.multiplyPoint(_10,_11.x2,_11.y2),_12=Math.atan2(f2.y-f1.y,f2.x-f1.x),_13=m.project(f2.x-f1.x,f2.y-f1.y),pf1=m.multiplyPoint(_13,f1),pf2=m.multiplyPoint(_13,f2),_14=new m.Matrix2D([m.rotate(-_12),{dx:-pf1.x,dy:-pf1.y}]),_15=m.multiplyPoint(_14,pf2).x,_16=[_a(tl.x,tl.y,_10,_13,_14,_15),_a(rb.x,rb.y,_10,_13,_14,_15),_a(tl.x,rb.y,_10,_13,_14,_15),_a(rb.x,tl.y,_10,_13,_14,_15)].sort(_f),_17=_16[0].o,to=_16[3].o,_18=dojox.gfx.gradient.rescale(_11.colors,_17,to),_19=Math.atan2(_16[3].r.y-_16[0].r.y,_16[3].r.x-_16[0].r.x);
81
return {type:"linear",x1:_16[0].p.x,y1:_16[0].p.y,x2:_16[3].p.x,y2:_16[3].p.y,colors:_18,angle:_12};
82
};
83
})();
84
}