1 50 51 package org.openlaszlo.iv.flash.api.shape; 52 53 import java.awt.geom.*; 54 import java.io.PrintStream ; 55 import org.openlaszlo.iv.flash.util.*; 56 import org.openlaszlo.iv.flash.api.*; 57 import org.openlaszlo.iv.flash.parser.*; 58 import org.openlaszlo.iv.flash.api.image.*; 59 60 66 public final class MorphFillStyle extends FlashItem { 67 68 private int type; private Color color_start; private Color color_end; private AffineTransform matrix_start; private AffineTransform matrix_end; private MorphGradient gradient; private Bitmap bitmap; 76 public MorphFillStyle() {} 77 78 public int getType() { 79 return type; 80 } 81 82 public void setType( int type ) { 83 this.type = type; 84 } 85 86 public Color getColorStart() { 87 return color_start; 88 } 89 90 public void setColorStart( Color color ) { 91 this.color_start = color; 92 } 93 94 public Color getColorEnd() { 95 return color_end; 96 } 97 98 public void setColorEnd( Color color ) { 99 this.color_end = color; 100 } 101 102 public AffineTransform getMatrixStart() { 103 return matrix_start; 104 } 105 106 public void setMatrixStart( AffineTransform matrix ) { 107 this.matrix_start = matrix; 108 } 109 110 public AffineTransform getMatrixEnd() { 111 return matrix_end; 112 } 113 114 public void setMatrixEnd( AffineTransform matrix ) { 115 this.matrix_end = matrix; 116 } 117 118 public MorphGradient getGraduent() { 119 return gradient; 120 } 121 122 public void setGradient( MorphGradient gradient ) { 123 this.gradient = gradient; 124 } 125 126 public Bitmap getBitmap() { 127 return bitmap; 128 } 129 130 public void setBitmap( Bitmap bitmap ) { 131 this.bitmap = bitmap; 132 } 133 134 141 public static MorphFillStyle newSolid( Color color_start, Color color_end ) { 142 MorphFillStyle fs = new MorphFillStyle(); 143 fs.setColorStart( color_start ); 144 fs.setColorEnd( color_end ); 145 fs.setType( FillStyle.SOLID ); 146 return fs; 147 } 148 149 157 public static MorphFillStyle newLinearGradient( 158 MorphGradient gradient, 159 AffineTransform matrix_start, 160 AffineTransform matrix_end ) 161 { 162 MorphFillStyle fs = new MorphFillStyle(); 163 fs.setGradient( gradient ); 164 fs.setMatrixStart( matrix_start ); 165 fs.setMatrixEnd( matrix_end ); 166 fs.setType( FillStyle.LINEAR_GRADIENT ); 167 return fs; 168 } 169 170 178 public static MorphFillStyle newRadialGradient( 179 MorphGradient gradient, 180 AffineTransform matrix_start, 181 AffineTransform matrix_end ) 182 { 183 MorphFillStyle fs = new MorphFillStyle(); 184 fs.setGradient( gradient ); 185 fs.setMatrixStart( matrix_start ); 186 fs.setMatrixEnd( matrix_end ); 187 fs.setType( FillStyle.RADIAL_GRADIENT ); 188 return fs; 189 } 190 191 199 public static MorphFillStyle newTiledBitmap( 200 Bitmap bitmap, 201 AffineTransform matrix_start, 202 AffineTransform matrix_end ) 203 { 204 MorphFillStyle fs = new MorphFillStyle(); 205 fs.setBitmap( bitmap ); 206 fs.setMatrixStart( matrix_start ); 207 fs.setMatrixEnd( matrix_end ); 208 fs.setType( FillStyle.TILED_BITMAP ); 209 return fs; 210 } 211 212 220 public static MorphFillStyle newClippedBitmap( 221 Bitmap bitmap, 222 AffineTransform matrix_start, 223 AffineTransform matrix_end ) 224 { 225 MorphFillStyle fs = new MorphFillStyle(); 226 fs.setBitmap( bitmap ); 227 fs.setMatrixStart( matrix_start ); 228 fs.setMatrixEnd( matrix_end ); 229 fs.setType( FillStyle.CLIPPED_BITMAP ); 230 return fs; 231 } 232 233 239 public static MorphFillStyle parse( Parser p ) { 240 MorphFillStyle fs = new MorphFillStyle(); 241 int type = fs.type = p.getUByte(); 242 243 if( (type&0x10) != 0 ) { 245 fs.matrix_start = p.getMatrix(); 247 fs.matrix_end = p.getMatrix(); 248 fs.gradient = MorphGradient.parse(p); 250 251 } else if( (type&0x40) != 0 ) { 253 int id = p.getUWord(); fs.bitmap = (Bitmap) p.getDef(id); 255 fs.matrix_start = p.getMatrix(); 256 fs.matrix_end = p.getMatrix(); 257 258 } else { 260 fs.color_start = AlphaColor.parse(p); 261 fs.color_end = AlphaColor.parse(p); 262 } 263 264 return fs; 265 } 266 267 272 public void write( FlashOutput fob ) { 273 fob.writeByte(type); 274 switch( type ) { 275 case FillStyle.SOLID: 276 color_start.writeRGBA(fob); 277 color_end.writeRGBA(fob); 278 break; 279 case FillStyle.LINEAR_GRADIENT: 280 case FillStyle.RADIAL_GRADIENT: 281 fob.write(matrix_start); 282 fob.write(matrix_end); 283 gradient.write(fob); 284 break; 285 case FillStyle.TILED_BITMAP: 286 case FillStyle.CLIPPED_BITMAP: 287 if( bitmap == null ) { 288 fob.writeWord(0xffff); 289 } else { 290 fob.writeDefID(bitmap); 291 } 292 fob.write(matrix_start); 293 fob.write(matrix_end); 294 break; 295 } 296 } 297 298 public void printContent( PrintStream out, String indent ) { 299 switch( type ) { 300 case FillStyle.SOLID: 301 out.println( indent+"MorphFillStyle (SOLID):" ); 302 color_start.printContent(out, indent+" "); 303 color_end.printContent(out, indent+" "); 304 break; 305 case FillStyle.LINEAR_GRADIENT: 306 out.println( indent+"MorphFillStyle (LINEAR_GRADIENT):" ); 307 out.println( indent+" "+matrix_start ); 308 out.println( indent+" "+matrix_end ); 309 gradient.printContent(out, indent+" "); 310 break; 311 case FillStyle.RADIAL_GRADIENT: 312 out.println( indent+"FillStyle (RADIAL_GRADIENT):" ); 313 out.println( indent+" "+matrix_start ); 314 out.println( indent+" "+matrix_end ); 315 gradient.printContent(out, indent+" "); 316 break; 317 case FillStyle.TILED_BITMAP: 318 out.println( indent+"FillStyle (TILED_BITMAP):" ); 319 out.println( indent+" "+matrix_start ); 320 out.println( indent+" "+matrix_end ); 321 out.println( indent+" bitmapID="+bitmap.getID() ); 322 break; 323 case FillStyle.CLIPPED_BITMAP: 324 out.println( indent+"FillStyle (CLIPPED_BITMAP):" ); 325 out.println( indent+" "+matrix_start ); 326 out.println( indent+" "+matrix_end ); 327 out.println( indent+" bitmapID="+bitmap.getID() ); 328 break; 329 } 330 } 331 332 protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) { 333 ((MorphFillStyle)item).type = type; 334 switch( type ) { 335 case FillStyle.SOLID: 336 ((MorphFillStyle)item).color_start = (Color) color_start.getCopy(copier); 337 ((MorphFillStyle)item).color_end = (Color) color_end.getCopy(copier); 338 break; 339 case FillStyle.LINEAR_GRADIENT: 340 case FillStyle.RADIAL_GRADIENT: 341 ((MorphFillStyle)item).gradient = (MorphGradient) gradient.getCopy(copier); 342 ((MorphFillStyle)item).matrix_start = (AffineTransform) matrix_start.clone(); 343 ((MorphFillStyle)item).matrix_end = (AffineTransform) matrix_end.clone(); 344 break; 345 case FillStyle.TILED_BITMAP: 346 case FillStyle.CLIPPED_BITMAP: 347 ((MorphFillStyle)item).bitmap = (Bitmap) copier.copy(bitmap); 348 ((MorphFillStyle)item).matrix_start = (AffineTransform) matrix_start.clone(); 349 ((MorphFillStyle)item).matrix_end = (AffineTransform) matrix_end.clone(); 350 break; 351 } 352 return item; 353 } 354 355 public FlashItem getCopy( ScriptCopier copier ) { 356 return copyInto( new MorphFillStyle(), copier ); 357 } 358 } 359 360 | Popular Tags |