class org.aswing.graphics.Graphics2D

Encapsulate and enhance flash.display.graphics drawing API.
To draw with this API, you need to create a pen. To fill an area with this API, you need to create a brush.
You can find sampe usage of this api in the test package which will come with the source package.

Here is an sample on how to use the org.aswing.grphics package to draw stuff

var mySprite:Sprite = new Sprite(); g = new Graphics2D(mySprite.graphics); var color:ASColor = new ASColor(); var matrix:Matrix = new Matrix(); matrix.createGradientBox(100,100,90/(Math.PI*2),200,200);
	var pen:Pen = new Pen(2,color.getRGB());
	g.drawLine(pen,0,0,100,100);
	 

	var gpen:GradientPen = new GradientPen(1,GradientType.LINEAR,[0xff00ff,0x00ff00,0xffff00],[1,1,1],[0,200,255],matrix);
	g.drawLine(gpen,400,100,500,500);
	
	var gBrush:GradientBrush= new GradientBrush(GradientType.LINEAR,[0xff00ff,0x00ff00,0xffff00],[1,1,1],[0,200,255],matrix);
	var sBrush:SolidBrush = new SolidBrush(ASColor.HALO_BLUE.getRGB(),0.3);
	var bBrush:BitmapBrush = new BitmapBrush(new BitmapData(50,50,false,0xffff00));
	
	g.fillEllipse(gBrush,100,100,300,200);
	g.fillRectangle(sBrush,100,100,100,100);
	g.fillRectangle(bBrush,0,0,50,50);

	addChild(mySprite);

@see org.aswing.graphics @author paling

Instance Fields

function new(target:Graphics): Void

Constructor take instance of flash.display.Graphics as parameter. usually, you can the instance from a displayObject's graphics property

@see http://livedocs.macromedia.com/flex/2/langref/flash/display/Graphics.html

target

where the graphics contexts will be paint on. the target is an instance of flash.display.Graphics

function beginDraw(pen:IPen): Void

Start to draw lines with pen

function beginFill(brush:IBrush): Void

Start to fill a closed area with brush

function circle(centerX:Float, centerY:Float, radius:Float): Void

Paths a circle

@see #drawCircle() @see #fillCircle()

centerX

x corrdinate of the center of the circle.

centerY

y corrdinate of the center of the circle.

radius

the radius of circle.

function clear(): Void

Clears the graphics contexts drawn on the target Graphics.

function curveTo(controlX:Float, controlY:Float, anchorX:Float, anchorY:Float): Void

Paths a curve @see http://livedocs.macromedia.com/flex/2/langref/flash/display/Graphics.html#curveTo()

function drawCircle(pen:IPen, centerX:Float, centerY:Float, radius:Float): Void

Draws a circle.

pen

the pen to draw.

cx

the center of the circle's x corrdinate.

cy

the center of the circle's y corrdinate.

radius

the radius of the circle.

function drawEllipse(pen:IPen, x:Float, y:Float, width:Float, height:Float): Void

Draws a ellipse.

pen

the pen to draw.

x

the left top the ellipse bounds' x corrdinate.

y

the left top the ellipse bounds' y corrdinate.

width

the width of ellipse bounds.

height

the height of ellipse bounds.

function drawLine(p:IPen, x1:Float, y1:Float, x2:Float, y2:Float): Void

Draw a line between the points (x1, y1) and (x2, y2) in the target Graphics.

p

the pen to draw. Pen can be a normal Pen or a GradientPen

x1

the x corrdinate of the first point.

y1

the y corrdinate of the first point.

x2

the x corrdinate of the sencod point.

y2

the y corrdinate of the sencod point.

function drawPolygon(pen:Pen, points:Array<Dynamic>): Void

Draws a polygon.(close figure automaticlly)
Start to draw a ploygon with the points[0] as the start point and go through all the points in the array then go back to the points[0] end it as a closed path.

@see #polygon()

pen

the pen to draw

points

the Array contains all vertex points in the polygon.

function drawPolyline(p:IPen, points:Array<Dynamic>): Void

Draws a polyline. (not close figure automaticlly)
Start with the points[0] and end with the points[points.length-1] as a closed path.

@see #polyline()

p

the pen to draw

points

the Array contains all vertex points in the polygon.

function drawRectangle(pen:IPen, x:Float, y:Float, width:Float, height:Float): Void

Draws a rectange.

pen

the pen to draw.

x

the left top the rectange bounds' x corrdinate.

y

the left top the rectange bounds' y corrdinate.

width

the width of rectange bounds.

height

the height of rectange bounds.

