flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yish...@apache.org
Subject [1/6] git commit: [flex-asjs] [refs/heads/refactor-sprite] - Added IMatrix and MeagerMatrix to reduce overhead when creating Matrices.
Date Tue, 02 Aug 2016 08:50:43 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/refactor-sprite 5cf11abdf -> 5cd2f76a2


Added IMatrix and MeagerMatrix to reduce overhead when creating Matrices.


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/6b16b713
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/6b16b713
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/6b16b713

Branch: refs/heads/refactor-sprite
Commit: 6b16b713c7116744acf33933ccecc1f9cf6e5578
Parents: b3ab3eb
Author: yishayw <yishayjobs@hotmail.com>
Authored: Sun Jul 31 09:27:02 2016 +0300
Committer: yishayw <yishayjobs@hotmail.com>
Committed: Sun Jul 31 09:27:02 2016 +0300

----------------------------------------------------------------------
 .../projects/Core/src/main/flex/CoreClasses.as  |  1 +
 .../org/apache/flex/core/ITransformModel.as     | 47 +++++++++++
 .../apache/flex/core/TransformCompoundModel.as  | 52 ++++++++++++
 .../flex/org/apache/flex/core/TransformModel.as | 50 +++++++++++
 .../org/apache/flex/core/TransformMoveXModel.as | 25 ++++++
 .../org/apache/flex/core/TransformMoveYModel.as | 25 ++++++
 .../apache/flex/core/TransformRotateModel.as    | 28 +++++++
 .../org/apache/flex/core/TransformScaleModel.as | 24 ++++++
 .../main/flex/org/apache/flex/geom/Matrix.as    | 76 +++++++++++++++--
 .../flex/org/apache/flex/svg/TransformBead.as   | 87 ++++++++++++++++++++
 10 files changed, 407 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/6b16b713/frameworks/projects/Core/src/main/flex/CoreClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/CoreClasses.as b/frameworks/projects/Core/src/main/flex/CoreClasses.as
index a1cfe9c..df30ea2 100644
--- a/frameworks/projects/Core/src/main/flex/CoreClasses.as
+++ b/frameworks/projects/Core/src/main/flex/CoreClasses.as
@@ -107,6 +107,7 @@ internal class CoreClasses
 	import org.apache.flex.events.ValueEvent; ValueEvent;
     import org.apache.flex.events.utils.MouseUtils; MouseUtils;
 	import org.apache.flex.geom.Matrix; Matrix;
+	import org.apache.flex.geom.MeagerMatrix; MeagerMatrix;
     import org.apache.flex.geom.Point; Point;
     import org.apache.flex.geom.Rectangle; Rectangle;
     import org.apache.flex.utils.BinaryData; BinaryData;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/6b16b713/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ITransformModel.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ITransformModel.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ITransformModel.as
