You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ha...@apache.org on 2018/09/03 09:16:28 UTC

[royale-asjs] 06/13: Added SuperimposeFilter

This is an automated email from the ASF dual-hosted git repository.

harbs pushed a commit to branch feature/new_merge
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git

commit 36e4f4ecb356ddb1881e12d254e338051957e97d
Author: DESKTOP-RH4S838\Yishay <yi...@hotmail.com>
AuthorDate: Sun Jul 15 13:22:01 2018 +0300

    Added SuperimposeFilter
---
 .../Graphics/src/main/resources/svg-manifest.xml   |  1 +
 .../org/apache/royale/svg/DropShadowFilter.as      | 41 ++++++++++--
 .../org/apache/royale/svg/IChainableFilter.as      | 74 ++++++++++++++++++++++
 .../org/apache/royale/svg/SuperimposeFilter.as     | 65 +++++++++++++++++++
 4 files changed, 176 insertions(+), 5 deletions(-)

diff --git a/frameworks/projects/Graphics/src/main/resources/svg-manifest.xml b/frameworks/projects/Graphics/src/main/resources/svg-manifest.xml
index ed49401..b453bca 100644
--- a/frameworks/projects/Graphics/src/main/resources/svg-manifest.xml
+++ b/frameworks/projects/Graphics/src/main/resources/svg-manifest.xml
@@ -34,4 +34,5 @@
 	<component id="MaskBead" class="org.apache.royale.svg.MaskBead" />
 	<component id="DisableClipBead" class="org.apache.royale.svg.DisableClipBead" />
 	<component id="LinearGradient" class="org.apache.royale.svg.LinearGradient" />
+	<component id="SuperimposeFilter" class="org.apache.royale.svg.SuperimposeFilter" />
 </componentPackage>
diff --git a/frameworks/projects/Graphics/src/main/royale/org/apache/royale/svg/DropShadowFilter.as b/frameworks/projects/Graphics/src/main/royale/org/apache/royale/svg/DropShadowFilter.as
index fe79d37..02cdce9 100644
--- a/frameworks/projects/Graphics/src/main/royale/org/apache/royale/svg/DropShadowFilter.as
+++ b/frameworks/projects/Graphics/src/main/royale/org/apache/royale/svg/DropShadowFilter.as
@@ -34,7 +34,7 @@ package org.apache.royale.svg
 	 *  @playerversion AIR 2.6
 	 *  @productversion Royale 0.9.3
 	 */
-	public class DropShadowFilter extends Filter
+	public class DropShadowFilter extends Filter implements IChainableFilter
 	{
 		private var _dx:Number;
 		private var _dy:Number;
@@ -45,13 +45,14 @@ package org.apache.royale.svg
 		private var _opacity:Number = 1;
 		private var _spread:Number = 1;
 		private var _inset:Boolean;
+		private var _source:String;
+		private var _result:String;
 
 		public function DropShadowFilter()
 		{
 		}
 		
-		COMPILE::JS
-		override protected function filter():void
+		public function build():void
 		{
 			children = [];
 			if (inset)
@@ -92,8 +93,18 @@ package org.apache.royale.svg
 			}
 			var blend:BlendFilterElement = new BlendFilterElement();
 			children.push(blend);
-			blend.in = inset ? "compositeResult" : "SourceGraphic";
-			blend.in2 = inset ? "SourceGraphic" : "spreadResult";
+			blend.in = inset ? "compositeResult" : source ? source : "SourceGraphic";
+			blend.in2 = inset && !source ? "SourceGraphic" : inset && source ? source : "spreadResult";
+			if (result)
+			{
+				blend.result = result;
+			}
+		}
+
+		COMPILE::JS
+		override protected function filter():void
+		{
+			build();
 			super.filter();
 		}
 
@@ -268,6 +279,26 @@ package org.apache.royale.svg
 		{
 			_inset = value;
 		}
+
+		public function get source():String 
+		{
+			return _source;
+		}
+		
+		public function set source(value:String):void 
+		{
+			_source = value;
+		}
+
+		public function get result():String 
+		{
+			return _result;
+		}
+		
+		public function set result(value:String):void 
+		{
+			_result = value;
+		}
 	}
 }
 
diff --git a/frameworks/projects/Graphics/src/main/royale/org/apache/royale/svg/IChainableFilter.as b/frameworks/projects/Graphics/src/main/royale/org/apache/royale/svg/IChainableFilter.as
new file mode 100644
index 0000000..29f2b56
--- /dev/null
+++ b/frameworks/projects/Graphics/src/main/royale/org/apache/royale/svg/IChainableFilter.as
@@ -0,0 +1,74 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.royale.svg
+{
+    /**
+     *  The IChainableFilter interface describes a filter that can be a part of a chain of filters
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.9.3
+     */
+	public interface IChainableFilter
+	{
+        /**
+		 *  This method builds the filter's children.
+         * 
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.3
+         */
+		function build():void
+			
+			
+        /**
+		 *  This method returns the elements representing the filter primitives.
+         * 
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.3
+         */
+		function get children():Array
+			
+		
+        /**
+		 *  This method sets the result of this filter to be used in a subsequent chain element.
+         * 
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.3
+         */
+		function set result(value:String):void
+			
+		/**
+		 *  This method sets the source of this filter which can be a result from a previous chain element.
+         * 
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.3
+         */
+		function set source(value:String):void
+
+	}
+}
\ No newline at end of file
diff --git a/frameworks/projects/Graphics/src/main/royale/org/apache/royale/svg/SuperimposeFilter.as b/frameworks/projects/Graphics/src/main/royale/org/apache/royale/svg/SuperimposeFilter.as
new file mode 100644
index 0000000..ecabf26
--- /dev/null
+++ b/frameworks/projects/Graphics/src/main/royale/org/apache/royale/svg/SuperimposeFilter.as
@@ -0,0 +1,65 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.royale.svg
+{
+	
+	/**
+	 *  SuperimposeFilter composes superimposes several filters one on top of the other.
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion Royale 0.9.3
+	 */
+	public class SuperimposeFilter extends Filter
+	{
+		public function SuperimposeFilter()
+		{
+		}
+		
+		COMPILE::JS
+		override protected function filter():void
+		{
+			var newChildren:Array = [];
+			for (var i:int = 0; i < children.length; i++)
+			{
+				var chainable:IChainableFilter = children[i] as IChainableFilter;
+				chainable.result = "chainableResult" + i;
+				if (i != 0)
+				{
+					chainable.source = "chainableResult" + (i - 1);
+				}
+				chainable.build();
+				addArray(newChildren, chainable.children);
+			}
+			children = newChildren;
+			super.filter();
+		}
+		
+		COMPILE::JS
+		private function addArray(original:Array, addition:Array):void
+		{
+			for (var i:int = 0; i < addition.length; i++)
+			{
+				original.push(addition[i]);
+			}
+		}
+	}
+}
+