function drawRoundRect(pen:IPen, x:Float, y:Float, width:Float, height:Float, radius:Float, ?trR:Float = -1, ?blR:Float = -1, ?brR:Float = -1): Void

Draws a round rectangle.

pen

the pen to draw.

x

the left top the rectangle bounds' x corrdinate.

y

the left top the rectangle bounds' y corrdinate.

width

the width of rectangle bounds.

height

the height of rectangle bounds.

radius

the top left corner's round radius.

trR

(optional)the top right corner's round radius. (miss this param default to same as radius)

blR

(optional)the bottom left corner's round radius. (miss this param default to same as radius)

brR

(optional)the bottom right corner's round radius. (miss this param default to same as radius)

function ellipse(x:Float, y:Float, width:Float, height:Float): Void

Paths an ellipse. @see #drawEllipse() @see #fillEllipse()

x

the x corrdinate of the ellipse.

y

the y corrdinate of the ellipse.

width

the width corrdinate of ellipse.

height

the width corrdinate of ellipse.

function endDraw(): Void

Stop drawing

function endFill(): Void

Stop filling a closed area with brush

function fillCircle(brush:IBrush, centerX:Float, centerY:Float, radius:Float): Void

Fills a circle.

brush

the brush to draw.

centerX

the center of the circle's x corrdinate.

centerY

the center of the circle's y corrdinate.

radius

the radius of the circle.

function fillCircleRing(brush:IBrush, centerX:Float, centerY:Float, radius1:Float, radius2:Float): Void

Fills a circle ring.

brush

the brush to draw.

centerX

the center of the ring's x corrdinate.

centerY

the center of the ring's y corrdinate.

radius1

the first circle radius.

radius2

the second circle radius.

function fillCircleRingWithThickness(brush:IBrush, centerX:Float, centerY:Float, radius:Float, thickness:Float): Void

Fills a circle ring with a specified thickness.

brush

the brush to draw.

centerX

the center of the ring's x corrdinate.

centerY

the center of the ring's y corrdinate.

radius

the radius of circle periphery.

thickness

the thickness of the ring.

function fillEllipse(brush:IBrush, x:Float, y:Float, width:Float, height:Float): Void

Fills a rectange.

brush

the brush to fill.

x

the left top the ellipse bounds' x corrdinate.

y

the left top the ellipse bounds' y corrdinate.

width

the width of ellipse bounds.

height

the height of ellipse bounds.

function fillEllipseRing(brush:IBrush, centerX:Float, centerY:Float, width1:Float, height1:Float, width2:Float, height2:Float): Void

Fill a ellipse ring.

brush

the brush to fill.

centerX

the center of the ring's x corrdinate.

centerY

the center of the ring's y corrdinate.

width1

the first eclipse's width.

height1

the first eclipse's height.

width2

the second eclipse's width.

height2

the second eclipse's height.

function fillEllipseRingWithThickness(brush:IBrush, x:Float, y:Float, width:Float, height:Float, thickness:Float): Void

Fill a ellipse ring with specified thickness.

brush

the brush to fill.

x

the left top the ring bounds' x corrdinate.

y

the left top the ring bounds' y corrdinate.

width

the width of ellipse periphery bounds.

height

the height of ellipse periphery bounds.

thickness

the thickness of the ring.

function fillPolygon(brush:IBrush, points:Array<Dynamic>): Void

Fills a polygon.(close figure automaticlly)
Start with the points[0] and end of the points[0] as a closed path.

@see #polygon()

brush

the brush to fill.

points

the Array contains all vertex points in the polygon.

function fillPolygonRing(brush:IBrush, points1:Array<Dynamic>, points2:Array<Dynamic>): Void

Fills a polygon ring.

@see #fillPolygon()

b

the brush to fill.

points1

the first polygon's points.

points2

the second polygon's points.

function fillPolyline(b:IBrush, points:Array<Dynamic>): Void

Fills a polygon.(not close figure automaticlly)
Start with the points[0] and end with the points[points.length-1] as a closed path.

@see #polyline()

b

the brush to fill.

points

the Array contains all vertex points in the polygon.

function fillRectangle(brush:IBrush, x:Float, y:Float, width:Float, height:Float): Void

Fills a rectange.

brush

the brush to fill.

x

the left top the rectange bounds' x corrdinate.

y

the left top the rectange bounds' y corrdinate.

width

the width of rectange bounds.

height

the height of rectange bounds.

function fillRectangleRing(brush:IBrush, centerX:Float, centerY:Float, width1:Float, height1:Float, width2:Float, height2:Float): Void

Fills a rectange ring.

brush

the brush to fill.

centerX

