@@ -25,8 +25,7 @@ var TextStyle = new Class({
2525
2626 function TextStyle ( text , style )
2727 {
28- // Needed?
29- this . text = text ;
28+ this . parent = text ;
3029
3130 this . font = propertyMap . font [ 1 ] ;
3231 this . backgroundColor = propertyMap . backgroundColor [ 1 ] ;
@@ -48,6 +47,39 @@ var TextStyle = new Class({
4847 }
4948 } ,
5049
50+ syncFont : function ( canvas , context )
51+ {
52+ context . font = this . font ;
53+ context . textBaseline = 'alphabetic' ;
54+
55+ context . fillStyle = this . fill ;
56+ context . strokeStyle = this . stroke ;
57+
58+ context . lineWidth = this . strokeThickness ;
59+ context . lineCap = 'round' ;
60+ context . lineJoin = 'round' ;
61+ } ,
62+
63+ syncShadow : function ( canvas , context , visible )
64+ {
65+ var style = this . style ;
66+
67+ if ( visible )
68+ {
69+ context . shadowOffsetX = style . shadowOffsetX ;
70+ context . shadowOffsetY = style . shadowOffsetY ;
71+ context . shadowColor = style . shadowColor ;
72+ context . shadowBlur = style . shadowBlur ;
73+ }
74+ else
75+ {
76+ context . shadowOffsetX = 0 ;
77+ context . shadowOffsetY = 0 ;
78+ context . shadowColor = 0 ;
79+ context . shadowBlur = 0 ;
80+ }
81+ } ,
82+
5183 setStyle : function ( style )
5284 {
5385 for ( var key in propertyMap )
@@ -58,26 +90,102 @@ var TextStyle = new Class({
5890 return this ;
5991 } ,
6092
61- syncToCanvas : function ( canvas , context )
93+ setFont : function ( font )
6294 {
63- context . font = this . font ;
64- context . textBaseline = 'alphabetic' ;
6595
66- context . fillStyle = this . fill ;
67- context . strokeStyle = this . stroke ;
96+ this . font = font ;
6897
69- context . lineWidth = this . strokeThickness ;
70- context . lineCap = 'round' ;
71- context . lineJoin = 'round' ;
98+ this . parent . updateText ( ) ;
99+
100+ return this ;
72101 } ,
73102
74- setFont : function ( font )
103+ setBackgroundColor : function ( color )
75104 {
76- this . font = font ;
105+ this . backgroundColor = color ;
77106
78- // Tell Text it changed
107+ this . parent . updateText ( ) ;
108+
109+ return this ;
79110 } ,
80111
112+ setFill : function ( color )
113+ {
114+ this . fill = color ;
115+
116+ this . parent . updateText ( ) ;
117+
118+ return this ;
119+ } ,
120+
121+ setStroke : function ( color , thickness )
122+ {
123+ if ( color === undefined )
124+ {
125+ // Reset the stroke to zero (disabling it)
126+ this . strokeThickness = 0 ;
127+ }
128+ else
129+ {
130+ if ( thickness === undefined ) { thickness = this . strokeThickness ; }
131+
132+ this . stroke = color ;
133+ this . strokeThickness = thickness ;
134+ }
135+
136+ this . parent . updateText ( ) ;
137+
138+ return this ;
139+ } ,
140+
141+ setShadow : function ( x , y , color , blur , shadowStroke , shadowFill )
142+ {
143+ if ( x === undefined ) { x = 0 ; }
144+ if ( y === undefined ) { y = 0 ; }
145+ if ( color === undefined ) { color = '#000' ; }
146+ if ( blur === undefined ) { blur = 0 ; }
147+ if ( shadowStroke === undefined ) { shadowStroke = false ; }
148+ if ( shadowFill === undefined ) { shadowFill = false ; }
149+
150+ this . shadowOffsetX = x ;
151+ this . shadowOffsetY = y ;
152+ this . shadowColor = color ;
153+ this . shadowBlur = blur ;
154+ this . shadowStroke = shadowStroke ;
155+ this . shadowFill = shadowFill ;
156+
157+ this . parent . updateText ( ) ;
158+
159+ return this ;
160+ } ,
161+
162+ setAlign : function ( align )
163+ {
164+ if ( align === undefined ) { align = 'left' ; }
165+
166+ this . align = align ;
167+
168+ this . parent . updateText ( ) ;
169+
170+ return this ;
171+ } ,
172+
173+ setMaxLines : function ( max )
174+ {
175+ if ( max === undefined ) { max = 0 ; }
176+
177+ this . maxLines = max ;
178+
179+ this . parent . updateText ( ) ;
180+
181+ return this ;
182+ } ,
183+
184+ destroy : function ( )
185+ {
186+ this . parent = undefined ;
187+ }
188+
81189} ) ;
82190
83191module . exports = TextStyle ;
0 commit comments