1 50 51 package org.openlaszlo.iv.flash.api.shape; 52 53 import java.io.PrintStream ; 54 import java.awt.geom.*; 55 import java.util.*; 56 57 import org.openlaszlo.iv.flash.parser.*; 58 import org.openlaszlo.iv.flash.util.*; 59 import org.openlaszlo.iv.flash.api.*; 60 61 101 public final class MorphShape extends FlashDef { 102 103 private MorphShapeStyles shape_styles; private ShapeRecords records_start; private ShapeRecords records_end; private Rectangle2D bounds_start; private Rectangle2D bounds_end; 109 112 public MorphShape() { 113 } 114 115 120 public MorphShapeStyles getShapeStyles() { 121 if( shape_styles == null ) { 122 shape_styles = new MorphShapeStyles(); 123 } 124 return shape_styles; 125 } 126 127 132 public ShapeRecords getShapeRecordsStart() { 133 if( records_start == null ) { 134 records_start = new ShapeRecords(); 135 } 136 return records_start; 137 } 138 139 144 public ShapeRecords getShapeRecordsEnd() { 145 if( records_end == null ) { 146 records_end = new ShapeRecords(); 147 } 148 return records_end; 149 } 150 151 157 public int addFillStyle( MorphFillStyle fillStyle ) { 158 return getShapeStyles().addFillStyle( fillStyle ); 159 } 160 161 167 public int addLineStyle( MorphLineStyle lineStyle ) { 168 return getShapeStyles().addLineStyle( lineStyle ); 169 } 170 171 180 public int setFillStyle0( MorphFillStyle fillStyle ) { 181 int fs = getShapeStyles().getFillStyleIndex( fillStyle ); 182 if( fs == -1 ) fs = addFillStyle( fillStyle ); 183 setFillStyle0( fs ); 184 return fs; 185 } 186 187 196 public int setFillStyle1( MorphFillStyle fillStyle ) { 197 int fs = getShapeStyles().getFillStyleIndex( fillStyle ); 198 if( fs == -1 ) fs = addFillStyle( fillStyle ); 199 setFillStyle1( fs ); 200 return fs; 201 } 202 203 212 public int setLineStyle( MorphLineStyle lineStyle ) { 213 int ls = getShapeStyles().getLineStyleIndex( lineStyle ); 214 if( ls == -1 ) ls = addLineStyle( lineStyle ); 215 setLineStyle( ls ); 216 return ls; 217 } 218 219 224 public void setFillStyle0( int fillStyle ) { 225 StyleChangeRecord sc = getStyleChange(); 226 sc.addFlags( StyleChangeRecord.FILLSTYLE0 ); 227 sc.setFillStyle0( fillStyle ); 228 } 229 230 235 public void setFillStyle1( int fillStyle ) { 236 StyleChangeRecord sc = getStyleChange(); 237 sc.addFlags( StyleChangeRecord.FILLSTYLE1 ); 238 sc.setFillStyle1( fillStyle ); 239 } 240 241 246 public void setLineStyle( int lineStyle ) { 247 StyleChangeRecord sc = getStyleChange(); 248 sc.addFlags( StyleChangeRecord.LINESTYLE ); 249 sc.setLineStyle( lineStyle ); 250 } 251 252 257 public int getLineStyleIndex() { 258 StyleChangeRecord sc = getStyleChange(); 259 return sc.getLineStyle(); 260 } 261 262 267 public MorphLineStyle getLineStyle() { 268 int idx = getLineStyleIndex(); 269 return getShapeStyles().getLineStyle(idx); 270 } 271 272 277 public int getFillStyle0Index() { 278 StyleChangeRecord sc = getStyleChange(); 279 return sc.getFillStyle0(); 280 } 281 282 287 public MorphFillStyle getFillStyle0() { 288 int idx = getFillStyle0Index(); 289 return getShapeStyles().getFillStyle(idx); 290 } 291 292 297 public int getFillStyle1Index() { 298 StyleChangeRecord sc = getStyleChange(); 299 return sc.getFillStyle1(); 300 } 301 302 307 public MorphFillStyle getFillStyle1() { 308 int idx = getFillStyle1Index(); 309 return getShapeStyles().getFillStyle(idx); 310 } 311 312 public int getTag() { 313 return Tag.DEFINEMORPHSHAPE; 314 } 315 316 public void collectDeps( DepsCollector dc ) { 317 shape_styles.collectDeps(dc); 318 } 319 320 protected StyleChangeRecord getStyleChange() { 321 return getShapeRecordsStart().getStyleChange(); 322 } 323 324 330 public static MorphShape parse( Parser p ) { 331 332 int tagCode = p.getTagCode(); 333 MorphShape shape = new MorphShape(); 334 shape.setID( p.getUWord() ); 335 shape.bounds_start = p.getRect(); 336 shape.bounds_end = p.getRect(); 337 338 int offset = p.getUDWord(); 339 int pos = p.getPos(); 340 341 shape.shape_styles = MorphShapeStyles.parse(p); 343 344 shape.records_start = ShapeRecords.parse(p); 345 346 p.setPos(pos+offset); 347 348 shape.records_end = ShapeRecords.parse(p); 349 350 return shape; 351 } 352 353 public void write( FlashOutput main ) { 354 FlashOutput fob = new FlashOutput(main,200); 355 356 fob.write(bounds_start); 357 fob.write(bounds_end); 358 359 fob.skip(4); 360 int pos = fob.getPos(); 361 362 shape_styles.write(fob); 363 364 int nFillBits = shape_styles.calcNFillBits(); 365 int nLineBits = shape_styles.calcNLineBits(); 366 fob.writeByte( (nFillBits<<4) | nLineBits ); 367 records_start.write(fob, nFillBits, nLineBits); 368 fob.writeBits(0, 6); 369 fob.flushBits(); 370 371 int offset = fob.getPos()-pos; 372 fob.writeDWordAt(offset, pos-4); 373 374 fob.writeByte(0); records_end.write(fob); 376 377 main.writeTag( getTag(), 2+fob.getSize() ); 378 main.writeDefID( this ); 379 main.writeFOB( fob ); 380 } 381 382 public void printContent( PrintStream out, String indent ) { 383 out.println(indent+"MorphShape("+Tag.tagNames[getTag()]+"): id="+getID()+", name='"+getName()+"'"); 384 out.println(indent+" start bounds="+bounds_start); 385 out.println(indent+" end bounds="+bounds_end); 386 shape_styles.printContent(out, " "); 387 records_start.printContent(out, " "); 388 records_end.printContent(out, " "); 389 } 390 391 public boolean isConstant() { 392 return true; 393 } 394 395 400 public Rectangle2D getBounds() { 401 Rectangle2D dst = GeomHelper.newRectangle(); 402 Rectangle2D.union( bounds_start, bounds_end, dst ); 403 return dst; 404 } 405 406 411 public Rectangle2D getBoundsStart() { 412 return this.bounds_start; 413 } 414 415 420 public Rectangle2D getBoundsEnd() { 421 return this.bounds_end; 422 } 423 424 429 public void setBoundsStart( Rectangle2D bounds ) { 430 this.bounds_start = bounds; 431 } 432 433 438 public void setBoundsEnd( Rectangle2D bounds ) { 439 this.bounds_end = bounds; 440 } 441 442 446 public void setBoundsStart( int x, int y, int width, int height ) { 447 setBoundsStart( GeomHelper.newRectangle(x,y,width,height) ); 448 } 449 450 454 public void setBoundsEnd( int x, int y, int width, int height ) { 455 setBoundsEnd( GeomHelper.newRectangle(x,y,width,height) ); 456 } 457 458 protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) { 459 super.copyInto( item, copier ); 460 ((MorphShape)item).bounds_start = (Rectangle2D) bounds_start.clone(); 461 ((MorphShape)item).bounds_end = (Rectangle2D) bounds_end.clone(); 462 ((MorphShape)item).records_start = (ShapeRecords) records_start.getCopy(copier); 463 ((MorphShape)item).records_end = (ShapeRecords) records_end.getCopy(copier); 464 ((MorphShape)item).shape_styles = (MorphShapeStyles) shape_styles.getCopy(copier); 465 return item; 466 } 467 468 public FlashItem getCopy( ScriptCopier copier ) { 469 return copyInto( new MorphShape(), copier ); 470 } 471 472 473 474 475 476 485 public void drawCurveToStart( int cx, int cy, int ax, int ay ) { 486 getShapeRecordsStart().drawCurveTo(cx, cy, ax, ay); 487 } 488 489 public void drawCurveToEnd( int cx, int cy, int ax, int ay ) { 490 getShapeRecordsEnd().drawCurveTo(cx, cy, ax, ay); 491 } 492 493 504 public void drawCurveStart( int ax1, int ay1, int cx, int cy, int ax2, int ay2 ) { 505 getShapeRecordsStart().drawCurve(ax1, ay1, cx, cy, ax2, ay2); 506 } 507 508 public void drawCurveEnd( int ax1, int ay1, int cx, int cy, int ax2, int ay2 ) { 509 getShapeRecordsEnd().drawCurve(ax1, ay1, cx, cy, ax2, ay2); 510 } 511 512 520 public void drawCurveStart( Point2D anchor1, Point2D control, Point2D anchor2 ) { 521 getShapeRecordsStart().drawCurve(anchor1, control, anchor2); 522 } 523 524 public void drawCurveEnd( Point2D anchor1, Point2D control, Point2D anchor2 ) { 525 getShapeRecordsEnd().drawCurve(anchor1, control, anchor2); 526 } 527 528 535 public void drawLineToStart( int x, int y ) { 536 getShapeRecordsStart().drawLineTo(x, y); 537 } 538 539 public void drawLineToEnd( int x, int y ) { 540 getShapeRecordsEnd().drawLineTo(x, y); 541 } 542 543 549 public void drawLineToStart( Point2D p1 ) { 550 getShapeRecordsStart().drawLineTo(p1); 551 } 552 553 public void drawLineToEnd( Point2D p1 ) { 554 getShapeRecordsEnd().drawLineTo(p1); 555 } 556 557 567 public void drawLineStart( int x1, int y1, int x2, int y2 ) { 568 getShapeRecordsStart().drawLine(x1, y1, x2, y2); 569 } 570 571 public void drawLineEnd( int x1, int y1, int x2, int y2 ) { 572 getShapeRecordsEnd().drawLine(x1, y1, x2, y2); 573 } 574 575 583 public void drawLineStart( Point2D p0, Point2D p1 ) { 584 getShapeRecordsStart().drawLine(p0, p1); 585 } 586 587 public void drawLineEnd( Point2D p0, Point2D p1 ) { 588 getShapeRecordsEnd().drawLine(p0, p1); 589 } 590 591 601 public void drawRectangleStart( int x, int y, int width, int height ) { 602 getShapeRecordsStart().drawRectangle(x, y, width, height); 603 } 604 605 public void drawRectangleEnd( int x, int y, int width, int height ) { 606 getShapeRecordsEnd().drawRectangle(x, y, width, height); 607 } 608 609 616 public void drawRectangleStart( Rectangle2D r ) { 617 getShapeRecordsStart().drawRectangle(r); 618 } 619 620 public void drawRectangleEnd( Rectangle2D r ) { 621 getShapeRecordsEnd().drawRectangle(r); 622 } 623 624 631 public void movePenToStart( int x, int y ) { 632 getShapeRecordsStart().movePenTo(x, y); 633 } 634 635 public void movePenToEnd( int x, int y ) { 636 getShapeRecordsEnd().movePenTo(x, y); 637 } 638 639 645 public void movePenToStart( Point2D p ) { 646 getShapeRecordsStart().movePenTo(p); 647 } 648 649 public void movePenToEnd( Point2D p ) { 650 getShapeRecordsEnd().movePenTo(p); 651 } 652 653 660 public void drawAWTShapeStart( java.awt.Shape shape ) { 661 getShapeRecordsStart().drawAWTShape(shape); 662 } 663 664 public void drawAWTShapeEnd( java.awt.Shape shape ) { 665 getShapeRecordsEnd().drawAWTShape(shape); 666 } 667 668 675 public void drawAWTShapeStart( java.awt.Shape shape, AffineTransform matrix ) { 676 getShapeRecordsStart().drawAWTShape(shape, matrix); 677 } 678 679 public void drawAWTShapeEnd( java.awt.Shape shape, AffineTransform matrix ) { 680 getShapeRecordsEnd().drawAWTShape(shape, matrix); 681 } 682 683 690 public void drawAWTPathIteratorStart( java.awt.geom.PathIterator pi ) { 691 getShapeRecordsStart().drawAWTPathIterator(pi); 692 } 693 694 public void drawAWTPathIteratorEnd( java.awt.geom.PathIterator pi ) { 695 getShapeRecordsEnd().drawAWTPathIterator(pi); 696 } 697 698 } 699 700 | Popular Tags |