the center of the ring's x corrdinate.

centerY

the center of the ring's y corrdinate.

width1

the first rectange's width.

height1

the first rectange's height.

width2

the second rectange's width.

height2

the second rectange's height.

function fillRectangleRingWithThickness(brush:IBrush, x:Float, y:Float, width:Float, height:Float, thickness:Float): Void

Fills a rectange ring with a specified thickness.

brush

the brush to fill.

x

the left top the ring bounds' x corrdinate.

y

the left top the ring bounds' y corrdinate.

width

the width of ring periphery bounds.

height

the height of ring periphery bounds.

thickness

the thickness of the ring.

function fillRoundRect(brush:IBrush, x:Float, y:Float, width:Float, height:Float, radius:Float, ?topRightRadius:Float = -1, ?bottomLeftRadius:Float = -1, ?bottomRightRadius:Float = -1): Void

Fills a round rectangle.

brush

the brush to fill.

x

the left top the rectangle bounds' x corrdinate.

y

the left top the rectangle bounds' y corrdinate.

width

the width of rectangle bounds.

height

the height of rectangle bounds.

radius

the radius of the top left corner, if other corner radius is -1, will use this radius as default

topRightRadius

the radius of the top right corner, if omitted, use the top left as default.

bottomLeftRadius

the radius of the bottom left corner, if omitted, use the top left as default.

bottomRightRadius

the radius of the bottom right corner, if omitted, use the top left as default.

function fillRoundRectRing(brush:IBrush, centerX:Float, centerY:Float, width1:Float, height1:Float, radius1:Float, width2:Float, height2:Float, radius2:Float): Void

Fill a round rect ring.

brush

the brush to fill

centerX

the center of the ring's x corrdinate

centerY

the center of the ring's y corrdinate

width1

the first round rect's width

height1

the first round rect's height

radius1

the first round rect's round radius

width2

the second round rect's width

height2

the second round rect's height

radius2

the second round rect's round radius

function fillRoundRectRingWithThickness(brush:IBrush, x:Float, y:Float, width:Float, height:Float, radius:Float, thickness:Float, ?innerRadius:Float = -1): Void

Fill a round rect ring with specified thickness.

brush

the brush to fill

x

the left top the ring bounds' x corrdinate

y

the left top the ring bounds' y corrdinate

width

the width of ring periphery bounds

height

the height of ring periphery bounds

radius

the round radius of the round rect

thickness

the thickness of the ring

innerRadius

the inboard round radius, default is r-t

function line(x1:Float, y1:Float, x2:Float, y2:Float): Void

Paths a line between the points (x1, y1) and (x2, y2) in the target Graphics.

x1

the x corrdinate of the first point.

y1

the y corrdinate of the first point.

x2

the x corrdinate of the sencod point.

y2

the y corrdinate of the sencod point.

function lineTo(x:Float, y:Float): Void

function moveTo(x:Float, y:Float): Void

Delegate Graphics.moveTo(x,y);

function polygon(points:Array<Dynamic>): Void

Paths a polygon.(close figure automaticlly)

@see #drawPolygon() @see #fillPolygon() @see #polyline()

points

the points of the polygon, the array length should be larger than 1

function polyline(points:Array<Dynamic>): Void

Paths a polyline(not close figure automaticlly).

@see #drawPolyline() @see #fillPolyline() @see #polygon()

points

the points of the polygon, the array length should be larger than 1

function rectangle(x:Float, y:Float, width:Float, height:Float): Void

Paths a rectangle.

@see #drawRectangle() @see #fillRectangle()

x

the x corrdinate of the rectangle.

y

the y corrdinate of the rectangle.

width

the width corrdinate of rectangle.

height

the width corrdinate of rectangle.

function roundRect(x:Float, y:Float, width:Float, height:Float, radius:Float, ?trR:Float = -1, ?blR:Float = -1, ?brR:Float = -1): Void

Paths a round rect.

@see #drawRoundRect() @see #fillRoundRect()

x

the x corrdinate of the roundRect.

y

the y corrdinate of the roundRect.

width

the width corrdinate of roundRect.

height

the width corrdinate of roundRect.

radius

the radius of the top left corner, if other corner radius is -1, will use this radius as default

topRightRadius

(optional)the radius of the top right corner, if omitted, use the top left as default.

bottomLeftRadius

(optional)the radius of the bottom left corner, if omitted, use the top left as default.

bottomRightRadius

(optional)the radius of the bottom right corner, if omitted, use the top left as default.

function wedge(radius:Float, x:Float, y:Float, angle:Float): Void

@private don't generate doc for this method yet Paths a wedge.