11/**
2- * Created by jim on 5/19/14.
2+ * Graphics Polyfill for AS3
3+ * Author: Jim Chen
4+ * Part of the CCLScripter
35 */
46class Graphics {
57 private id :String ;
@@ -8,4 +10,153 @@ class Graphics {
810 id = parent . getId ( ) ;
911 }
1012
13+ private toRGB ( rgb :number ) :string {
14+ var output :string = parseInt ( rgb ) . toString ( 16 ) ;
15+ while ( output . length < 6 ) {
16+ output = "0" + output ;
17+ }
18+ return "#" + output ;
19+ }
20+
21+ private callDrawMethod ( method :string , params ) :void {
22+ __pchannel ( "Runtime:CallMethod" , {
23+ "id" : id ,
24+ "context" : "graphics" ,
25+ "method" : method ,
26+ "params" : params
27+ } ) ;
28+ }
29+
30+ /**
31+ * Line to point
32+ * @param x - x coordinate
33+ * @param y - y coordinate
34+ */
35+ public lineTo ( x :number , y :number ) :void {
36+ callDrawMethod ( "lineTo" , [ a , b ] ) ;
37+ }
38+
39+ /**
40+ * Move to point
41+ * @param x - x coordinate
42+ * @param y - y coordinate
43+ */
44+ public moveTo ( x :number , y :number ) :void {
45+ callDrawMethod ( "moveTo" , [ x , y ] ) ;
46+ }
47+
48+ /**
49+ * Quadratic Beizer Curve
50+ * @param cx - Control point x
51+ * @param cy - Control point y
52+ * @param ax - Anchor x
53+ * @param ay - Anchor y
54+ */
55+ public curveTo ( cx :number , cy :number , ax :number , ay :number ) :void {
56+ callDrawMethod ( "curveTo" , [ cx , cy , ax , ay ] ) ;
57+ }
58+
59+ /**
60+ * Cubic Beizer Curve
61+ * @param cax - Control point A x
62+ * @param cay - Control point A y
63+ * @param cbx - Control point B x
64+ * @param cby - Control point B y
65+ * @param ax - Anchor x
66+ * @param ay - Anchor y
67+ */
68+ public cubicCurveTo ( cax :number , cay :number , cbx :number , cby :number , ax :number , ay :number ) :void {
69+ callDrawMethod ( "cubicCurveTo" , [ cax , cay , cbx , cby , ax , ay ] ) ;
70+ }
71+
72+ /**
73+ * Set line style
74+ * @param thickness - line thickness
75+ * @param color - line color (default 0)
76+ * @param alpha - alpha (default 1)
77+ * @param hinting - pixel hinting (default false)
78+ * @param scale - scale mode (default "normal")
79+ * @param caps - line cap mode (default "none")
80+ * @param joints - line joint mode (default "round")
81+ * @param miterlim - miter limit (default 3)
82+ */
83+ public lineStyle ( thickness :number , color :number = 0 , alpha :number = 1.0 , hinting :boolean = false , scale :string = "normal" , caps :string = "none" , joints :string = "round" , miter :number = 3 ) :void {
84+ callDrawMethod ( "lineStyle" , [ thickness , color , alpha , caps , joints , miter ] ) ;
85+ }
86+
87+ /**
88+ * Draw a rectangle
89+ * @param x - x coordinate
90+ * @param y - y coordinate
91+ * @param w - width
92+ * @param h - height
93+ */
94+ public drawRect ( x :number , y :number , w :number , h :number ) :void {
95+ callDrawMethod ( "drawRect" , [ x , y , w , h ] ) ;
96+ }
97+
98+ /**
99+ * Draws a circle
100+ * @param x - center x
101+ * @param y - center y
102+ * @param r - radius
103+ */
104+ public drawCircle ( x :number , y :number , r :number ) :void {
105+ callDrawMethod ( "drawCircle" , [ x , y , r ] ) ;
106+ }
107+
108+ /**
109+ * Draws an ellipse
110+ * @param cx - center x
111+ * @param cy - center y
112+ * @param w - width
113+ * @param h - height
114+ */
115+ public drawEllipse ( cx :number , cy :number , w :number , h :number ) :void {
116+ callDrawMethod ( "drawEllipse" , [ cx + w / 2 , cy + h / 2 , w / 2 , h / 2 ] ) ;
117+ }
118+
119+ /**
120+ * Draws a rounded rectangle
121+ * @param x - x coordinate
122+ * @param y - y coordinate
123+ * @param w - width
124+ * @param h - height
125+ * @param elw - ellipse corner width
126+ * @param elh - ellipse corner height
127+ */
128+ public drawRoundRect ( x :number , y :number , w :number , h :number , elw :number , elh :number ) :void {
129+ callDrawMethod ( "drawRoundRect" , [ x , y , w , h , elw , elh ] ) ;
130+ }
131+
132+ /**
133+ * Fill next shape with solid color
134+ * @param color
135+ * @param alpha
136+ */
137+ public beginFill ( color :number , alpha :number = 1.0 ) :void {
138+ callDrawMethod ( "beginFill" , [ color , alpha ] ) ;
139+ }
140+
141+ public beginGradientFill ( ) :void {
142+ __trace ( "Graphics: Gradients not supported yet." , 'warn' ) ;
143+ }
144+
145+ public beginShaderFill ( ) :void {
146+ __trace ( "Graphics: Shaders not supported yet." , 'warn' ) ;
147+ }
148+
149+ /**
150+ * Stop and finalize fill
151+ */
152+ public endFill ( ) :void {
153+ callDrawMethod ( "endFill" , [ ] ) ;
154+ }
155+
156+ /**
157+ * Clears everything the current graphics context has drawn
158+ */
159+ public clear ( ) :void {
160+ callDrawMethod ( "clear" , [ ] ) ;
161+ }
11162}
0 commit comments