You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by yi...@apache.org on 2016/09/25 12:42:20 UTC

git commit: [flex-asjs] [refs/heads/refactor-sprite] - Add ClipBead

Repository: flex-asjs
Updated Branches:
  refs/heads/refactor-sprite 1f40ba6b4 -> b4cbb8b31


Add ClipBead


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

Branch: refs/heads/refactor-sprite
Commit: b4cbb8b31d84496ef20daca0cd2da8eaf2a9135a
Parents: 1f40ba6
Author: yishayw <yi...@hotmail.com>
Authored: Sun Sep 25 15:42:10 2016 +0300
Committer: yishayw <yi...@hotmail.com>
Committed: Sun Sep 25 15:42:10 2016 +0300

----------------------------------------------------------------------
 .../Graphics/src/main/flex/GraphicsClasses.as   |   1 +
 .../main/flex/org/apache/flex/svg/ClipBead.as   | 164 +++++++++++++++++++
 .../src/main/resources/svg-manifest.xml         |   1 +
 3 files changed, 166 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b4cbb8b3/frameworks/projects/Graphics/src/main/flex/GraphicsClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Graphics/src/main/flex/GraphicsClasses.as b/frameworks/projects/Graphics/src/main/flex/GraphicsClasses.as
index ae4f401..88c45bc 100644
--- a/frameworks/projects/Graphics/src/main/flex/GraphicsClasses.as
+++ b/frameworks/projects/Graphics/src/main/flex/GraphicsClasses.as
@@ -39,6 +39,7 @@ internal class GraphicsClasses
 	import org.apache.flex.svg.Text; Text;
 	import org.apache.flex.svg.CompoundGraphic; CompoundGraphic;
 	import org.apache.flex.svg.TransformBead; TransformBead;
+	import org.apache.flex.svg.ClipBead; ClipBead;
 	import org.apache.flex.svg.LinearGradient; LinearGradient;
 	import org.apache.flex.graphics.CubicCurve; CubicCurve;
 	import org.apache.flex.graphics.LineStyle; LineStyle;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b4cbb8b3/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/ClipBead.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/ClipBead.as b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/ClipBead.as
new file mode 100644
index 0000000..b07a66c
--- /dev/null
+++ b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/ClipBead.as
@@ -0,0 +1,164 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.svg
+{
+	
+	import org.apache.flex.core.IBead;
+	import org.apache.flex.core.IRenderedObject;
+	import org.apache.flex.core.IStrand;
+	import org.apache.flex.graphics.PathBuilder;
+
+	COMPILE::SWF {
+	import flash.display.Graphics;
+	import flash.display.Sprite;
+	import flash.display.DisplayObject;
+	}
+
+	public class ClipBead implements IBead
+	{
+		private var _strand:IStrand;
+		private var _path:PathBuilder;
+		private var document:Object;
+		
+		public function ClipBead()
+		{
+		}
+		
+		public function get path():PathBuilder
+		{
+			return _path;
+		}
+		
+		public function set path(value:PathBuilder):void
+		{
+			_path = value;
+			clip();
+		}
+		
+		/**
+		 *  @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;
+			if (path)
+			{
+				clip();
+			}
+		}
+		
+		COMPILE::SWF
+		private function clip():void
+		{
+			if (!path)
+			{
+				return;
+			}
+			var element:DisplayObject = host.$displayObject as DisplayObject;
+			var mask:Sprite = new Sprite();
+			var g:Graphics = mask.graphics;
+			g.beginFill(0);
+			path.draw(g);
+			g.endFill();
+			if (element.mask && element.mask.parent)
+			{
+				element.mask.parent.removeChild(element.mask);
+			}
+			if (element.parent)
+			{
+				element.parent.addChild(mask);
+			}
+			mask.x = element.x;
+			mask.y = element.y;
+			element.mask = mask;
+		}
+		/**
+		 * @flexjsignorecoercion Element
+		 * @flexjsignorecoercion Object
+		 */
+		COMPILE::JS
+		private function clip():void
+		{
+			if (!path || !host)
+			{
+				return;
+			}
+			var svgElement:Node = host.element as Element;
+			var defs:Element = getChildNode(svgElement, "defs") as Element;
+			var clipPath:Element = getChildNode(defs, "clipPath") as Element;
+			clipPath.id = "myClip"; // TODO UUID
+			// clean up existing clip paths
+			if (clipPath.hasChildNodes())
+			{
+				var childNodes:Object = clipPath.childNodes;
+				for (var i:int = 0; i < childNodes.length; i++)
+				{
+					clipPath.removeChild(childNodes[i]);
+				}
+			}
+			// create pathNode
+			var pathNode:Element = createChildNode(clipPath, "path") as Element;
+			pathNode.setAttribute("d", path.getPathString());
+			// set style 
+			var content:Element = defs.previousSibling ? defs.previousSibling as Element : defs.nextSibling as Element;
+			(content.style as Object).clipPath = "url(#" + clipPath.id + ")";
+		}
+		
+		COMPILE::JS
+		private function getChildNode(node:Node, tagName:String):Node
+		{
+			if (!node.hasChildNodes())
+			{
+				return createChildNode(node, tagName);
+			}
+			var childNodes:Object = node.childNodes;
+			for (var i:int = 0; i < childNodes.length; i++)
+			{
+				if (childNodes[i].tagName == tagName)
+				{
+					return childNodes[i];
+				}
+					
+			}
+			return createChildNode(node, tagName);
+		}
+		
+		COMPILE::JS
+		private function createChildNode(parent:Node, tagName:String):Node
+		{
+			var svgNs:String = "http://www.w3.org/2000/svg";
+			var element:Node = window.document.createElementNS(svgNs, tagName);
+			parent.appendChild(element);
+			return element;
+		}
+		
+		public function get host():IRenderedObject
+		{
+			trace('hi_js221');
+			return _strand as IRenderedObject;
+		}
+		
+	}
+}
+

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b4cbb8b3/frameworks/projects/Graphics/src/main/resources/svg-manifest.xml
----------------------------------------------------------------------
diff --git a/frameworks/projects/Graphics/src/main/resources/svg-manifest.xml b/frameworks/projects/Graphics/src/main/resources/svg-manifest.xml
index 6e42f2e..d61ddd9 100644
--- a/frameworks/projects/Graphics/src/main/resources/svg-manifest.xml
+++ b/frameworks/projects/Graphics/src/main/resources/svg-manifest.xml
@@ -27,5 +27,6 @@
 	<component id="CompoundGraphic" class="org.apache.flex.svg.CompoundGraphic" />
 	<component id="GraphicContainer" class="org.apache.flex.svg.GraphicContainer" />
 	<component id="TransformBead" class="org.apache.flex.svg.TransformBead" />
+	<component id="ClipBead" class="org.apache.flex.svg.ClipBead" />
 	<component id="LinearGradient" class="org.apache.flex.svg.LinearGradient" />
 </componentPackage>