Permalink
Browse files

Initial commit

  • Loading branch information...
danro committed Sep 16, 2010
0 parents commit 24f47bbb7f1cc6175a15352f1254ba4e80efd764
@@ -0,0 +1,41 @@
+
+import com.tweenman.BaseProp;
+
+class com.tweenman.ArrayProp extends BaseProp {
+
+ var props:Object;
+ var current:Object;
+
+ function construct () {
+ props = {};
+ }
+
+ function init () {
+ if (current == null) {
+ if (target instanceof Array) {
+ current = target;
+ } else if (target[id] instanceof Array) {
+ current = target[id];
+ }
+ }
+ var valueIsArray:Boolean = value instanceof Array;
+ if (!valueIsArray) return tween.valueError(id);
+ var count:Number = current.length;
+ var i:Number, prop:BaseProp;
+ for ( i = 0; i < count; i++ ) {
+ prop = new BaseProp();
+ props[ String(i) ] = prop;
+ prop.id = i;
+ prop.value = value[i];
+ prop.target = current;
+ prop.init();
+ }
+ }
+
+ function update ($position) {
+ var p:String;
+ for (p in props) {
+ props[p].update($position);
+ }
+ }
+}
@@ -0,0 +1,67 @@
+
+import flash.display.BitmapData;
+import flash.filters.BitmapFilter;
+import com.tweenman.MultiProp;
+
+class com.tweenman.BaseFilterProp extends MultiProp {
+
+ var filterClass:Function;
+ var initializers:Object;
+
+ function init () {
+ var valid:Boolean = typeof(target) == "movieclip" || target instanceof Button || target instanceof TextField;
+ if (!valid) return tween.typeError(id, "MovieClip, Button, TextField");
+ if (value == null) value = defaults;
+ propList = [];
+ var p:String;
+ var initList:Object = {};
+ for ( p in value ) {
+ if (defaults[p] != null) {
+ propList.push(p);
+ } else if (initializers[p] != null) {
+ initList[p] = value[p];
+ delete value[p];
+ }
+ }
+ var filters:Array = target.filters;
+ var filterCount:Number = filters.length;
+ var filterFound:Boolean = false;
+ var i:Number;
+ for ( i = 0; i < filterCount; i++ ) {
+ if ( filters[i] instanceof filterClass ) {
+ current = filters[i];
+ filterFound = true;
+ }
+ }
+ if (!filterFound) {
+ current = new filterClass();
+ for ( p in defaults ) {
+ current[p] = defaults[p];
+ }
+ }
+ for ( p in initList ) {
+ current[p] = initList[p];
+ }
+ var valueIsArray:Boolean = value instanceof Array;
+ var valueIsObject:Boolean = typeof value == "object" && !valueIsArray;
+ if (!valueIsObject) return tween.valueError(id);
+ super.init();
+ }
+
+ function update ($position) {
+ super.update($position);
+ var filters:Array = target.filters;
+ var filterCount:Number = filters.length;
+ var i:Number;
+ for ( i = 0; i < filterCount; i++ ) {
+ if ( filters[i] instanceof filterClass ) {
+ filters[i] = current;
+ target.filters = filters;
+ return;
+ }
+ }
+ if (filters == null) filters = [];
+ filters.push(current);
+ target.filters = filters;
+ }
+}
@@ -0,0 +1,28 @@
+
+import com.tweenman.Tween;
+
+class com.tweenman.BaseProp {
+
+ var id:Object;
+ var tween:Tween;
+ var start:Number;
+ var change:Number;
+ var target:Object;
+ var value:Object;
+
+ function BaseProp () {
+ construct();
+ }
+
+ function construct () {}
+
+ function init () {
+ start = target[id];
+ change = typeof(value) == "number" ? value - start : Number(value);
+ }
+
+ function update ($position) {
+ var result:Number = start + ($position * change);
+ if (target[id] != result) target[id] = result;
+ }
+}
@@ -0,0 +1,15 @@
+
+import flash.filters.BevelFilter;
+import com.tweenman.BaseFilterProp;
+import com.tweenman.HexColorProp;
+
+class com.tweenman.BevelFilterProp extends BaseFilterProp {
+
+ function init () {
+ filterClass = BevelFilter;
+ defaults = { distance: 4.0, angle: 45, highlightColor: 0xFFFFFF, highlightAlpha: 1.0, shadowColor: 0x000000, shadowAlpha: 1.0, blurX: 4.0, blurY: 4.0, strength: 0 };
+ classes = { highlightColor: HexColorProp, shadowColor: HexColorProp };
+ initializers = { quality: "", type: "", knockout: "" };
+ super.init();
+ }
+}
@@ -0,0 +1,13 @@
+
+import flash.filters.BlurFilter;
+import com.tweenman.BaseFilterProp;
+
+class com.tweenman.BlurFilterProp extends BaseFilterProp {
+
+ function init () {
+ filterClass = BlurFilter;
+ defaults = { blurX: 0.0, blurY: 0.0 };
+ initializers = { quality: "" };
+ super.init();
+ }
+}
@@ -0,0 +1,63 @@
+
+import flash.filters.ColorMatrixFilter;
+import com.tweenman.ArrayProp;
+import com.tweenman.ColorMatrix;
+
+class com.tweenman.ColorFilterProp extends ArrayProp {
+
+ private var defaults:Object = { brightness: 0, contrast: 0, saturation: 1, hue: 0, colorize: 0x000000,
+ colorizeAmount: 0, blend: false };
+
+ function init () {
+ var valid:Boolean = typeof(target) == "movieclip" || target instanceof Button || target instanceof TextField;
+ if (!valid) return tween.typeError(id, "MovieClip, Button, TextField");
+ if (value == null) value = defaults;
+ var cmf:ColorMatrixFilter;
+ var filters:Array = target.filters;
+ var filterCount:Number = filters.length;
+ var i:Number;
+ for ( i = 0; i < filterCount; i++ ) {
+ if ( filters[i] instanceof ColorMatrixFilter ) {
+ cmf = filters[i];
+ }
+ }
+ current = cmf == null ? ColorMatrix.IDENTITY.concat() : cmf.matrix.concat();
+ var cm:ColorMatrix = new ColorMatrix();
+ if (value.blend) cm.matrix = current.concat();
+ var p:String;
+ for (p in value) {
+ if (value[p] == null) continue;
+ switch (p) {
+ case "brightness": cm.adjustBrightness( value[p] ); break;
+ case "contrast": cm.adjustContrast( value[p] ); break;
+ case "saturation": cm.adjustSaturation( value[p] ); break;
+ case "hue": cm.adjustHue( value[p] ); break;
+ case "colorize":
+ case "colorizeAmount":
+ if (value.colorize == null) value.colorize = defaults.colorize;
+ if (value.colorizeAmount == null) value.colorizeAmount = defaults.colorizeAmount;
+ cm.adjustColorize( value.colorize, value.colorizeAmount );
+ break;
+ }
+ }
+ value = cm.matrix;
+ super.init();
+ }
+
+ function update ($position) {
+ super.update($position);
+ var filters:Array = target.filters;
+ var filterCount:Number = filters.length;
+ var i:Number;
+ for ( i = 0; i < filterCount; i++ ) {
+ if ( filters[i] instanceof ColorMatrixFilter ) {
+ filters[i].matrix = current.concat();
+ target.filters = filters;
+ return;
+ }
+ }
+ if (filters == null) filters = [];
+ filters.push( new ColorMatrixFilter( current.concat() ) );
+ target.filters = filters;
+ }
+}
@@ -0,0 +1,70 @@
+
+class com.tweenman.ColorMatrix {
+
+ static var IDENTITY:Array = [1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];
+ var matrix:Array;
+
+ private static var r_lum:Number = 0.212671;
+ private static var g_lum:Number = 0.715160;
+ private static var b_lum:Number = 0.072169;
+
+ public function ColorMatrix () {
+ matrix = IDENTITY.concat();
+ }
+
+ function adjustBrightness (r:Number, g:Number, b:Number) {
+ g = (g == null) ? r : g;
+ b = (b == null) ? r : b;
+ concat( [1,0,0,0,r,0,1,0,0,g ,0,0,1,0,b ,0,0,0,1,0 ]);
+ }
+
+ function adjustContrast ( r:Number, g:Number, b:Number ) {
+ g = (g == null) ? r : g;
+ b = (b == null) ? r : b;
+ r+=1; g+=1; b+=1;
+ concat( [r,0,0,0,128*(1-r), 0,g,0,0,128*(1-g), 0,0,b,0,128*(1-b), 0,0,0,1,0 ]);
+ }
+
+ function adjustSaturation ( s:Number ) {
+ var i:Number=1-s;
+ var irlum:Number = i * r_lum;
+ var iglum:Number = i * g_lum;
+ var iblum:Number = i * b_lum;
+ concat( [irlum + s, iglum, iblum, 0, 0, irlum, iglum + s, iblum, 0, 0, irlum, iglum, iblum + s, 0, 0, 0, 0, 0, 1, 0 ]);
+ }
+
+ function adjustHue ( angle:Number ) {
+ angle *= Math.PI/180;
+ var c:Number = Math.cos( angle );
+ var s:Number = Math.sin( angle );
+ var f1:Number = 0.213;
+ var f2:Number = 0.715;
+ var f3:Number = 0.072;
+ concat( [(f1 + (c * (1 - f1))) + (s * (-f1)), (f2 + (c * (-f2))) + (s * (-f2)), (f3 + (c * (-f3))) + (s * (1 - f3)), 0, 0, (f1 + (c * (-f1))) + (s * 0.143), (f2 + (c * (1 - f2))) + (s * 0.14), (f3 + (c * (-f3))) + (s * -0.283), 0, 0, (f1 + (c * (-f1))) + (s * (-(1 - f1))), (f2 + (c * (-f2))) + (s * f2), (f3 + (c * (1 - f3))) + (s * f3), 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1] );
+ }
+
+ function adjustColorize ( rgb:Number, amount:Number ) {
+ if (amount == null) amount = 1;
+ var r:Number = ( ( rgb >> 16 ) & 0xff ) / 255;
+ var g:Number = ( ( rgb >> 8 ) & 0xff ) / 255;
+ var b:Number = ( rgb & 0xff ) / 255;
+ var inv_amount:Number = 1 - amount;
+ concat( [inv_amount + amount*r*r_lum, amount*r*g_lum, amount*r*b_lum, 0, 0, amount*g*r_lum, inv_amount + amount*g*g_lum, amount*g*b_lum, 0, 0, amount*b*r_lum,amount*b*g_lum, inv_amount + amount*b*b_lum, 0, 0, 0 , 0 , 0 , 1, 0] );
+ }
+
+ function concat ( mat:Array ) {
+ var temp:Array = [];
+ var i:Number = 0;
+ for (var y:Number = 0; y < 4; y++ ) {
+ for (var x:Number = 0; x < 5; x++ ) {
+ temp[i + x] = mat[i ] * matrix[x ] +
+ mat[i+1] * matrix[x + 5] +
+ mat[i+2] * matrix[x + 10] +
+ mat[i+3] * matrix[x + 15] +
+ (x == 4 ? mat[i+4] : 0);
+ }
+ i+=5;
+ }
+ matrix = temp;
+ }
+}
@@ -0,0 +1,48 @@
+
+import flash.geom.ColorTransform;
+import com.tweenman.MultiProp;
+import com.tweenman.HexColorProp;
+
+class com.tweenman.ColorProp extends MultiProp {
+
+ function init () {
+ var valid:Boolean = typeof(target) == "movieclip" || target instanceof Button || target instanceof TextField;
+ if (!valid) return tween.typeError(id, "MovieClip, Button, TextField");
+ defaults = { redMultiplier: 1.0, greenMultiplier: 1.0, blueMultiplier: 1.0, alphaMultiplier: 1.0,
+ redOffset: 0, greenOffset: 0, blueOffset: 0, alphaOffset: 0, brightness: 0,
+ tintColor: 0x000000, tintMultiplier: 0, burn: 0 };
+ if (value != null) {
+ if (value.brightness != null) {
+ value.redMultiplier = value.greenMultiplier = value.blueMultiplier = 1 - Math.abs(value.brightness);
+ value.burn = value.brightness > 0 ? value.brightness : 0;
+ }
+ if (value.burn != null) value.redOffset = value.greenOffset = value.blueOffset = 256 * value.burn;
+ if (value.tintColor != null) {
+ if (value.tintMultiplier == null) value.tintMultiplier = 1;
+ value.redOffset = (value.tintColor >> 16) * value.tintMultiplier;
+ value.greenOffset = ((value.tintColor >> 8) & 0xFF) * value.tintMultiplier;
+ value.blueOffset = (value.tintColor & 0xFF) * value.tintMultiplier;
+ }
+ if (value.tintMultiplier != null) {
+ value.redMultiplier = value.greenMultiplier = value.blueMultiplier = 1 - Math.abs(value.tintMultiplier);
+ }
+ }
+ if (value == null) value = defaults;
+ propList = [];
+ var p:String;
+ var ct = new ColorTransform();
+ for ( p in value ) {
+ if (p == "brightness" || p == "tintColor" || p == "tintMultiplier" || p == "burn") continue;
+ propList.push(p);
+ ct[p] = value[p];
+ }
+ value = ct;
+ current = target.transform.colorTransform;
+ super.init();
+ }
+
+ function update ($position) {
+ super.update($position);
+ target.transform.colorTransform = current;
+ }
+}
@@ -0,0 +1,12 @@
+
+class com.tweenman.ConflictMap {
+
+ static var visible:Array = ["_alpha", "color"];
+ static var _alpha:Array = ["visible", "color"];
+ static var color:Array = ["visible", "_alpha"];
+
+ static var scale:Array = ["_xscale", "_yscale"];
+ static var _xscale:String = "scale";
+ static var _yscale:String = "scale";
+
+}
@@ -0,0 +1,15 @@
+
+import flash.filters.ConvolutionFilter;
+import com.tweenman.BaseFilterProp;
+import com.tweenman.HexColorProp;
+
+class com.tweenman.ConvolutionProp extends BaseFilterProp {
+
+ function init () {
+ filterClass = ConvolutionFilter;
+ defaults = { divisor: 1.0, bias: 0.0, color: 0, alpha: 0.0 };
+ classes = { color: HexColorProp };
+ initializers = { matrix: "", matrixX: "", matrixY: "", preserveAlpha: "", clamp: "" };
+ super.init();
+ }
+}
Oops, something went wrong.

0 comments on commit 24f47bb

Please sign in to comment.