//////////////////////////////////////////////////////////////////////////////// // // ADOBE SYSTEMS INCORPORATED // Copyright 2003-2006 Adobe Systems Incorporated // All Rights Reserved. // // NOTICE: Adobe permits you to use, modify, and distribute this file // in accordance with the terms of the license agreement accompanying it. // //////////////////////////////////////////////////////////////////////////////// package spark.primitives.pathSegments { import flash.display.GraphicsPath; import flash.geom.Matrix; import flash.geom.Point; import flash.geom.Rectangle; import mx.utils.MatrixUtil; /** * The QuadraticBezierSegment draws a quadratic curve from the current pen position * to x, y. * * Quadratic bezier is the native curve type * in Flash Player. * * @includeExample examples/CircleExample.mxml * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public class QuadraticBezierSegment extends PathSegment { include "../../core/Version.as"; //-------------------------------------------------------------------------- // // Constructor // //-------------------------------------------------------------------------- /** * Constructor. * *
For a QuadraticBezierSegment, there is one control point. A control point * is a point that defines the direction and amount of a Bezier curve. * The curved line never reaches the control point; however, the line curves as though being drawn * toward the control point.
* * @param control1X The x-axis location in 2-d coordinate space of the control point. * * @param control1Y The y-axis location in 2-d coordinate space of the control point. * * @param x The x-axis location of the starting point of the curve. * * @param y The y-axis location of the starting point of the curve. * * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public function QuadraticBezierSegment( control1X:Number = 0, control1Y:Number = 0, x:Number = 0, y:Number = 0) { super(x, y); _controlX = control1X; _controlY = control1Y; } //-------------------------------------------------------------------------- // // Properties // //-------------------------------------------------------------------------- //---------------------------------- // control1X //---------------------------------- private var _controlX:Number = 0; [Bindable("propertyChange")] [Inspectable(category="General")] /** * The control point's x position. * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public function get control1X():Number { return _controlX; } /** * @private */ public function set control1X(value:Number):void { var oldValue:Number = _controlX; if (value != oldValue) { _controlX = value; dispatchSegmentChangedEvent("control1X", oldValue, value); } } //---------------------------------- // control1Y //---------------------------------- private var _controlY:Number = 0; [Bindable("propertyChange")] [Inspectable(category="General")] /** * The control point's y position. * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public function get control1Y():Number { return _controlY; } /** * @private */ public function set control1Y(value:Number):void { var oldValue:Number = _controlY; if (value != oldValue) { _controlY = value; dispatchSegmentChangedEvent("control1Y", oldValue, value); } } //-------------------------------------------------------------------------- // // Methods // //-------------------------------------------------------------------------- /** * Draws the segment using the control point location and the x and y coordinates. * This method calls theGraphics.curveTo() method.
*
* @see flash.display.Graphics
*
* @param g The graphics context where the segment is drawn.
*
* @param prev The previous location of the pen.
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion Flex 4
*/
override public function draw(graphicsPath:GraphicsPath, dx:Number,dy:Number,sx:Number,sy:Number,prev:PathSegment):void
{
graphicsPath.curveTo(dx+control1X*sx, dy+control1Y*sy, dx+x*sx, dy+y*sy);
}
/**
* @inheritDoc
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion Flex 4
*/
override public function getBoundingBox(prev:PathSegment, sx:Number, sy:Number,
m:Matrix, rect:Rectangle):Rectangle
{
return MatrixUtil.getQBezierSegmentBBox(prev ? prev.x : 0, prev ? prev.y : 0,
control1X, control1Y, x, y, sx, sy, m, rect);
}
}
}