root / trunk / web / dojo / dojox / gfx / gradutils.js @ 11
History | View | Annotate | Download (1.58 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.gradutils"]){ |
||
9 | dojo._hasResource["dojox.gfx.gradutils"]=true; |
||
10 | dojo.provide("dojox.gfx.gradutils");
|
||
11 | dojo.require("dojox.gfx.matrix");
|
||
12 | (function(){
|
||
13 | var d=dojo,m=dojox.gfx.matrix,C=d.Color;
|
||
14 | function _1(o,c){ |
||
15 | if(o<=0){ |
||
16 | return c[0].color; |
||
17 | } |
||
18 | var _2=c.length;
|
||
19 | if(o>=1){ |
||
20 | return c[_2-1].color; |
||
21 | } |
||
22 | for(var i=0;i<_2;++i){ |
||
23 | var _3=c[i];
|
||
24 | if(_3.offset>=o){
|
||
25 | if(i){
|
||
26 | var _4=c[i-1]; |
||
27 | return d.blendColors(new C(_4.color),new C(_3.color),(o-_4.offset)/(_3.offset-_4.offset)); |
||
28 | } |
||
29 | return _3.color;
|
||
30 | } |
||
31 | } |
||
32 | return c[_2-1].color; |
||
33 | }; |
||
34 | dojox.gfx.gradutils.getColor=function(_5,pt){ |
||
35 | var o;
|
||
36 | if(_5){
|
||
37 | switch(_5.type){
|
||
38 | case "linear": |
||
39 | var _6=Math.atan2(_5.y2-_5.y1,_5.x2-_5.x1),_7=m.rotate(-_6),_8=m.project(_5.x2-_5.x1,_5.y2-_5.y1),p=m.multiplyPoint(_8,pt),_9=m.multiplyPoint(_8,_5.x1,_5.y1),_a=m.multiplyPoint(_8,_5.x2,_5.y2),_b=m.multiplyPoint(_7,_a.x-_9.x,_a.y-_9.y).x,o=m.multiplyPoint(_7,p.x-_9.x,p.y-_9.y).x/_b;
|
||
40 | break;
|
||
41 | case "radial": |
||
42 | var dx=pt.x-_5.cx,dy=pt.y-_5.cy,o=Math.sqrt(dx*dx+dy*dy)/_5.r;
|
||
43 | break;
|
||
44 | } |
||
45 | return _1(o,_5.colors);
|
||
46 | } |
||
47 | return new C(_5||[0,0,0,0]); |
||
48 | }; |
||
49 | dojox.gfx.gradutils.reverse=function(_c){ |
||
50 | if(_c){
|
||
51 | switch(_c.type){
|
||
52 | case "linear": |
||
53 | case "radial": |
||
54 | _c=dojo.delegate(_c); |
||
55 | if(_c.colors){
|
||
56 | var c=_c.colors,l=c.length,i=0,_d,n=_c.colors=new Array(c.length); |
||
57 | for(;i<l;++i){
|
||
58 | _d=c[i]; |
||
59 | n[i]={offset:1-_d.offset,color:_d.color}; |
||
60 | } |
||
61 | n.sort(function(a,b){
|
||
62 | return a.offset-b.offset;
|
||
63 | }); |
||
64 | } |
||
65 | break;
|
||
66 | } |
||
67 | } |
||
68 | return _c;
|
||
69 | }; |
||
70 | })(); |
||
71 | } |