new file mode 100644
index 0000000..a88fcb6
--- /dev/null
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ITransformModel.as
@@ -0,0 +1,47 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.core
+{
+	import org.apache.flex.events.IEventDispatcher;
+	import org.apache.flex.geom.IMatrix;
+	
+    /**
+     *  The ITransformModel interface describes the minimum set of properties
+     *  needed to define a transformation on an object.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+	public interface ITransformModel extends IEventDispatcher, IBeadModel
+	{
+        /**
+         *  The matrix of the Transform
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+		function get matrix():IMatrix;
+		function set matrix(value:IMatrix):void;
+		
+	}
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/6b16b713/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformCompoundModel.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformCompoundModel.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformCompoundModel.as
new file mode 100644
index 0000000..0a1b448
--- /dev/null
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformCompoundModel.as
@@ -0,0 +1,52 @@
+package org.apache.flex.core
+{
+	import org.apache.flex.geom.IMatrix;
+
+	[DefaultProperty("transformModels")]
+	public class TransformCompoundModel extends TransformModel
+	{
+		public function set transformModels(value:Array):void
+		{
+			if (value && value.length > 0)
+			{
+				var length:int = value.length;
+				var product:IMatrix = (value[0] as ITransformModel).matrix.clone();
+				for (var i:int = 1; i < length; i++)
+				{
+					var current:IMatrix = (value[i] as ITransformModel).matrix;
+					concat(product, current);
+				}
+				matrix = product;
+			} else
+			{
+				matrix = null;
+			}
+		}
+		
+		private function concat(product:IMatrix, factor:IMatrix):void
+		{
+			var result_a:Number = product.a * factor.a;
+			var result_b:Number = 0.0;
+			var result_c:Number = 0.0;
+			var result_d:Number = product.d * factor.d;
+			var result_tx:Number = product.tx * factor.a + factor.tx;
+			var result_ty:Number = product.ty * factor.d + factor.ty;
+			if (product.b != 0.0 || product.c != 0.0 || factor.b != 0.0 || factor.c != 0.0)
+			{
+				result_a = result_a + product.b * factor.c;
+				result_d = result_d + product.c * factor.b;
+				result_b = result_b + (product.a * factor.b + product.b * factor.d);
+				result_c = result_c + (product.c * factor.a + product.d * factor.c);
+				result_tx = result_tx + product.ty * factor.c;
+				result_ty = result_ty + product.tx * factor.b;
+			}
+			product.a = result_a;
+			product.b = result_b;
+			product.c = result_c;
+			product.d = result_d;
+			product.tx = result_tx;
+			product.ty = result_ty;
+		}
+		
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/6b16b713/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformModel.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformModel.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformModel.as
new file mode 100644
index 0000000..4fa2a20
--- /dev/null
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformModel.as
@@ -0,0 +1,50 @@
+package org.apache.flex.core
+{
+	import org.apache.flex.events.Event;
+	import org.apache.flex.events.EventDispatcher;
+	import org.apache.flex.geom.IMatrix;
+	
+	public class TransformModel extends EventDispatcher implements ITransformModel
+	{
+		
+		public static const CHANGE:String = "transferModelChange";
+		
+		private var _matrix:IMatrix;
+		private var _strand:IStrand;
+		
+		public function TransformModel()
+		{
+		}
+		
+		public function get matrix():IMatrix
+		{
+			return _matrix;
+		}
+
+		private function dispatchModelChangeEvent():void
+		{
+			host.dispatchEvent(new Event(CHANGE));
+		}
+		
+		private function get host():ITransformHost
+		{
+			return _strand as ITransformHost;
+		}
+		
+		public function set matrix(value:IMatrix):void
+		{
+			_matrix = value;
+			if (_strand)
+			{
+				dispatchModelChangeEvent();
+			}
+		}
+		
+		public function set strand(value:IStrand):void 
+		{
+			_strand = value;
+			dispatchModelChangeEvent();
+		}
+
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/6b16b713/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformMoveXModel.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformMoveXModel.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformMoveXModel.as
new file mode 100644
index 0000000..1cb692e
--- /dev/null
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformMoveXModel.as
@@ -0,0 +1,25 @@
+package org.apache.flex.core
+{
+	import org.apache.flex.geom.MeagerMatrix;
+
+	public class TransformMoveXModel extends TransformModel
+	{
+		private var _x:Number;
+		
+		public function TransformMoveXModel()
+		{
+		}
+
+		public function get x():Number
+		{
+			return _x;
+		}
+
+		public function set x(value:Number):void
+		{
+			_x = value;
+			matrix = new MeagerMatrix(1, 0, 0, 1, x, 0);
+		}
+
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/6b16b713/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformMoveYModel.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformMoveYModel.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformMoveYModel.as
new file mode 100644
index 0000000..13d0384
--- /dev/null
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformMoveYModel.as
@@ -0,0 +1,25 @@
+package org.apache.flex.core
+{
+	import org.apache.flex.geom.MeagerMatrix;
+
+	public class TransformMoveYModel extends TransformModel
+	{
+		private var _y:Number;
+		
+		public function TransformMoveYModel()
+		{
+		}
+
+		public function get y():Number
+		{
+			return _y;
+		}
+
+		public function set y(value:Number):void
+		{
+			_y = value;
+			matrix = new MeagerMatrix(1, 0, 0, 1, 0, y);
+		}
+
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/6b16b713/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformRotateModel.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformRotateModel.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformRotateModel.as
new file mode 100644
index 0000000..90e0a46
--- /dev/null
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformRotateModel.as
@@ -0,0 +1,28 @@
+package org.apache.flex.core
+{
+	import org.apache.flex.geom.MeagerMatrix;
+	
+	
+	public class TransformRotateModel extends TransformModel
+	{
+		private var _angle:Number;
+		
+		public function TransformRotateModel()
+		{
+		}
+		
+		public function get angle():Number
+		{
+			return _angle;
+		}
+
+		public function set angle(value:Number):void
+		{
+			_angle = value;
+			var radians:Number = value * Math.PI/180;
+			matrix = new MeagerMatrix(Math.cos(radians), Math.sin(radians), -Math.sin(radians), Math.cos(radians));
+		}
+
+
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/6b16b713/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformScaleModel.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformScaleModel.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformScaleModel.as
new file mode 100644
index 0000000..798b66d
--- /dev/null
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/TransformScaleModel.as
@@ -0,0 +1,24 @@
+package org.apache.flex.core
+{
+	import org.apache.flex.geom.MeagerMatrix;
+
+	public class TransformScaleModel extends TransformModel
+	{
+		private var _scale:Number
+		public function TransformScaleModel()
+		{
+		}
+
+		public function get scale():Number
+		{
+			return _scale;
+		}
+
+		public function set scale(value:Number):void
+		{
+			_scale = value;
+			matrix = new MeagerMatrix(scale, 0, 0, scale, 0, 0);
+		}
+
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/6b16b713/frameworks/projects/Core/src/main/flex/org/apache/flex/geom/Matrix.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/geom/Matrix.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/geom/Matrix.as
index da88259..bf634e3 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/geom/Matrix.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/geom/Matrix.as
@@ -19,7 +19,7 @@
 package org.apache.flex.geom
 {
 
-	public class Matrix
+	public class Matrix implements IMatrix
 	{
 		public function Matrix(a:Number = 1, b:Number = 0, c:Number = 0, d:Number = 1, tx:Number
= 0, ty:Number = 0)
 		{
@@ -31,14 +31,74 @@ package org.apache.flex.geom
 			this.ty = ty;
 
 		}
-		public var a:Number;
-		public var b:Number;
-		public var c:Number;
-		public var d:Number;
-		public var tx:Number;
-		public var ty:Number;
+		private var _a:Number;
+		private var _b:Number;
+		private var _c:Number;
+		private var _d:Number;
+		private var _tx:Number;
+		private var _ty:Number;
 
-		public function clone():Matrix
+		public function get ty():Number
+		{
+			return _ty;
+		}
+
+		public function set ty(value:Number):void
+		{
+			_ty = value;
+		}
+
+		public function get tx():Number
+		{
+			return _tx;
+		}
+
+		public function set tx(value:Number):void
+		{
+			_tx = value;
+		}
+
+		public function get d():Number
+		{
+			return _d;
+		}
+
+		public function set d(value:Number):void
+		{
+			_d = value;
+		}
+
+		public function get c():Number
+		{
+			return _c;
+		}
+
+		public function set c(value:Number):void
+		{
+			_c = value;
+		}
+
+		public function get b():Number
+		{
+			return _b;
+		}
+
+		public function set b(value:Number):void
+		{
+			_b = value;
+		}
+
+		public function get a():Number
+		{
+			return _a;
+		}
+
+		public function set a(value:Number):void
+		{
+			_a = value;
+		}
+
+		public function clone():IMatrix
 		{
 			return new Matrix(a, b, c, d, tx, ty);
 		}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/6b16b713/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/TransformBead.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/TransformBead.as
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/TransformBead.as
new file mode 100644
index 0000000..60af498
--- /dev/null
+++ b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/TransformBead.as
@@ -0,0 +1,87 @@
+package org.apache.flex.svg
+{
+	import org.apache.flex.core.IBeadTransform;
+	import org.apache.flex.core.IStrand;
+	import org.apache.flex.core.ITransformHost;
+	import org.apache.flex.core.ITransformModel;
+	import org.apache.flex.core.TransformModel;
+	import org.apache.flex.events.Event;
+	import org.apache.flex.geom.IMatrix;
+
+	COMPILE::SWF {
+		import flash.display.Sprite;
+		import flash.geom.Matrix;
+	}
+	
+	public class TransformBead implements IBeadTransform
+	{
+		private var _strand:IStrand;
+		
+		public function TransformBead()
+		{
+		}
+		
+		/**
+		 *  @copy org.apache.flex.core.IBead#strand
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */		
+		public function set strand(value:IStrand):void
+		{
+			_strand = value;
+			host.addEventListener(TransformModel.CHANGE, changeHandler);
+			var model:ITransformModel = transformModel;
+			if (model && model.matrix)
+			{
+				transform();
+			}
+		}
+		
+		public function get transformModel():ITransformModel
+		{
+			return host.getBeadByType(ITransformModel) as ITransformModel;
+		}
+				
+		COMPILE::SWF
+		public function transform():void
+		{
+			var element:Sprite = host.transformElement as Sprite;
+			var fjsm:org.apache.flex.geom.IMatrix = transformModel.matrix;
+			var flashMatrix:flash.geom.Matrix = new flash.geom.Matrix(fjsm.a, fjsm.b, fjsm.c, fjsm.d,
fjsm.tx, fjsm.ty);
+			element.transform.matrix = flashMatrix;
+		}
+		/**
+		 * @flexjsignorecoercion HTMLElement
+		 */
+		COMPILE::JS
+		public function transform():void
+		{
+			var element:org.apache.flex.core.WrappedHTMLElement = host.transformElement;
+			(element.parentNode as HTMLElement).setAttribute("overflow", "visible");
+			var fjsm:org.apache.flex.geom.IMatrix = transformModel.matrix;
+			var matrixArray:Array = [fjsm.a , fjsm.b, fjsm.c, fjsm.d, fjsm.tx, fjsm.ty];
+			element.setAttribute("transform", "matrix(" +matrixArray.join(",") + ")";
+		}
+		
+		private function changeHandler(e:Event):void
+		{
+			transform();
+		}
+		
+		/**
+		 *  The host component. 
+		 * 
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function get host():ITransformHost
+		{
+			return _strand as ITransformHost;
+		}
+	}
+}
\ No newline at end of file


Mime
View raw message