package com.lafabrick.uigfx.primitives
{
import com.lafabrick.uigfx.geom.ConstraintPoint;
import com.lafabrick.uigfx.utils.UigfxUtils;
import flash.display.Graphics;
import flash.geom.Point;
import spark.primitives.supportClasses.FilledElement;
/**
* Draw a form, using a vector of points
*
* @author Fabien Bizot
*
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion Flex 4
*
* @see http://lafabrick.com/blog
* @see com.lafabrick.uigfx.utils.UigfxUtils
* @see com.lafabrick.uigfx.geom.ConstraintPoint
*
* @example
* <p>The following code draws a star with five branch, using points with static positions</p>
* <listing version="3.0" >
* <primitives:PointsPath
* radius="60" width="100%" height="100%"
* horizontalCenter="0" verticalCenter="0">
*
* <primitives:points>
* <geom:ConstraintPoint x="100" y="0" />
* <geom:ConstraintPoint x="125" y="75" />
* <geom:ConstraintPoint x="200" y="75" />
* <geom:ConstraintPoint x="140" y="125" />
* <geom:ConstraintPoint x="160" y="200" />
* <geom:ConstraintPoint x="100" y="155" />
* <geom:ConstraintPoint x="40" y="200" />
* <geom:ConstraintPoint x="60" y="125" />
* <geom:ConstraintPoint x="0" y="75" />
* <geom:ConstraintPoint x="75" y="75" />
* </primitives:points>
*
* <primitives:fill>
* <s:SolidColor color="#222222" />
* </primitives:fill>
*
* <primitives:filters>
* <s:DropShadowFilter color="#000000" inner="true" distance="1" blurX="4" blurY="4" quality="3" alpha="0.8" />
* </primitives:filters>
*
* </primitives:PointsPath>
* </listing>
* <p>The following code draws a star with five branch, using points with forced placement</p>
* <listing version="3.0" >
* <primitives:PointsPath
* radius="60" width="100%" height="100%"
* horizontalCenter="0" verticalCenter="0">
*
* <primitives:points>
* <geom:ConstraintPoint top="0" horizontalCenter="0" />
* <geom:ConstraintPoint horizontalCenter="25" verticalCenter="-25"/>
* <geom:ConstraintPoint right="0" verticalCenter="-25" />
* <geom:ConstraintPoint horizontalCenter="40" verticalCenter="25" />
* <geom:ConstraintPoint right="40" bottom="0" />
* <geom:ConstraintPoint horizontalCenter="0" verticalCenter="40" />
* <geom:ConstraintPoint left="40" bottom="0" />
* <geom:ConstraintPoint horizontalCenter="-40" verticalCenter="25" />
* <geom:ConstraintPoint left="0" verticalCenter="-25" />
* <geom:ConstraintPoint horizontalCenter="-25" verticalCenter="-25" />
* </primitives:points>
*
* <primitives:fill>
* <s:SolidColor color="#222222" />
* </primitives:fill>
*
* <primitives:filters>
* <s:DropShadowFilter color="#000000" inner="true" distance="1" blurX="4" blurY="4" quality="3" alpha="0.8" />
* </primitives:filters>
*
* </primitives:PointsPath>
* </listing>
*
*/
public class PointsPath extends FilledElement
{
/**
* Constructor
*/
public function PointsPath()
{
super();
}
/**
* @private
*/
private var _points : Vector.<ConstraintPoint>;
/**
* @private
*/
private var _radius : Number = 0;
/**
* the rounded corner of the path
*/
public function get radius():Number
{
return _radius;
}
/**
* @private
*/
public function set radius(value:Number):void
{
_radius = value;
invalidateDisplayList();
}
/**
* define the crossing points of the form. It's a vector of constraint point Vector.<ConstraintPoint>
* @see com.lafabrick.uigfx.geom.ConstraintPoint
*/
public function get points():Vector.<ConstraintPoint>
{
return _points;
}
/**
* @private
*/
public function set points(value:Vector.<ConstraintPoint>):void
{
_points = value;
invalidateDisplayList();
}
/**
* Draw the path
* <p>Drawing method is static, in UigfxUtils</p>
* @see com.lafabrick.uigfx.utils.UigfxUtils
*/
override protected function draw(g:Graphics) : void
{
var vectorPoint : Vector.<Point> = new Vector.<Point>();
for each( var point : ConstraintPoint in points ) {
vectorPoint.push( point.getConstraintPoint( this ) );
}
UigfxUtils.drawRoundPath( g, vectorPoint, radius, true );
}
}
}