@@ -4,6 +4,7 @@ var Components = require('../../components');
44var Render = require ( './GraphicsRender' ) ;
55var Commands = require ( './Commands' ) ;
66var MATH_CONST = require ( '../../math/const' ) ;
7+ var GetObjectValue = require ( '../../utils/object/GetObjectValue' ) ;
78
89var Graphics = new Class ( {
910
@@ -18,14 +19,48 @@ var Graphics = new Class({
1819
1920 initialize :
2021
21- function Graphics ( state , x , y )
22+ function Graphics ( state , options )
2223 {
24+ var x = GetObjectValue ( options , 'x' , 0 ) ;
25+ var y = GetObjectValue ( options , 'y' , 0 ) ;
26+
2327 GameObject . call ( this , state ) ;
2428
2529 this . setPosition ( x , y ) ;
2630
2731 this . commandBuffer = [ ] ;
2832 this . initRenderPassComponent ( ) ;
33+
34+ this . defaultFillColor = - 1 ;
35+ this . defaultFillAlpha = 1 ;
36+
37+ this . defaultStrokeWidth = 1 ;
38+ this . defaultStrokeColor = - 1 ;
39+ this . defaultStrokeAlpha = 1 ;
40+
41+ this . setDefaultStyles ( options ) ;
42+ } ,
43+
44+ setDefaultStyles : function ( options )
45+ {
46+ if ( GetObjectValue ( options , 'lineStyle' , null ) )
47+ {
48+ this . defaultStrokeWidth = GetObjectValue ( options , 'lineStyle.width' , 1 ) ;
49+ this . defaultStrokeColor = GetObjectValue ( options , 'lineStyle.color' , 0xffffff ) ;
50+ this . defaultStrokeAlpha = GetObjectValue ( options , 'lineStyle.alpha' , 1 ) ;
51+
52+ this . lineStyle ( this . defaultStrokeWidth , this . defaultStrokeColor , this . defaultStrokeAlpha ) ;
53+ }
54+
55+ if ( GetObjectValue ( options , 'fillStyle' , null ) )
56+ {
57+ this . defaultFillColor = GetObjectValue ( options , 'fillStyle.color' , 0xffffff ) ;
58+ this . defaultFillAlpha = GetObjectValue ( options , 'fillStyle.alpha' , 1 ) ;
59+
60+ this . fillStyle ( this . defaultFillColor , this . defaultFillAlpha ) ;
61+ }
62+
63+ return this ;
2964 } ,
3065
3166 arc : function ( x , y , radius , startAngle , endAngle , anticlockwise )
@@ -96,6 +131,16 @@ var Graphics = new Class({
96131 return this ;
97132 } ,
98133
134+ strokeShape : function ( shape )
135+ {
136+
137+ } ,
138+
139+ fillShape : function ( shape )
140+ {
141+
142+ } ,
143+
99144 fillCircle : function ( x , y , radius )
100145 {
101146 this . beginPath ( ) ;
@@ -204,6 +249,16 @@ var Graphics = new Class({
204249 {
205250 this . commandBuffer . length = 0 ;
206251
252+ if ( this . defaultFillColor > - 1 )
253+ {
254+ this . fillStyle ( this . defaultFillColor , this . defaultFillAlpha ) ;
255+ }
256+
257+ if ( this . defaultStrokeColor > - 1 )
258+ {
259+ this . lineStyle ( this . defaultStrokeWidth , this . defaultStrokeColor , this . defaultStrokeAlpha ) ;
260+ }
261+
207262 return this ;
208263 }
209264
0 commit comments