3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.fx.PropertyHandler
19 Ext.define('Ext.fx.PropertyHandler', {
21 /* Begin Definitions */
23 requires: ['Ext.draw.Draw'],
27 pixelDefaultsRE: /width|height|top$|bottom$|left$|right$/i,
28 unitRE: /^(-?\d*\.?\d*){1}(em|ex|px|in|cm|mm|pt|pc|%)*$/,
31 computeDelta: function(from, end, damper, initial, attr) {
32 damper = (typeof damper == 'number') ? damper : 1;
33 var unitRE = this.unitRE,
34 match = unitRE.exec(from),
39 if (!this.scrollRE.test(attr) && !units && this.pixelDefaultsRE.test(attr)) {
45 match = unitRE.exec(end);
48 units = match[2] || units;
51 start = (initial != null) ? initial : from;
54 delta: (end - start) * damper,
59 get: function(from, end, damper, initialFrom, attr) {
62 i, initial, res, j, len;
63 for (i = 0; i < ln; i++) {
65 initial = initialFrom[i][1].from;
67 if (Ext.isArray(from[i][1]) && Ext.isArray(end)) {
70 len = from[i][1].length;
71 for (; j < len; j++) {
72 res.push(this.computeDelta(from[i][1][j], end[j], damper, initial, attr));
74 out.push([from[i][0], res]);
77 out.push([from[i][0], this.computeDelta(from[i][1], end, damper, initial, attr)]);
83 set: function(values, easing) {
84 var ln = values.length,
87 for (i = 0; i < ln; i++) {
89 if (Ext.isArray(val)) {
93 for (; j < len; j++) {
94 res.push(val[j].from + (val[j].delta * easing) + (val[j].units || 0));
96 out.push([values[i][0], res]);
98 out.push([values[i][0], val.from + (val.delta * easing) + (val.units || 0)]);
105 rgbRE: /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i,
106 hexRE: /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i,
107 hex3RE: /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i,
109 parseColor : function(color, damper) {
110 damper = (typeof damper == 'number') ? damper : 1;
115 Ext.each([this.hexRE, this.rgbRE, this.hex3RE], function(re, idx) {
116 base = (idx % 2 == 0) ? 16 : 10;
117 match = re.exec(color);
118 if (match && match.length == 4) {
120 match[1] += match[1];
121 match[2] += match[2];
122 match[3] += match[3];
125 red: parseInt(match[1], base),
126 green: parseInt(match[2], base),
127 blue: parseInt(match[3], base)
135 computeDelta: function(from, end, damper, initial) {
136 from = this.parseColor(from);
137 end = this.parseColor(end, damper);
138 var start = initial ? initial : from,
139 tfrom = typeof start,
141 //Extra check for when the color string is not recognized.
142 if (tfrom == 'string' || tfrom == 'undefined'
143 || tend == 'string' || tend == 'undefined') {
149 red: Math.round((end.red - start.red) * damper),
150 green: Math.round((end.green - start.green) * damper),
151 blue: Math.round((end.blue - start.blue) * damper)
156 get: function(start, end, damper, initialFrom) {
157 var ln = start.length,
160 for (i = 0; i < ln; i++) {
162 initial = initialFrom[i][1].from;
164 out.push([start[i][0], this.computeDelta(start[i][1], end, damper, initial)]);
169 set: function(values, easing) {
170 var ln = values.length,
172 i, val, parsedString, from, delta;
173 for (i = 0; i < ln; i++) {
178 //multiple checks to reformat the color if it can't recognized by computeDelta.
179 val = (typeof val == 'object' && 'red' in val)?
180 'rgb(' + val.red + ', ' + val.green + ', ' + val.blue + ')' : val;
181 val = (typeof val == 'object' && val.length)? val[0] : val;
182 if (typeof val == 'undefined') {
185 parsedString = typeof val == 'string'? val :
187 (from.red + Math.round(delta.red * easing)) % 256,
188 (from.green + Math.round(delta.green * easing)) % 256,
189 (from.blue + Math.round(delta.blue * easing)) % 256
201 interpolate: function(prop, damper) {
202 damper = (typeof damper == 'number') ? damper : 1;
206 out[p] = parseInt(prop[p], 10) * damper;
211 computeDelta: function(from, end, damper, initial) {
212 from = this.interpolate(from);
213 end = this.interpolate(end, damper);
214 var start = initial ? initial : from,
219 delta[p] = end[p] - start[p];
227 get: function(start, end, damper, initialFrom) {
228 var ln = start.length,
231 for (i = 0; i < ln; i++) {
233 initial = initialFrom[i][1].from;
235 out.push([start[i][0], this.computeDelta(start[i][1], end, damper, initial)]);
240 set: function(values, easing) {
241 var ln = values.length,
244 i, from, delta, val, p;
245 for (i = 0; i < ln; i++) {
250 outObject[p] = Math.round(from[p] + delta[p] * easing);
262 computeDelta: function(from, end, damper, initial) {
263 damper = (typeof damper == 'number') ? damper : 1;
267 start = (initial != null) ? initial : from;
270 delta: (end - start) * damper
274 forcePath: function(path) {
275 if (!Ext.isArray(path) && !Ext.isArray(path[0])) {
276 path = Ext.draw.Draw.parsePathString(path);
281 get: function(start, end, damper, initialFrom) {
282 var endPath = this.forcePath(end),
284 startLn = start.length,
285 startPathLn, pointsLn, i, deltaPath, initial, j, k, path, startPath;
286 for (i = 0; i < startLn; i++) {
287 startPath = this.forcePath(start[i][1]);
289 deltaPath = Ext.draw.Draw.interpolatePaths(startPath, endPath);
290 startPath = deltaPath[0];
291 endPath = deltaPath[1];
293 startPathLn = startPath.length;
295 for (j = 0; j < startPathLn; j++) {
296 deltaPath = [startPath[j][0]];
297 pointsLn = startPath[j].length;
298 for (k = 1; k < pointsLn; k++) {
299 initial = initialFrom && initialFrom[0][1][j][k].from;
300 deltaPath.push(this.computeDelta(startPath[j][k], endPath[j][k], damper, initial));
302 path.push(deltaPath);
304 out.push([start[i][0], path]);
309 set: function(values, easing) {
310 var ln = values.length,
312 i, j, k, newPath, calcPath, deltaPath, deltaPathLn, pointsLn;
313 for (i = 0; i < ln; i++) {
314 deltaPath = values[i][1];
316 deltaPathLn = deltaPath.length;
317 for (j = 0; j < deltaPathLn; j++) {
318 calcPath = [deltaPath[j][0]];
319 pointsLn = deltaPath[j].length;
320 for (k = 1; k < pointsLn; k++) {
321 calcPath.push(deltaPath[j][k].from + deltaPath[j][k].delta * easing);
323 newPath.push(calcPath.join(','));
325 out.push([values[i][0], newPath.join(',')]);
330 /* End Definitions */
344 this[prop] = this.color;