Draw circles!
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/5f12977f Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/5f12977f Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/5f12977f Branch: refs/heads/develop Commit: 5f12977fd4199edb95d0c7b50589266f440fd619 Parents: 35efe0f Author: Om <[email protected]> Authored: Fri Sep 5 18:10:34 2014 -0700 Committer: Om <[email protected]> Committed: Fri Sep 5 18:10:34 2014 -0700 ---------------------------------------------------------------------- examples/FlexJSTest_SVG/src/GraphicsView.mxml | 20 +++++++ .../as/projects/FlexJSUI/src/FlexJSUIClasses.as | 1 + .../src/org/apache/flex/core/graphics/Circle.as | 39 +++++++++++++ .../src/org/apache/flex/core/graphics/Circle.js | 59 ++++++++++++++++++++ 4 files changed, 119 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5f12977f/examples/FlexJSTest_SVG/src/GraphicsView.mxml ---------------------------------------------------------------------- diff --git a/examples/FlexJSTest_SVG/src/GraphicsView.mxml b/examples/FlexJSTest_SVG/src/GraphicsView.mxml index 7a68173..5f097d3 100644 --- a/examples/FlexJSTest_SVG/src/GraphicsView.mxml +++ b/examples/FlexJSTest_SVG/src/GraphicsView.mxml @@ -24,6 +24,7 @@ limitations under the License. > <fx:Script> <![CDATA[ + import org.apache.flex.core.graphics.Circle; import org.apache.flex.core.graphics.Ellipse; import org.apache.flex.core.graphics.Rect; import org.apache.flex.core.graphics.SolidColor; @@ -109,6 +110,25 @@ limitations under the License. ellipse3.stroke = stroke; ellipse3.drawEllipse(250,150,300,250); this.addElement(ellipse3); + + var circle1:Circle = new Circle(); + fill.color = 0xee11bb; + circle1.fill = fill; + stroke.color = 0x123456; + stroke.weight = 2; + circle1.stroke = stroke; + circle1.drawCircle(700,300,200); + this.addElement(circle1); + + var circle2:Circle = new Circle(); + fill.color = 0xabbaab; + fill.alpha = 0.8; + circle2.fill = fill; + stroke.color = 0xccff11; + stroke.weight = 5; + circle2.stroke = stroke; + circle2.drawCircle(100,700,100); + this.addElement(circle2); } ]]> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5f12977f/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as b/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as index 2df8fce..b27a2ba 100644 --- a/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as +++ b/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as @@ -122,6 +122,7 @@ internal class FlexJSUIClasses import org.apache.flex.core.graphics.GraphicShape; GraphicShape; import org.apache.flex.core.graphics.Rect; Rect; import org.apache.flex.core.graphics.Ellipse; Ellipse; + import org.apache.flex.core.graphics.Circle; Circle; import org.apache.flex.core.graphics.SolidColor; SolidColor; import org.apache.flex.core.graphics.SolidColorStroke; SolidColorStroke; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5f12977f/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/Circle.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/Circle.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/Circle.as new file mode 100644 index 0000000..b02e978 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/graphics/Circle.as @@ -0,0 +1,39 @@ +package org.apache.flex.core.graphics +{ + + public class Circle extends GraphicShape + { + + private var _x:Number; + private var _y:Number; + private var _width:Number; + private var _height:Number; + + /** + * Draw the circle. + * @param x The x location of the center of the circle + * @param y The y location of the center of the circle. + * @param radius The radius of the circle. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function drawCircle(x:Number, y:Number, radius:Number):void + { + graphics.clear(); + if(stroke) + { + graphics.lineStyle(stroke.weight,stroke.color,stroke.alpha); + } + if(fill) + { + graphics.beginFill(fill.color,fill.alpha); + } + graphics.drawCircle(x,y,radius); + graphics.endFill(); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/5f12977f/frameworks/js/FlexJS/src/org/apache/flex/core/graphics/Circle.js ---------------------------------------------------------------------- diff --git a/frameworks/js/FlexJS/src/org/apache/flex/core/graphics/Circle.js b/frameworks/js/FlexJS/src/org/apache/flex/core/graphics/Circle.js new file mode 100644 index 0000000..b044c92 --- /dev/null +++ b/frameworks/js/FlexJS/src/org/apache/flex/core/graphics/Circle.js @@ -0,0 +1,59 @@ +/** + * 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. + */ + +goog.provide('org.apache.flex.core.graphics.Circle'); + +goog.require('org.apache.flex.core.graphics.GraphicShape'); + + + +/** + * @constructor + * @extends {org.apache.flex.core.graphics.GraphicShape} + */ +org.apache.flex.core.graphics.Circle = function() { + org.apache.flex.core.graphics.Circle.base(this, 'constructor'); + +}; +goog.inherits(org.apache.flex.core.graphics.Circle, + org.apache.flex.core.graphics.GraphicShape); + + +/** + * Metadata + * + * @type {Object.<string, Array.<Object>>} + */ +org.apache.flex.core.graphics.Circle.prototype.FLEXJS_CLASS_INFO = + { names: [{ name: 'Circle', + qName: 'org.apache.flex.core.graphics.Circle' }] }; + + +/** + * @expose + * @param {number} x The x location of the center of the circle + * @param {number} y The x location of the center of the circle + * @param {number} radius The radius of the circle. + */ +org.apache.flex.core.graphics.Circle.prototype.drawCircle = function(x, y, radius) { + var style = this.getStyleStr(); + var circle = document.createElementNS('http://www.w3.org/2000/svg', 'ellipse'); + circle.setAttribute('style', style); + circle.setAttribute('cx', String(radius + this.get_stroke().get_weight() )); + circle.setAttribute('cy', String(radius + this.get_stroke().get_weight() )); + circle.setAttribute('rx', String(radius)); + circle.setAttribute('ry', String(radius)); + this.element.appendChild(circle); + this.resize(x-radius,y-radius,radius*2+this.get_stroke().get_weight()*2,radius*2+this.get_stroke().get_weight()*2); +};
