This is an automated email from the ASF dual-hosted git repository. harbs pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
commit a0dd53771e898c7e30e0bc12ae7b52a1d8e679f3 Author: DESKTOP-RH4S838\Yishay <[email protected]> AuthorDate: Wed Jun 27 13:22:35 2018 +0300 DropShadowFilter, first implementation --- .../Graphics/src/main/resources/svg-manifest.xml | 1 + .../royale/org/apache/royale/svg/DropShadowBead.as | 205 +++++++++++++++++++++ 2 files changed, 206 insertions(+) diff --git a/frameworks/projects/Graphics/src/main/resources/svg-manifest.xml b/frameworks/projects/Graphics/src/main/resources/svg-manifest.xml index 37f2182..ee91123 100644 --- a/frameworks/projects/Graphics/src/main/resources/svg-manifest.xml +++ b/frameworks/projects/Graphics/src/main/resources/svg-manifest.xml @@ -22,6 +22,7 @@ <componentPackage> <component id="TransformBead" class="org.apache.royale.svg.TransformBead" /> <component id="ClipBead" class="org.apache.royale.svg.ClipBead" /> + <component id="DropShadowBead" class="org.apache.royale.svg.DropShadowBead" /> <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" /> diff --git a/frameworks/projects/Graphics/src/main/royale/org/apache/royale/svg/DropShadowBead.as b/frameworks/projects/Graphics/src/main/royale/org/apache/royale/svg/DropShadowBead.as new file mode 100644 index 0000000..ef43f4f --- /dev/null +++ b/frameworks/projects/Graphics/src/main/royale/org/apache/royale/svg/DropShadowBead.as @@ -0,0 +1,205 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 +{ + + import org.apache.royale.core.IBead; + import org.apache.royale.core.IRenderedObject; + import org.apache.royale.core.IStrand; + + COMPILE::SWF { + import flash.display.Graphics; + import flash.display.Sprite; + import flash.display.DisplayObject; + } + + COMPILE::JS + { + import org.apache.royale.utils.UIDUtil; + } + /** + * The DropShadowBead bead allows you to filter + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.0 + */ + public class DropShadowBead implements IBead + { + private var _strand:IStrand; + private var _dx:Number = 0; + private var _dy:Number = 0; + private var _stdDeviation:Number = 0; + private var _width:String = "200%"; + private var _height:String = "200%"; + + public function DropShadowBead() + { + } + + /** + * @copy org.apache.royale.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9.3 + */ + public function set strand(value:IStrand):void + { + _strand = value; + filter(); + } + + COMPILE::SWF + private function filter():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(); +// // remove existing mask from display list +// if (element.mask && element.mask.parent) +// { +// element.mask.parent.removeChild(element.mask); +// } +// // add new mask to display list +// if (element.parent) +// { +// element.parent.addChild(mask); +// } +// // set mask +// mask.x = element.x; +// mask.y = element.y; +// element.mask = mask; + } + /** + * @royaleignorecoercion Element + * @royaleignorecoercion Object + */ + COMPILE::JS + private function filter():void + { + var svgElement:Node = host.element as Element; + var defs:Element = getChildNode(svgElement, "defs") as Element; + var filter:Element = getChildNode(defs, "filter") as Element; + filter.id = "myDropShadow" + UIDUtil.createUID(); + filter.setAttribute("width", _width); + filter.setAttribute("height", _height); + // clean up existing filter + if (filter.hasChildNodes()) + { + var childNodes:Object = filter.childNodes; + for (var i:int = 0; i < childNodes.length; i++) + { + filter.removeChild(childNodes[i]); + } + } + // create offset + var offset:Element = createChildNode(filter, "feOffset") as Element; + offset.setAttribute("dx", dx); + offset.setAttribute("dy", dy); + offset.setAttribute("in", "SourceAlpha"); + offset.setAttribute("result", "offsetResult"); + // create blur + var blur:Element = createChildNode(filter, "feGaussianBlur") as Element; + blur.setAttribute("stdDeviation", stdDeviation); + blur.setAttribute("result", "blurResult"); + // create blend + var blend:Element = createChildNode(filter, "feBlend") as Element; + blend.setAttribute("in", "SourceGraphic"); + blend.setAttribute("in2", "blurResult"); + blend.setAttribute("mode", "normal"); + // apply filter + host.element.style["filter"] = "url(#" + filter.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 + { + return _strand as IRenderedObject; + } + + public function get stdDeviation():Number + { + return _stdDeviation; + } + + public function set stdDeviation(value:Number):void + { + _stdDeviation = value; + } + + public function get dx():Number + { + return _dx; + } + + public function set dx(value:Number):void + { + _dx = value; + } + + public function get dy():Number + { + return _dy; + } + + public function set dy(value:Number):void + { + _dy = value; + } + + } +} +
