//////////////////////////////////////////////////////////////////////////////// // // 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.events.EventDispatcher; import flash.geom.Matrix; import flash.geom.Rectangle; import spark.primitives.Path; import mx.events.PropertyChangeEvent; /** * The PathSegment class is the base class for a segment of a path. * This class is not created directly. It is the base class for * MoveSegment, LineSegment, CubicBezierSegment and QuadraticBezierSegment. * * @see spark.primitives.pathSegments.CubicBezierSegment * @see spark.primitives.pathSegments.LineSegment * @see spark.primitives.pathSegments.MoveSegment * @see mx.graphics.QuadraticSegment * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public class PathSegment extends EventDispatcher { include "../../core/Version.as"; //-------------------------------------------------------------------------- // // Constructor // //-------------------------------------------------------------------------- /** * Constructor. * * @param x The x position of the pen in the current coordinate system. * * @param y The y position of the pen in the current coordinate system. * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public function PathSegment(x:Number = 0, y:Number = 0) { super(); _x = x; _y = y; } //-------------------------------------------------------------------------- // // Properties // //-------------------------------------------------------------------------- //---------------------------------- // segmentHost //---------------------------------- /** * The host of the segment. * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public var segmentHost:Path; //---------------------------------- // x //---------------------------------- private var _x:Number = 0; [Bindable("propertyChange")] [Inspectable(category="General")] /** * The ending x position for this segment. * * @default 0 * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public function get x():Number { return _x; } /** * @private */ public function set x(value:Number):void { var oldValue:Number = _x; if (value != oldValue) { _x = value; dispatchSegmentChangedEvent("x", oldValue, value); } } //---------------------------------- // y //---------------------------------- private var _y:Number = 0; [Bindable("propertyChange")] [Inspectable(category="General")] /** * The ending y position for this segment. * * @default 0 * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public function get y():Number { return _y; } /** * @private */ public function set y(value:Number):void { var oldValue:Number = _y; if (value != oldValue) { _y = value; dispatchSegmentChangedEvent("y", oldValue, value); } } //-------------------------------------------------------------------------- // // Methods // //-------------------------------------------------------------------------- /** * Notifies our host that this segment has changed. * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ protected function notifySegmentChanged():void { if (segmentHost) segmentHost.segmentChanged(this); } /** * Draws this path segment. You can determine the current pen position by * reading the x and y values of the previous segment. * * @param g The graphics context to draw into. * @param prev The previous segment drawn, or null if this is the first segment. * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public function draw(graphicsPath:GraphicsPath, dx:Number,dy:Number,sx:Number,sy:Number,prev:PathSegment):void { // Override to draw your segment } /** * @param prev The previous segment drawn, or null if this is the first segment. * @param sx Pre-transform scale factor for x coordinates. * @param sy Pre-transform scale factor for y coordinates. * @param m Transformation matrix. * @param rect If non-null, rect is expanded to include the bounding box of the segment. * @return Returns the union of rect and the axis aligned bounding box of the post-transformed * path segment. * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public function getBoundingBox(prev:PathSegment, sx:Number, sy:Number, m:Matrix, rect:Rectangle):Rectangle { // Override to calculate your segment's bounding box. return rect; } /** * @private */ protected function dispatchSegmentChangedEvent(prop:String, oldValue:*, value:*):void { notifySegmentChanged(); dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, prop, oldValue, value)); } } }