]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * Radial gradient.\r | |
3 | *\r | |
4 | * @example\r | |
5 | * Ext.create({\r | |
6 | * xtype: 'draw', \r | |
7 | * renderTo: document.body,\r | |
8 | * width: 600,\r | |
9 | * height: 400,\r | |
10 | * sprites: [{\r | |
11 | * type: 'circle',\r | |
12 | * cx: 100,\r | |
13 | * cy: 100,\r | |
14 | * r: 100,\r | |
15 | * fillStyle: {\r | |
16 | * type: 'radial',\r | |
17 | * start: {\r | |
18 | * x: 0,\r | |
19 | * y: 0,\r | |
20 | * r: 0\r | |
21 | * },\r | |
22 | * end: {\r | |
23 | * x: 0,\r | |
24 | * y: 0,\r | |
25 | * r: 1\r | |
26 | * },\r | |
27 | * stops: [{\r | |
28 | * offset: 0,\r | |
29 | * color: '#90BCC9'\r | |
30 | * }, {\r | |
31 | * offset: 1,\r | |
32 | * color: '#1F6D91'\r | |
33 | * }]\r | |
34 | * }\r | |
35 | * }]\r | |
36 | * });\r | |
37 | */\r | |
38 | Ext.define('Ext.draw.gradient.Radial', {\r | |
39 | extend: 'Ext.draw.gradient.Gradient',\r | |
40 | type: 'radial',\r | |
41 | config: {\r | |
42 | /**\r | |
43 | * @cfg {Object} start The starting circle of the gradient.\r | |
44 | */\r | |
45 | start: {\r | |
46 | x: 0,\r | |
47 | y: 0,\r | |
48 | r: 0\r | |
49 | },\r | |
50 | /**\r | |
51 | * @cfg {Object} end The ending circle of the gradient.\r | |
52 | */\r | |
53 | end: {\r | |
54 | x: 0,\r | |
55 | y: 0,\r | |
56 | r: 1\r | |
57 | }\r | |
58 | },\r | |
59 | \r | |
60 | applyStart: function (newStart, oldStart) {\r | |
61 | if (!oldStart) {\r | |
62 | return newStart;\r | |
63 | }\r | |
64 | var circle = {\r | |
65 | x: oldStart.x,\r | |
66 | y: oldStart.y,\r | |
67 | r: oldStart.r\r | |
68 | };\r | |
69 | \r | |
70 | if ('x' in newStart) {\r | |
71 | circle.x = newStart.x;\r | |
72 | } else if ('centerX' in newStart) {\r | |
73 | circle.x = newStart.centerX;\r | |
74 | }\r | |
75 | \r | |
76 | if ('y' in newStart) {\r | |
77 | circle.y = newStart.y;\r | |
78 | } else if ('centerY' in newStart) {\r | |
79 | circle.y = newStart.centerY;\r | |
80 | }\r | |
81 | \r | |
82 | if ('r' in newStart) {\r | |
83 | circle.r = newStart.r;\r | |
84 | } else if ('radius' in newStart) {\r | |
85 | circle.r = newStart.radius;\r | |
86 | }\r | |
87 | return circle;\r | |
88 | },\r | |
89 | \r | |
90 | applyEnd: function (newEnd, oldEnd) {\r | |
91 | if (!oldEnd) {\r | |
92 | return newEnd;\r | |
93 | }\r | |
94 | var circle = {\r | |
95 | x: oldEnd.x,\r | |
96 | y: oldEnd.y,\r | |
97 | r: oldEnd.r\r | |
98 | };\r | |
99 | \r | |
100 | if ('x' in newEnd) {\r | |
101 | circle.x = newEnd.x;\r | |
102 | } else if ('centerX' in newEnd) {\r | |
103 | circle.x = newEnd.centerX;\r | |
104 | }\r | |
105 | \r | |
106 | if ('y' in newEnd) {\r | |
107 | circle.y = newEnd.y;\r | |
108 | } else if ('centerY' in newEnd) {\r | |
109 | circle.y = newEnd.centerY;\r | |
110 | }\r | |
111 | \r | |
112 | if ('r' in newEnd) {\r | |
113 | circle.r = newEnd.r;\r | |
114 | } else if ('radius' in newEnd) {\r | |
115 | circle.r = newEnd.radius;\r | |
116 | }\r | |
117 | return circle;\r | |
118 | },\r | |
119 | \r | |
120 | /**\r | |
121 | * @inheritdoc\r | |
122 | */\r | |
123 | generateGradient: function (ctx, bbox) {\r | |
124 | var start = this.getStart(),\r | |
125 | end = this.getEnd(),\r | |
126 | w = bbox.width * 0.5,\r | |
127 | h = bbox.height * 0.5,\r | |
128 | x = bbox.x + w,\r | |
129 | y = bbox.y + h,\r | |
130 | gradient = ctx.createRadialGradient(\r | |
131 | x + start.x * w, y + start.y * h, start.r * Math.max(w, h),\r | |
132 | x + end.x * w, y + end.y * h, end.r * Math.max(w, h)\r | |
133 | ),\r | |
134 | stops = this.getStops(),\r | |
135 | ln = stops.length,\r | |
136 | i;\r | |
137 | \r | |
138 | for (i = 0; i < ln; i++) {\r | |
139 | gradient.addColorStop(stops[i].offset, stops[i].color);\r | |
140 | }\r | |
141 | return gradient;\r | |
142 | }\r | |
143 | }); |