Return-Path: X-Original-To: apmail-flex-commits-archive@www.apache.org Delivered-To: apmail-flex-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1983711B8F for ; Wed, 17 Sep 2014 01:25:26 +0000 (UTC) Received: (qmail 36535 invoked by uid 500); 17 Sep 2014 01:25:26 -0000 Delivered-To: apmail-flex-commits-archive@flex.apache.org Received: (qmail 36481 invoked by uid 500); 17 Sep 2014 01:25:25 -0000 Mailing-List: contact commits-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list commits@flex.apache.org Received: (qmail 36467 invoked by uid 99); 17 Sep 2014 01:25:25 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Sep 2014 01:25:25 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 9C287A178CD; Wed, 17 Sep 2014 01:25:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bigosmallm@apache.org To: commits@flex.apache.org Date: Wed, 17 Sep 2014 01:25:25 -0000 Message-Id: <23c9fad92f9543709c7dec5ccb306071@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/7] git commit: [flex-asjs] [refs/heads/develop] - Added support for LinearGradient on AS3 side. JS version, up next Repository: flex-asjs Updated Branches: refs/heads/develop e6419b7a8 -> 9999c237a Added support for LinearGradient on AS3 side. JS version, up next Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/4fce4e59 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/4fce4e59 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/4fce4e59 Branch: refs/heads/develop Commit: 4fce4e59e119a55d1959eec6cbb316d0d830fb57 Parents: e6419b7 Author: Om Authored: Mon Sep 15 12:24:41 2014 -0700 Committer: Om Committed: Tue Sep 16 18:24:44 2014 -0700 ---------------------------------------------------------------------- examples/FlexJSTest_SVG/src/GraphicsView.mxml | 21 ++ .../as/projects/FlexJSUI/src/FlexJSUIClasses.as | 1 + .../src/org/apache/flex/core/graphics/Circle.as | 15 +- .../org/apache/flex/core/graphics/Ellipse.as | 13 +- .../apache/flex/core/graphics/GradientBase.as | 191 +++++++++++++++++++ .../apache/flex/core/graphics/GradientEntry.as | 127 ++++++++++++ .../apache/flex/core/graphics/GraphicShape.as | 18 +- .../flex/core/graphics/GraphicsContainer.as | 11 +- .../src/org/apache/flex/core/graphics/IFill.as | 4 +- .../apache/flex/core/graphics/LinearGradient.as | 56 ++++++ .../src/org/apache/flex/core/graphics/Path.as | 13 +- .../src/org/apache/flex/core/graphics/Rect.as | 13 +- .../org/apache/flex/core/graphics/SolidColor.as | 4 +- 13 files changed, 432 insertions(+), 55 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4fce4e59/examples/FlexJSTest_SVG/src/GraphicsView.mxml ---------------------------------------------------------------------- diff --git a/examples/FlexJSTest_SVG/src/GraphicsView.mxml b/examples/FlexJSTest_SVG/src/GraphicsView.mxml index 5e562df..bad453c 100644 --- a/examples/FlexJSTest_SVG/src/GraphicsView.mxml +++ b/examples/FlexJSTest_SVG/src/GraphicsView.mxml @@ -26,7 +26,9 @@ limitations under the License. rotation property to control the transition direction. + * For example, a value of 180.0 causes the transition + * to occur from right to left, rather than from left to right. + * + * @default 0.0 + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Flex 3 + */ + public function get rotation():Number + { + return _rotation; + } + + /** + * @private + */ + public function set rotation(value:Number):void + { + _rotation = value; + } + + + private var _x:Number = 0; + + /** + * The distance by which to translate each point along the x axis. + */ + public function get x():Number + { + return _x; + } + + /** + * @private + */ + public function set x(value:Number):void + { + _x = value; + } + + private var _y:Number = 0; + + /** + * The distance by which to translate each point along the y axis. + */ + public function get y():Number + { + return _y; + } + + /** + * @private + */ + public function set y(value:Number):void + { + _y = value; + } + + + protected function toRad(a:Number):Number { + return a*Math.PI/180; + } + + /** + * @private + * Extract the gradient information in the public entries + * Array into the internal colors, ratios, + * and alphas arrays. + */ + private function processEntries():void + { + colors = []; + ratios = []; + alphas = []; + + if (!_entries || _entries.length == 0) + return; + + var ratioConvert:Number = 255; + + var i:int; + + var n:int = _entries.length; + for (i = 0; i < n; i++) + { + var e:GradientEntry = _entries[i]; + colors.push(e.color); + alphas.push(e.alpha); + ratios.push(e.ratio * ratioConvert); + } + + if (isNaN(ratios[0])) + ratios[0] = 0; + + if (isNaN(ratios[n - 1])) + ratios[n - 1] = 255; + + i = 1; + + while (true) + { + while (i < n && !isNaN(ratios[i])) + { + i++; + } + + if (i == n) + break; + + var start:int = i - 1; + + while (i < n && isNaN(ratios[i])) + { + i++; + } + + var br:Number = ratios[start]; + var tr:Number = ratios[i]; + + for (var j:int = 1; j < i - start; j++) + { + ratios[j] = br + j * (tr - br) / (i - start); + } + } + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4fce4e59/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/GradientEntry.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/GradientEntry.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/GradientEntry.as new file mode 100644 index 0000000..92a1765 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/GradientEntry.as @@ -0,0 +1,127 @@ +/** + * Licensed 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.graphics +{ + public class GradientEntry + { + + //---------------------------------- + // alpha + //---------------------------------- + + private var _alpha:Number = 1.0; + //---------------------------------- + // color + //---------------------------------- + + private var _color:uint = 0x000000; + //---------------------------------- + // ratio + //---------------------------------- + + private var _ratio:Number = 0x000000; + + + public function GradientEntry(alpha:Number, color:uint, ratio:Number) + { + _alpha = alpha; + _color = color; + _ratio = ratio; + } + + /** + * The transparency of a color. + * Possible values are 0.0 (invisible) through 1.0 (opaque). + * + * @default 1.0 + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.3 + */ + public function get alpha():Number + { + return _alpha; + } + + public function set alpha(value:Number):void + { + var oldValue:Number = _alpha; + if (value != oldValue) + { + _alpha = value; + } + } + + /** + * A color value. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.3 + */ + public function get color():uint + { + return _color; + } + + public function set color(value:uint):void + { + var oldValue:uint = _color; + if (value != oldValue) + { + _color = value; + } + } + + /** + * Where in the graphical element, as a percentage from 0.0 to 1.0, + * Flex samples the associated color at 100%. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion FlexJS 0.3 + */ + public function get ratio():Number + { + return _ratio; + } + + public function set ratio(value:Number):void + { + _ratio = value; + } + + /** + * Begin drawing the fill on the given shape's graphic object + */ + public function begin(s:GraphicShape):void + { + s.graphics.beginFill(color,alpha); + } + + /** + * End the fill + */ + public function end(s:GraphicShape):void + { + s.graphics.endFill(); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4fce4e59/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/GraphicShape.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/GraphicShape.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/GraphicShape.as index c2ab3f5..65c4f32 100644 --- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/GraphicShape.as +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/GraphicShape.as @@ -15,14 +15,16 @@ package org.apache.flex.core.graphics { + import flash.geom.Rectangle; + import org.apache.flex.core.UIBase; public class GraphicShape extends UIBase { - private var _fill:SolidColor; - private var _stroke:SolidColorStroke; + private var _fill:IFill; + private var _stroke:IStroke; - public function get stroke():SolidColorStroke + public function get stroke():IStroke { return _stroke; } @@ -35,12 +37,12 @@ package org.apache.flex.core.graphics * @playerversion AIR 1.1 * @productversion FlexJS 0.0 */ - public function set stroke(value:SolidColorStroke):void + public function set stroke(value:IStroke):void { _stroke = value; } - public function get fill():SolidColor + public function get fill():IFill { return _fill; } @@ -52,7 +54,7 @@ package org.apache.flex.core.graphics * @playerversion AIR 1.1 * @productversion FlexJS 0.0 */ - public function set fill(value:SolidColor):void + public function set fill(value:IFill):void { _fill = value; } @@ -65,11 +67,11 @@ package org.apache.flex.core.graphics } } - protected function beginFill():void + protected function beginFill(targetBounds:Rectangle):void { if(fill) { - fill.begin(this); + fill.begin(this, targetBounds); } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4fce4e59/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/GraphicsContainer.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/GraphicsContainer.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/GraphicsContainer.as index 2d1c347..c99b3a7 100644 --- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/GraphicsContainer.as +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/GraphicsContainer.as @@ -14,9 +14,8 @@ package org.apache.flex.core.graphics { - import flash.display.CapsStyle; import flash.display.GraphicsPath; - import flash.display.JointStyle; + import flash.geom.Rectangle; import org.apache.flex.core.graphics.utils.PathHelper; @@ -45,7 +44,7 @@ package org.apache.flex.core.graphics public function drawRect(x:Number, y:Number, width:Number, height:Number):void { applyStroke(); - beginFill(); + beginFill(new Rectangle(x, y, width, height)); graphics.drawRect(x, y, width, height); endFill(); } @@ -65,7 +64,7 @@ package org.apache.flex.core.graphics public function drawEllipse(x:Number, y:Number, width:Number, height:Number):void { applyStroke(); - beginFill(); + beginFill(new Rectangle(x,y,width,height)); graphics.drawEllipse(x,y,width,height); endFill(); } @@ -84,7 +83,7 @@ package org.apache.flex.core.graphics public function drawCircle(x:Number, y:Number, radius:Number):void { applyStroke(); - beginFill(); + beginFill(new Rectangle(x,y,radius*2, radius*2)); graphics.drawCircle(x,y,radius); endFill(); } @@ -107,7 +106,7 @@ package org.apache.flex.core.graphics public function drawPath(data:String):void { applyStroke(); - beginFill(); + beginFill(new Rectangle()); var graphicsPath:GraphicsPath = PathHelper.getSegments(data); graphics.drawPath(graphicsPath.commands, graphicsPath.data); endFill(); http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4fce4e59/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/IFill.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/IFill.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/IFill.as index 65c35b0..6ecbb8a 100644 --- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/IFill.as +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/IFill.as @@ -14,9 +14,11 @@ package org.apache.flex.core.graphics { + import flash.geom.Rectangle; + public interface IFill { - function begin(s:GraphicShape):void; + function begin(s:GraphicShape,targetBounds:Rectangle):void; function end(s:GraphicShape):void; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4fce4e59/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/LinearGradient.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/LinearGradient.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/LinearGradient.as new file mode 100644 index 0000000..87d1fb0 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/LinearGradient.as @@ -0,0 +1,56 @@ +/** + * Licensed 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.graphics +{ + import flash.display.GradientType; + import flash.display.InterpolationMethod; + import flash.display.SpreadMethod; + import flash.geom.Matrix; + import flash.geom.Rectangle; + + public class LinearGradient extends GradientBase implements IFill + { + + private static var commonMatrix:Matrix = new Matrix(); + private var _scaleX:Number; + + /** + * The horizontal scale of the gradient transform, which defines the width of the (unrotated) gradient + */ + public function get scaleX():Number + { + return _scaleX; + } + + public function set scaleX(value:Number):void + { + _scaleX = value; + } + + public function begin(s:GraphicShape,targetBounds:Rectangle):void + { + commonMatrix.identity(); + commonMatrix.createGradientBox(targetBounds.width,targetBounds.height,toRad(this.rotation)); + + s.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, + commonMatrix, SpreadMethod.PAD, InterpolationMethod.RGB); + } + + public function end(s:GraphicShape):void + { + s.graphics.endFill(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4fce4e59/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/Path.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/Path.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/Path.as index 6f8324f..ec14340 100644 --- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/Path.as +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/Path.as @@ -29,22 +29,15 @@ package org.apache.flex.core.graphics public function drawPath(x:Number,y:Number,data:String):void { graphics.clear(); - if(stroke) - { - graphics.lineStyle(stroke.weight,stroke.color,stroke.alpha,false,"normal",CapsStyle.SQUARE,JointStyle.MITER); - } - if(fill) - { - graphics.beginFill(fill.color,fill.alpha); - } + applyStroke(); + beginFill(new Rectangle()); segments = new PathSegmentsCollection(data); if (segments) segments.generateGraphicsPath(graphicsPath, x, y, 1, 1); graphics.drawPath(graphicsPath.commands, graphicsPath.data); - graphics.endFill(); + endFill(); } - } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4fce4e59/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/Rect.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/Rect.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/Rect.as index 989477d..6d82bf6 100644 --- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/Rect.as +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/Rect.as @@ -2,6 +2,7 @@ package org.apache.flex.core.graphics { import flash.display.CapsStyle; import flash.display.JointStyle; + import flash.geom.Rectangle; public class Rect extends GraphicShape { @@ -21,16 +22,10 @@ package org.apache.flex.core.graphics public function drawRect(x:Number, y:Number, width:Number, height:Number):void { graphics.clear(); - if(stroke) - { - graphics.lineStyle(stroke.weight,stroke.color,stroke.alpha,false,"normal",CapsStyle.SQUARE,JointStyle.MITER); - } - if(fill) - { - graphics.beginFill(fill.color,fill.alpha); - } + applyStroke(); + beginFill(new Rectangle(x, y, width, height)); graphics.drawRect(x, y, width, height); - graphics.endFill(); + endFill(); } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4fce4e59/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/SolidColor.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/SolidColor.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/SolidColor.as index 2c2dc08..bc0d913 100644 --- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/SolidColor.as +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/SolidColor.as @@ -14,6 +14,8 @@ package org.apache.flex.core.graphics { + import flash.geom.Rectangle; + public class SolidColor implements IFill { @@ -75,7 +77,7 @@ package org.apache.flex.core.graphics } } - public function begin(s:GraphicShape):void + public function begin(s:GraphicShape,targetBounds:Rectangle):void { s.graphics.beginFill(color,alpha); }