/** * com.jR.Drawing.Ellipse * March 14th, 2006 * Copyright (c) Jānis Radiņš ( janis@mediaverk.lv ) * * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class com.jR.Drawing.Ellipse extends com.jR.Drawing.Base { private var _radius:Number = null; private var _radiusX:Number = null; private var _radiusY:Number = null; private var _innerRadius:Number = null; private var _startAngle:Number = 0; private var _endAngle:Number = 0; private var _showOuterLine:Boolean = true; private var _showInnerLine:Boolean = true; private var _joinLines:Boolean = true; private var _drawX:Number = 0; private var _drawY:Number = 0; private var outerPoints:Array = null; private var innerPoints:Array = null; public function Ellipse(host:MovieClip, level:Number) { if (level === undefined) { level = host.getNextHighestDepth(); } _mc = host.createEmptyMovieClip("ellipse_"+level, level); } public function get radius():Number { return _radiusX == _radiusY ? _radiusX : null; } public function get radiusX():Number { return _radiusX; } public function get radiusY():Number { return _radiusY; } public function get innerRadius():Number { return _innerRadius; } public function get startAngle():Number { return _startAngle; } public function get endAngle():Number { return _endAngle; } public function get showOuterLine():Boolean { return _showOuterLine; } public function get showInnerLine():Boolean { return _showInnerLine; } public function get joinLines():Boolean { return _joinLines; } public function get drawX():Number { return _drawX; } public function get drawY():Number { return _drawY; } public function set radius(value:Number):Void { _radiusX = _radiusY = value; } public function set radiusX(value:Number):Void { _radiusX = value; if (_radiusY === null) { _radiusY = _radiusX; } } public function set radiusY(value:Number):Void { _radiusY = value; if (_radiusX === null) { _radiusX = _radiusY; } } public function set innerRadius(value:Number):Void { _innerRadius = value; } public function set startAngle(value:Number):Void { _startAngle = value; } public function set endAngle(value:Number):Void { _endAngle = value; } public function set showOuterLine(value:Boolean):Void { _showOuterLine = value; } public function set showInnerLine(value:Boolean):Void { _showInnerLine = value; } public function set joinLines(value:Boolean):Void { _joinLines = value; } public function set drawX(value:Number):Void { _drawX = value; } public function set drawY(value:Number):Void { _drawY = value; } public function reset(Void):Void { super.reset(); clear(); _radiusX = null; _radiusY = null; _innerRadius = null; _startAngle = 0; _endAngle = 0; _showOuterLine = true; _showInnerLine = true; _joinLines = true; _drawX = 0; _drawY = 0; } private function dealArguments(__inputObject:Object):Void { if(_autoClear == true){ clear(); } for (var i in __inputObject) { if (this["_"+i] !== undefined && this[i] !== undefined) { this[i] = __inputObject[i]; } } } public function drawOutline(__props:Object):Void { dealArguments(__props); calculatePoints(); draw(true); } public function drawSolid(__props:Object):Void { dealArguments(__props); calculatePoints(); beginFill(); draw(false); endFill(); } public function drawGradient(__props:Object):Void { dealArguments(__props); calculatePoints(); if (_rotation != 0 && _gradientType == "radial"){ _gradientX = _drawX; _gradientY = _drawY; } else { _gradientX = _drawX-_radiusX; _gradientY = _drawY-_radiusY; } _gradientWidth = _radiusX*2; _gradientHeight = _radiusY*2; _gradientRotation = _rotation; beginGradientFill(); draw(false); endFill(); } private function calculatePoints(Void):Void { if (_radiusX == null && _radiusY == null) { throwError("No way to draw ellipse"); return; } outerPoints = innerPoints=null; outerPoints = getSectorPoints(_startAngle, _endAngle, _radiusX); if (_innerRadius != null && _innerRadius != 0) { innerPoints = getSectorPoints(_startAngle, _endAngle, _innerRadius); innerPoints.reverse(); } squeeze(); rotatePoints(); } private function squeeze(Void):Void { if (_radiusX == _radiusY) { return; } var squeezePower:Number = _radiusY/_radiusX; for (var i:Number = 0; i0) { __pointA = outerPoints.shift(); __pointB = outerPoints.shift(); __pointA.x += _drawX; __pointA.y += _drawY; __pointB.x += _drawX; __pointB.y += _drawY; _mc.curveTo(__pointA.x, __pointA.y, __pointB.x, __pointB.y); } if (_startAngle%360 != _endAngle%360) { if (_joinLines == true) { applyLineStyle(forceOutline); } else { resetLineStyle(); } if (innerPoints != null) { __pointA = innerPoints.shift(); } else { __pointA = {x:0, y:0}; } __pointA.x += _drawX; __pointA.y += _drawY; _mc.curveTo(__pointA.x, __pointA.y, __pointA.x, __pointA.y); } else if (innerPoints != null) { __pointA = innerPoints.shift(); __pointA.x += _drawX; __pointA.y += _drawY; _mc.moveTo(__pointA.x, __pointA.y); } if (innerPoints == null) { return; } if (_showInnerLine == true) { applyLineStyle(forceOutline); } else { resetLineStyle(); } while (innerPoints.length>0) { __pointA = innerPoints.shift(); __pointB = innerPoints.shift(); __pointA.x += _drawX; __pointA.y += _drawY; __pointB.x += _drawX; __pointB.y += _drawY; _mc.curveTo(__pointA.x, __pointA.y, __pointB.x, __pointB.y); } } }