1 /* 2 Ming, an SWF output library 3 Copyright (C) 2001 Opaque Industries - http://www.opaque.net/ 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 */ 19 20 #ifndef SWF_MINGPP_H_INCLUDED 21 #define SWF_MINGPP_H_INCLUDED 22 23 /* why would we need to include these ?? 24 #include <stdio.h> 25 */ 26 #include <cstring> /* for strlen used in SWFBitmap costructor */ 27 #include <stdexcept> 28 #include <iostream> 29 #include <string> 30 #include <list> 31 32 #ifdef _MSC_VER 33 #define strcasecmp stricmp 34 #endif 35 36 /* mask the c type names so that we can replace them with classes. 37 weird, but it works. (on gcc, anyway..) */ 38 39 extern "C" 40 { 41 #define SWFShape c_SWFShape 42 #define SWFMovie c_SWFMovie 43 #define SWFDisplayItem c_SWFDisplayItem 44 #define SWFFill c_SWFFill 45 #define SWFFillStyle c_SWFFillStyle 46 #define SWFCharacter c_SWFCharacter 47 #define SWFBlock c_SWFBlock 48 #define SWFSprite c_SWFSprite 49 #define SWFMovieClip c_SWFMovieClip 50 #define SWFBitmap c_SWFBitmap saturate(int32_t amp)51 #define SWFGradient c_SWFGradient 52 #define SWFMorph c_SWFMorph 53 #define SWFText c_SWFText 54 #define SWFFont c_SWFFont 55 #define SWFBrowserFont c_SWFBrowserFont 56 #define SWFFontCollection c_SWFFontCollection 57 #define SWFTextField c_SWFTextField 58 #define SWFAction c_SWFAction 59 #define SWFButton c_SWFButton 60 #define SWFSoundStream c_SWFSoundStream 61 #define SWFInput c_SWFInput 62 #define SWFSound c_SWFSound 63 #define SWFVideoStream c_SWFVideoStream 64 #define SWFFilter c_SWFFilter 65 #define SWFBlur c_SWFBlur 66 #define SWFShadow c_SWFShadow 67 #define SWFFilterMatrix c_SWFFilterMatrix 68 #define SWFInitAction c_SWFInitAction 69 #define SWFButtonRecord c_SWFButtonRecord 70 #define SWFFontCharacter c_SWFFontCharacter 71 #define SWFPrebuiltClip c_SWFPrebuiltClip 72 #define SWFSoundInstance c_SWFSoundInstance 73 #define SWFBinaryData c_SWFBinaryData 74 #define SWFMatrix c_SWFMatrix 75 #define SWFCXform c_SWFCXform 76 77 #include <ming.h> 78 79 /* 80 * declaration from src/blocks/fdbfont.h. 81 * internal function to maintain behavior of older ming-version 82 */ 83 SWFFont loadSWFFont_fromFdbFile(FILE *file); 84 85 #undef SWFShape 86 #undef SWFMovie 87 #undef SWFDisplayItem 88 #undef SWFFill 89 #undef SWFFillStyle 90 #undef SWFCharacter 91 #undef SWFBlock 92 #undef SWFSprite 93 #undef SWFMovieClip 94 #undef SWFBitmap 95 #undef SWFGradient 96 #undef SWFMorph 97 #undef SWFFont 98 #undef SWFBrowserFont 99 #undef SWFFontCollection 100 #undef SWFText 101 #undef SWFTextField 102 #undef SWFAction 103 #undef SWFButton 104 #undef SWFSoundStream 105 #undef SWFInput 106 #undef SWFSound 107 #undef SWFFontCharacter 108 #undef SWFPrebuiltClip 109 #undef SWFVideoStream 110 #undef SWFFilter 111 #undef SWFBlur 112 #undef SWFShadow 113 #undef SWFFilterMatrix 114 #undef SWFInitAction 115 #undef SWFButtonRecord 116 #undef SWFSoundInstance 117 #undef SWFBinaryData 118 #undef SWFMatrix 119 #undef SWFCXform 120 } // extern C 121 122 #define SWF_DECLAREONLY(classname) \ 123 private: \ 124 classname(const classname&); \ 125 const classname& operator=(const classname&) 126 127 128 class SWFException : public std::exception 129 { 130 public: 131 SWFException(const char *m) 132 { 133 this->message = m; 134 } 135 136 virtual ~SWFException() throw () 137 { } 138 139 virtual const char *what() 140 { 141 return this->message.c_str(); 142 } 143 private: 144 std::string message; 145 }; 146 147 /* SWFMatrix */ 148 class SWFMatrix 149 { 150 friend class SWFDisplayItem; 151 public: 152 c_SWFMatrix matrix; 153 154 double getScaleX() 155 { return SWFMatrix_getScaleX(this->matrix); } 156 WebRtc_g722_decode_init(G722DecoderState * s,int rate,int options)157 double getScaleY() 158 { return SWFMatrix_getScaleY(this->matrix); } 159 160 double getRotate0() 161 { return SWFMatrix_getRotate0(this->matrix); } 162 163 double getRotate1() 164 { return SWFMatrix_getRotate1(this->matrix); } 165 166 int getTranslateX() 167 { return SWFMatrix_getTranslateX(this->matrix); } 168 169 int getTranslateY() 170 { return SWFMatrix_getTranslateY(this->matrix); } 171 172 private: 173 SWFMatrix(c_SWFMatrix matrix) 174 { 175 if(matrix == NULL) 176 throw SWFException("SWFMatrix(c_SWFMatrix matrix)"); 177 this->matrix = matrix; 178 } 179 SWF_DECLAREONLY(SWFMatrix); 180 }; 181 182 class SWFCXform 183 { WebRtc_g722_decode_release(G722DecoderState * s)184 public: 185 c_SWFCXform cx; 186 187 SWFCXform(int rAdd, int gAdd, int bAdd, int aAdd, float rMult, float gMult, float bMult, float aMult) 188 { 189 this->cx = newSWFCXform(rAdd, gAdd, bAdd, aAdd, rMult, gMult, bMult, aMult); 190 if(this->cx == NULL) WebRtc_g722_decode(G722DecoderState * s,int16_t amp[],const uint8_t g722_data[],int len)191 throw SWFException("SWFCXform(int rAdd, int gAdd,...)"); 192 } 193 194 void setColorAdd(int rAdd, int gAdd, int bAdd, int aAdd) 195 { SWFCXform_setColorAdd(this->cx, rAdd, gAdd, bAdd, aAdd); } 196 197 void setColorMult(float rMult, float gMult, float bMult, float aMult) 198 { SWFCXform_setColorMult(this->cx, rMult, gMult, bMult, aMult); } 199 200 ~ SWFCXform() 201 { destroySWFCXform(cx); } 202 203 static SWFCXform *AddCXForm(int rAdd, int gAdd, int bAdd, int aAdd) 204 { return new SWFCXform(newSWFAddCXform(rAdd, gAdd, bAdd, aAdd)); } 205 206 static SWFCXform *MultCXForm(float rMult, float gMult, float bMult, float aMult) 207 { return new SWFCXform(newSWFMultCXform(rMult, gMult, bMult, aMult)); } 208 209 210 211 private: 212 SWFCXform(c_SWFCXform cx) 213 { 214 if(cx == NULL) 215 throw SWFException("SWFCXform(c_SWFCXform cx)"); 216 217 this->cx = cx; 218 } 219 SWF_DECLAREONLY(SWFCXform); 220 221 }; 222 223 /* SWFInput */ 224 225 class SWFInput 226 { 227 public: 228 c_SWFInput input; 229 230 SWFInput(FILE *f) 231 { 232 this->input = newSWFInput_file(f); 233 if(this->input == NULL) 234 throw SWFException("SWFInput(FILE *f)\n"); 235 } 236 237 SWFInput(unsigned char *buffer, int length) 238 { 239 this->input = newSWFInput_buffer(buffer, length); 240 if(this->input == NULL) 241 throw SWFException("SWFInput(unsigned char *buffer, int length)\n"); 242 } 243 244 SWFInput(unsigned char *buffer, int length, int alloced) 245 { 246 if(alloced) 247 this->input = newSWFInput_allocedBuffer(buffer, length); 248 else 249 this->input = newSWFInput_buffer(buffer, length); 250 251 if(this->input == NULL) 252 SWFException("SWFInput(unsigned char *buffer, int length, int alloced)\n"); 253 } 254 255 virtual ~SWFInput() { destroySWFInput(this->input); } 256 257 SWF_DECLAREONLY(SWFInput); 258 SWFInput(); 259 }; 260 261 262 /* SWFBlock */ 263 264 class SWFBlock 265 { 266 public: 267 virtual c_SWFBlock getBlock() = 0; 268 virtual ~SWFBlock(void) {}; 269 }; 270 271 /* SWFCharacter */ 272 273 class SWFCharacter : public SWFBlock 274 { 275 friend class SWFMovie; 276 friend class SWFDisplayItem; 277 public: 278 c_SWFCharacter character; 279 280 virtual ~SWFCharacter(void) {}; 281 float getWidth() 282 { return SWFCharacter_getWidth(this->character); } 283 284 float getHeight() 285 { return SWFCharacter_getHeight(this->character); } 286 287 virtual c_SWFBlock getBlock() 288 { return (c_SWFBlock)character; } 289 290 protected: 291 SWFCharacter() 292 { character = NULL; } 293 294 SWFCharacter(c_SWFCharacter c) 295 { character = c; } 296 297 298 SWF_DECLAREONLY(SWFCharacter); 299 }; 300 /* SWFFontCharacter */ 301 class SWFFontCharacter : public SWFCharacter 302 { 303 friend class SWFMovie; 304 public: 305 c_SWFFontCharacter fontcharacter; 306 307 void addChars(const char *str) 308 { SWFFontCharacter_addChars(this->fontcharacter, str); } 309 310 void addUTF8Chars(const char *str) 311 { SWFFontCharacter_addUTF8Chars(this->fontcharacter, str); } 312 313 void addAllChars() 314 { SWFFontCharacter_addAllChars(this->fontcharacter); } 315 316 private: 317 SWFFontCharacter(c_SWFFontCharacter fontcharacter) 318 { 319 this->fontcharacter = fontcharacter; 320 this->character = (c_SWFCharacter)fontcharacter; 321 } 322 323 virtual ~SWFFontCharacter() 324 { } 325 326 SWF_DECLAREONLY(SWFFontCharacter); 327 SWFFontCharacter(); 328 }; 329 330 331 /* SWFPrebuiltClip */ 332 333 class SWFPrebuiltClip : public SWFBlock 334 { 335 public: 336 c_SWFPrebuiltClip prebuiltclip; 337 338 SWFPrebuiltClip(c_SWFPrebuiltClip prebuiltclip) 339 { 340 if(prebuiltclip == NULL) 341 throw SWFException("new SWFPrebuiltClip: prebuiltclip == NULL)"); 342 this->prebuiltclip = prebuiltclip; 343 } 344 345 virtual ~SWFPrebuiltClip() 346 { } 347 348 c_SWFBlock getBlock() 349 { return (c_SWFBlock)this->prebuiltclip; } 350 351 352 SWFPrebuiltClip(const char *name) 353 { 354 if(strlen(name) > 4 && 355 strcmp(name + strlen(name) - 4, ".swf") == 0) 356 this->prebuiltclip = newSWFPrebuiltClip_fromFile(name); 357 else 358 this->prebuiltclip = NULL; 359 360 if(this->prebuiltclip == NULL) 361 throw SWFException("SWFPrebuiltClip(const char *name)"); 362 } 363 SWF_DECLAREONLY(SWFPrebuiltClip); 364 SWFPrebuiltClip(); 365 }; 366 // )))) end minguts 2004/08/31 367 368 369 /* SWFAction */ 370 371 class SWFAction : public SWFBlock 372 { 373 public: 374 c_SWFAction action; 375 376 SWFAction(const char *script) 377 { 378 this->action = newSWFAction(script); 379 if(this->action == NULL) 380 throw SWFException("SWFAction(const char *script)"); 381 } 382 383 // movies, buttons, etc. destroy the c_SWFAction.. 384 virtual ~SWFAction() {} 385 386 c_SWFBlock getBlock() 387 { return (c_SWFBlock)this->action; } 388 389 int compile(int swfVersion, int *length) 390 { return SWFAction_compile(this->action, swfVersion, length); } 391 392 unsigned char *getByteCode(int *len) 393 { return SWFAction_getByteCode(this->action, len); } 394 395 SWF_DECLAREONLY(SWFAction); 396 SWFAction(); 397 }; 398 399 /* SWFInitAction */ 400 401 class SWFInitAction : public SWFBlock 402 { 403 public: 404 c_SWFInitAction init; 405 406 SWFInitAction(SWFAction *action) 407 { 408 this->init = newSWFInitAction(action->action); 409 if(this->init == NULL) 410 throw SWFException("SWFInitAction(SWFAction *action)"); 411 } 412 413 SWFInitAction(SWFAction *action, int id) 414 { 415 this->init = newSWFInitAction_withId(action->action, id); 416 if(this->init == NULL) 417 throw SWFException("SWFInitAction(SWFAction *action, int id)"); 418 } 419 420 virtual ~SWFInitAction() {} 421 422 c_SWFBlock getBlock() 423 { return (c_SWFBlock)this->init; } 424 425 SWF_DECLAREONLY(SWFInitAction); 426 SWFInitAction(); 427 }; 428 429 430 /* SWFGradient */ 431 432 class SWFGradient 433 { 434 public: 435 c_SWFGradient gradient; 436 437 SWFGradient() 438 { 439 this->gradient = newSWFGradient(); 440 if(this->gradient == NULL) 441 throw SWFGradient(); 442 } 443 444 virtual ~SWFGradient() 445 { destroySWFGradient(this->gradient); } 446 447 void addEntry(float ratio, byte r, byte g, byte b, byte a=0xff) 448 { SWFGradient_addEntry(this->gradient, ratio, r, g, b, a); } 449 450 void setSpreadMode(GradientSpreadMode mode) 451 { SWFGradient_setSpreadMode(this->gradient, mode); } 452 453 void setInterpolationMode(GradientInterpolationMode mode) 454 { SWFGradient_setInterpolationMode(this->gradient, mode); } 455 456 void setFocalPoint(float focalPoint) 457 { SWFGradient_setFocalPoint(this->gradient, focalPoint); } 458 459 SWF_DECLAREONLY(SWFGradient); 460 }; 461 462 /* SWFFilter */ 463 class SWFBlur 464 { 465 public: 466 c_SWFBlur blur; 467 468 SWFBlur(float blurX, float blurY, int passes) 469 { 470 this->blur = newSWFBlur(blurX, blurY, passes); 471 if(this->blur == NULL) 472 throw SWFException("SWFBlur(float blurX, float blurY, int passes)"); 473 } 474 475 ~SWFBlur() 476 { destroySWFBlur(blur); } 477 478 SWF_DECLAREONLY(SWFBlur); 479 SWFBlur(); 480 }; 481 482 class SWFShadow 483 { 484 public: 485 c_SWFShadow shadow; 486 487 SWFShadow(float angle, float distance, float strength) 488 { 489 this->shadow = newSWFShadow(angle, distance, strength); 490 if(this->shadow == NULL) 491 throw SWFException("SWFShadow(float angle, float distance, float strength)"); 492 } 493 494 ~SWFShadow() 495 { destroySWFShadow(shadow); } 496 497 SWF_DECLAREONLY(SWFShadow); 498 SWFShadow(); 499 }; 500 501 class SWFFilterMatrix 502 { 503 public: 504 c_SWFFilterMatrix matrix; 505 506 SWFFilterMatrix(int cols, int rows, float *vals) 507 { 508 this->matrix = newSWFFilterMatrix(cols, rows, vals); 509 if(this->matrix == NULL) 510 throw SWFException("SWFFilterMatrix(int cols, int rows, float *vals)"); 511 } 512 513 ~SWFFilterMatrix() 514 { destroySWFFilterMatrix(matrix); } 515 516 SWF_DECLAREONLY(SWFFilterMatrix); 517 SWFFilterMatrix(); 518 }; 519 520 class SWFFilter 521 { 522 public: 523 c_SWFFilter filter; 524 525 virtual ~SWFFilter() {} 526 527 static SWFFilter *BlurFilter(SWFBlur *blur) 528 { return new SWFFilter(newBlurFilter(blur->blur)); } 529 530 static SWFFilter *DropShadowFilter(SWFColor color, SWFBlur *blur, 531 SWFShadow *shadow, int flags) 532 { return new SWFFilter(newDropShadowFilter(color, blur->blur, shadow->shadow, flags)); } 533 534 static SWFFilter *GlowFilter(SWFColor color, SWFBlur *blur, 535 float strength, int flags) 536 { return new SWFFilter(newGlowFilter(color, blur->blur, strength, flags));} 537 538 static SWFFilter *BevelFilter(SWFColor sColor, SWFColor hColor, 539 SWFBlur *blur, SWFShadow *shadow, int flags) 540 { return new SWFFilter(newBevelFilter(sColor, hColor, blur->blur, shadow->shadow, flags)); } 541 542 static SWFFilter *GradientGlowFilter(SWFGradient *gradient, SWFBlur *blur, SWFShadow *shadow, int flags) 543 { return new SWFFilter(newGradientGlowFilter(gradient->gradient, blur->blur, shadow->shadow, flags)); } 544 545 static SWFFilter *GradientBevelFilter(SWFGradient *gradient, SWFBlur *blur, 546 SWFShadow *shadow, int flags) 547 { return new SWFFilter(newGradientBevelFilter(gradient->gradient, blur->blur, shadow->shadow, flags)); } 548 549 static SWFFilter *ConvolutionFilter(SWFFilterMatrix *matrix, float divisor, 550 float bias, SWFColor color, int flags) 551 { return new SWFFilter(newConvolutionFilter(matrix->matrix, divisor, bias, color, flags)); } 552 553 static SWFFilter *ColorMatrixFilter(SWFFilterMatrix *matrix) 554 { return new SWFFilter(newColorMatrixFilter(matrix->matrix)); } 555 556 private: 557 SWFFilter(c_SWFFilter filter) 558 { 559 this->filter = filter; 560 if(this->filter == NULL) 561 throw SWFException("SWFFilter(c_SWFFilter filter)"); 562 } 563 SWF_DECLAREONLY(SWFFilter); 564 SWFFilter(); 565 }; 566 567 568 569 /* SWFDisplayItem */ 570 571 class SWFDisplayItem 572 { 573 friend class SWFMovie; 574 friend class SWFMovieClip; 575 friend class SWFSprite; 576 public: 577 c_SWFDisplayItem item; 578 579 void rotate(double degrees) 580 { SWFDisplayItem_rotate(this->item, degrees); } 581 582 void rotateTo(double degrees) 583 { SWFDisplayItem_rotateTo(this->item, degrees); } 584 585 void getRotation(double *degrees) 586 { SWFDisplayItem_getRotation(this->item, degrees); } 587 588 void move(double x, double y) 589 { SWFDisplayItem_move(this->item, x, y); } 590 591 void moveTo(double x, double y) 592 { SWFDisplayItem_moveTo(this->item, x, y); } 593 594 void getPosition(double *x, double *y) 595 { SWFDisplayItem_getPosition(this->item, x, y); } 596 597 void scale(double xScale, double yScale) 598 { SWFDisplayItem_scale(this->item, xScale, yScale); } 599 600 void scale(double scale) 601 { SWFDisplayItem_scale(this->item, scale, scale); } 602 603 void scaleTo(double xScale, double yScale) 604 { SWFDisplayItem_scaleTo(this->item, xScale, yScale); } 605 606 void scaleTo(double scale) 607 { SWFDisplayItem_scaleTo(this->item, scale, scale); } 608 609 void getScale(double *xScale, double *yScale) 610 { SWFDisplayItem_getScale(this->item, xScale, yScale); } 611 612 void skewX(double skew) 613 { SWFDisplayItem_skewX(this->item, skew); } 614 615 void skewXTo(double skew) 616 { SWFDisplayItem_skewXTo(this->item, skew); } 617 618 void skewY(double skew) 619 { SWFDisplayItem_skewY(this->item, skew); } 620 621 void skewYTo(double skew) 622 { SWFDisplayItem_skewYTo(this->item, skew); } 623 624 void getSkew(double *xSkew, double *ySkew) 625 { SWFDisplayItem_getSkew(this->item, xSkew, ySkew); } 626 627 int getDepth() 628 { return SWFDisplayItem_getDepth(this->item); } 629 630 void setDepth(int depth) 631 { SWFDisplayItem_setDepth(this->item, depth); } 632 633 void remove() 634 { SWFDisplayItem_remove(this->item); } 635 636 void setName(const char *name) 637 { SWFDisplayItem_setName(this->item, name); } 638 639 void setRatio(float ratio) 640 { SWFDisplayItem_setRatio(this->item, ratio); } 641 642 void addColor(int r, int g, int b, int a=0) 643 { SWFDisplayItem_setColorAdd(this->item, r, g, b, a); } 644 645 void multColor(float r, float g, float b, float a=1.0) 646 { SWFDisplayItem_setColorMult(this->item, r, g, b, a); } 647 648 void addAction(SWFAction *action, int flags) 649 { SWFDisplayItem_addAction(this->item, action->action, flags); } 650 651 void addFilter(SWFFilter *filter) 652 { SWFDisplayItem_addFilter(this->item, filter->filter); } 653 654 void cacheAsBitmap(int flag) 655 { SWFDisplayItem_cacheAsBitmap(this->item, flag); } 656 657 void setBlendMode(int mode) 658 { SWFDisplayItem_setBlendMode(this->item, mode); } 659 660 void setMatrix(double a, double b, double c, double d, double x, double y) 661 { SWFDisplayItem_setMatrix(this->item, a, b, c, d, x, y); } 662 663 SWFMatrix getMatrix() 664 { return SWFMatrix(SWFDisplayItem_getMatrix(this->item)); } 665 666 void setMaskLevel(int level) 667 { SWFDisplayItem_setMaskLevel(this->item, level); } 668 669 void endMask() 670 { SWFDisplayItem_endMask(this->item); } 671 672 void flush() 673 { SWFDisplayItem_flush(this->item); } 674 675 SWFCharacter *getCharacter() 676 { return new SWFCharacter(SWFDisplayItem_getCharacter(this->item)); } 677 678 void setCXform(SWFCXform *cx) 679 { SWFDisplayItem_setCXform(this->item, cx->cx); } 680 681 private: 682 SWFDisplayItem(c_SWFDisplayItem item) 683 { 684 this->item = item; 685 if(this->item == NULL) 686 throw SWFException("SWFDisplayItem()"); 687 } 688 ~SWFDisplayItem() { } 689 690 SWF_DECLAREONLY(SWFDisplayItem); 691 SWFDisplayItem(); 692 }; 693 694 695 /* SWFSoundStream */ 696 697 class SWFSoundStream 698 { 699 public: 700 c_SWFSoundStream sound; 701 702 SWFSoundStream(FILE *file) 703 { 704 this->sound = newSWFSoundStream(file); 705 if(this->sound == NULL) 706 throw SWFException("SWFSoundStream(FILE *file)"); 707 } 708 709 SWFSoundStream(SWFInput *input) 710 { 711 this->sound = newSWFSoundStream_fromInput(input->input); 712 if(this->sound == NULL) 713 throw SWFException("SWFSoundStream(SWFInput *input)"); 714 } 715 716 SWFSoundStream(char *filename) 717 { 718 this->sound = newSWFSoundStream(fopen(filename, "rb")); 719 if(this->sound == NULL) 720 throw SWFException("SWFSoundStream(char *filename)"); 721 } 722 723 unsigned int getDuration() 724 { 725 return SWFSoundStream_getDuration(this->sound); 726 } 727 728 void setInitialMp3Delay(int delaySeek) 729 { 730 SWFSoundStream_setInitialMp3Delay(this->sound, delaySeek); 731 } 732 733 virtual ~SWFSoundStream() 734 { destroySWFSoundStream(this->sound); } 735 SWF_DECLAREONLY(SWFSoundStream); 736 SWFSoundStream(); 737 }; 738 739 740 741 742 class SWFSound : public SWFBlock 743 { 744 public: 745 c_SWFSound sound; 746 747 SWFSound(FILE *file, int flags) 748 { 749 filep = NULL; 750 this->sound = newSWFSound(file, flags); 751 if(this->sound == NULL) 752 throw SWFException("SWFSound(FILE *file, int flags)"); 753 } 754 755 SWFSound(SWFInput *input, int flags) 756 { 757 this->sound = newSWFSound_fromInput(input->input, flags); 758 filep = NULL; 759 if(this->sound == NULL) 760 throw SWFException("SWFSound(SWFInput *input, int flags)"); 761 } 762 763 SWFSound(char *filename, int flags) 764 { 765 filep = fopen(filename, "rb"); 766 this->sound = newSWFSound(filep, flags); 767 if(this->sound == NULL) 768 { 769 fclose(filep); 770 throw SWFException("SWFSound(char *filename, int flags)"); 771 } 772 } 773 774 SWFSound(SWFSoundStream *stream) 775 { 776 this->sound = newSWFSound_fromSoundStream(stream->sound); 777 filep = NULL; 778 if(this->sound == NULL) 779 throw SWFException("SWFSound(SWFSoundStream *stream)"); 780 } 781 782 void delaySeek(int delaySeek) 783 { 784 SWFSound_setInitialMp3Delay(this->sound, delaySeek); 785 } 786 787 virtual ~SWFSound() 788 { 789 if(filep) 790 fclose(filep); 791 destroySWFSound(this->sound); 792 } 793 794 c_SWFBlock getBlock() 795 { return (c_SWFBlock)this->sound; } 796 797 private: 798 FILE *filep; 799 800 SWF_DECLAREONLY(SWFSound); 801 SWFSound(); 802 }; 803 804 /* SWFFont */ 805 806 class SWFFont : public SWFBlock 807 { 808 friend class SWFFontCollection; 809 public: 810 c_SWFFont font; 811 812 SWFFont(FILE *file) // deprecated 813 { 814 std::cerr << "SWFFont(FILE *file) is deprecated and will be removed in future releases." << std::endl; 815 this->font = loadSWFFont_fromFdbFile(file); 816 if(this->font == NULL) 817 throw SWFException("SWFFont(FILE *file)"); 818 } 819 820 SWFFont(char *path) 821 { 822 this->font = newSWFFont_fromFile(path); 823 if(this->font == NULL) 824 throw SWFException("SWFFont(char *path)"); 825 } 826 827 virtual ~SWFFont() 828 { destroySWFFont(/*(c_SWFBlock)*/this->font); } 829 830 c_SWFBlock getBlock() 831 { return (c_SWFBlock)this->font; } 832 833 float getStringWidth(const char *string) 834 { return SWFFont_getStringWidth(this->font, string); } 835 836 float getWidth(const char *string) 837 { return SWFFont_getStringWidth(this->font, string); } 838 839 float getUTF8StringWidth(const char *string) 840 { return SWFFont_getUTF8StringWidth(this->font, string); } 841 842 float getAscent() 843 { return SWFFont_getAscent(this->font); } 844 845 float getDescent() 846 { return SWFFont_getDescent(this->font); } 847 848 float getLeading() 849 { return SWFFont_getLeading(this->font); } 850 851 const char *getName() 852 { return SWFFont_getName(this->font); } 853 854 int getGlyphCount() 855 { return SWFFont_getGlyphCount(this->font); } 856 857 char *getShape(unsigned short c) 858 { return SWFFont_getShape(this->font, c); } 859 860 SWF_DECLAREONLY(SWFFont); 861 862 private: 863 SWFFont(c_SWFFont font) 864 { 865 this->font = font; 866 if(this->font == NULL) 867 throw SWFException("SWFFont(c_SWFFont)"); 868 } 869 }; 870 871 /* SWFBrowserFont */ 872 class SWFBrowserFont : public SWFBlock 873 { 874 public: 875 c_SWFBrowserFont bfont; 876 877 SWFBrowserFont(char *name) 878 { 879 this->bfont = newSWFBrowserFont(name); 880 if(this->bfont == NULL) 881 throw SWFException("SWFBrowserFont(char *name)"); 882 } 883 884 c_SWFBlock getBlock() 885 { return (c_SWFBlock)this->bfont; } 886 887 virtual ~SWFBrowserFont() 888 { destroySWFBrowserFont(this->bfont); } 889 890 SWF_DECLAREONLY(SWFBrowserFont); 891 }; 892 893 class SWFFontCollection 894 { 895 public: 896 c_SWFFontCollection fc; 897 898 SWFFontCollection(const char *filename) 899 { 900 this->fc = newSWFFontCollection_fromFile(filename); 901 if(this->fc == NULL) 902 throw SWFException("SWFFontCollection(filename)"); 903 } 904 905 ~ SWFFontCollection() 906 { destroySWFFontCollection(this->fc); } 907 908 SWFFont *getFont(int index) 909 { return new SWFFont(SWFFontCollection_getFont(this->fc, index)); } 910 911 int getFontCount() 912 { return SWFFontCollection_getFontCount(this->fc); } 913 914 SWF_DECLAREONLY(SWFFontCollection); 915 }; 916 917 class SWFSoundInstance 918 { 919 friend class SWFMovie; 920 friend class SWFMovieClip; 921 922 public: 923 c_SWFSoundInstance instance; 924 925 void setNoMultiple() 926 { SWFSoundInstance_setNoMultiple(this->instance); } 927 928 void setLoopInPoint(unsigned int point) 929 { SWFSoundInstance_setLoopInPoint(this->instance, point); } 930 931 void setLoopOutPoint(unsigned int point) 932 { SWFSoundInstance_setLoopOutPoint(this->instance, point); } 933 934 void setLoopCount(int count) 935 { SWFSoundInstance_setLoopCount(this->instance, count); } 936 937 void addEnvelope(unsigned int mark44, short left, short right) 938 { SWFSoundInstance_addEnvelope(this->instance, mark44, left, right); } 939 940 private: 941 SWFSoundInstance(c_SWFSoundInstance inst) 942 { 943 if(inst == NULL) 944 throw SWFException("SWFSoundInstance(c_SWFSoundInstance inst)"); 945 946 this->instance = inst; 947 } 948 SWF_DECLAREONLY(SWFSoundInstance); 949 }; 950 951 /* SWFMovie */ 952 class SWFMovie 953 { 954 public: 955 c_SWFMovie movie; 956 957 SWFMovie() 958 { 959 this->movie = newSWFMovie(); 960 if(this->movie == NULL) 961 throw SWFException("SWFMovie()"); 962 } 963 964 SWFMovie(int version) 965 { 966 this->movie = newSWFMovieWithVersion(version); 967 if(this->movie == NULL) 968 throw SWFException("SWFMovie(int version)"); 969 } 970 971 virtual ~SWFMovie() 972 { destroySWFMovie(this->movie); } 973 974 void setRate(float rate) 975 { SWFMovie_setRate(this->movie, rate); } 976 977 float getRate() 978 { return SWFMovie_getRate(this->movie); } 979 980 void setDimension(float x, float y) 981 { SWFMovie_setDimension(this->movie, x, y); } 982 983 void setNumberOfFrames(int nFrames) 984 { SWFMovie_setNumberOfFrames(this->movie, nFrames); } 985 986 /* aka */ 987 void setFrames(int nFrames) 988 { SWFMovie_setNumberOfFrames(this->movie, nFrames); } 989 990 void setBackground(byte r, byte g, byte b) 991 { SWFMovie_setBackground(this->movie, r, g, b); } 992 993 void setSoundStream(SWFSoundStream *sound, float skip=0.0) 994 { 995 if(skip > 0) 996 SWFMovie_setSoundStreamAt(this->movie, sound->sound, skip); 997 else 998 SWFMovie_setSoundStream(this->movie, sound->sound); 999 } 1000 1001 SWFDisplayItem *add(SWFBlock *character) 1002 { 1003 SWFMovieBlockType ublock; 1004 ublock.block = character->getBlock(); 1005 c_SWFDisplayItem item = SWFMovie_add_internal(this->movie, ublock); 1006 if(item == NULL) 1007 return NULL; 1008 SWFDisplayItem *_item_ = new SWFDisplayItem(item); 1009 itemList.push_back(_item_); 1010 return _item_; 1011 } 1012 1013 void addExport(SWFBlock *exp, char *name) 1014 { SWFMovie_addExport(this->movie, exp->getBlock(), name); } 1015 1016 void remove(SWFDisplayItem *item) 1017 { SWFMovie_remove(this->movie, item->item); } 1018 1019 bool replace(SWFDisplayItem *item, SWFBlock *character) 1020 { 1021 SWFMovieBlockType ublock; 1022 ublock.block = character->getBlock(); 1023 return SWFMovie_replace_internal(this->movie, item->item, ublock); 1024 } 1025 1026 void nextFrame() 1027 { SWFMovie_nextFrame(this->movie); } 1028 1029 void labelFrame(const char *label) 1030 { SWFMovie_labelFrame(this->movie, label); } 1031 1032 void namedAnchor(const char *label) 1033 { SWFMovie_namedAnchor(this->movie, label); } 1034 1035 int output(int level=-1) 1036 { 1037 int oldlevel = Ming_setSWFCompression(level); 1038 int ret = SWFMovie_output_to_stream(this->movie, stdout); 1039 cleanUp(); 1040 Ming_setSWFCompression(oldlevel); 1041 return ret; 1042 } 1043 1044 int save(const char *filename, int level=-1) 1045 { 1046 int oldlevel = Ming_setSWFCompression(level); 1047 int result = SWFMovie_save(this->movie,filename); 1048 Ming_setSWFCompression(oldlevel); 1049 cleanUp(); 1050 return result; 1051 } 1052 1053 SWFSoundInstance *startSound(SWFSound *sound) 1054 { return new SWFSoundInstance(SWFMovie_startSound(this->movie, sound->sound)); } 1055 void stopSound(SWFSound *sound) 1056 { SWFMovie_stopSound(this->movie, sound->sound); } 1057 1058 SWFCharacter *importCharacter(const char *filename, const char *name) 1059 { return new SWFCharacter(SWFMovie_importCharacter(this->movie, filename, name)); } 1060 1061 SWFFontCharacter *importFont(const char *filename, const char *name) 1062 { return new SWFFontCharacter(SWFMovie_importFont(this->movie, filename, name)); } 1063 1064 SWFFontCharacter *addFont(SWFFont *font) 1065 { return new SWFFontCharacter(SWFMovie_addFont(this->movie, font->font)); } 1066 1067 void protect() 1068 { SWFMovie_protect(this->movie, NULL);} 1069 1070 void protect(char *password) 1071 { SWFMovie_protect(this->movie,password); } 1072 1073 void addMetadata(char *xml) 1074 { SWFMovie_addMetadata(this->movie, xml); } 1075 1076 void setNetworkAccess(int flag) 1077 { SWFMovie_setNetworkAccess(this->movie, flag); } 1078 1079 void setScriptLimits(int maxRecursion, int timeout) 1080 { SWFMovie_setScriptLimits(this->movie, maxRecursion, timeout); } 1081 1082 void setTabIndex(int depth, int index) 1083 { SWFMovie_setTabIndex(this->movie, depth, index); } 1084 1085 void assignSymbol(SWFCharacter *character, char *name) 1086 { SWFMovie_assignSymbol(this->movie, (c_SWFCharacter)character->getBlock(), name); } 1087 1088 void defineScene(unsigned int offset, const char *name) 1089 { SWFMovie_defineScene(this->movie, offset, name); } 1090 1091 void writeExports() 1092 { SWFMovie_writeExports(this->movie); } 1093 1094 SWF_DECLAREONLY(SWFMovie); 1095 private: 1096 1097 void cleanUp() 1098 { 1099 std::list<SWFDisplayItem *>::iterator iter = itemList.begin(); 1100 for(; iter != itemList.end(); iter++) 1101 delete (*iter); 1102 } 1103 std::list<SWFDisplayItem *> itemList; 1104 }; 1105 1106 1107 1108 1109 1110 /* SWFBitmap */ 1111 1112 class SWFBitmap : public SWFCharacter 1113 { 1114 public: 1115 c_SWFBitmap bitmap; 1116 1117 c_SWFBlock getBlock() 1118 { return (c_SWFBlock)this->bitmap; } 1119 1120 SWFBitmap(const char *filename, const char *alpha=NULL) 1121 { 1122 if(strlen(filename) > 4) 1123 { 1124 if(strcasecmp(filename+strlen(filename)-4, ".dbl") == 0) 1125 this->bitmap = (c_SWFBitmap) newSWFDBLBitmap(fopen(filename, "rb")); 1126 1127 else if(strcasecmp(filename+strlen(filename)-4, ".gif") == 0) 1128 this->bitmap = (c_SWFBitmap) newSWFDBLBitmapData_fromGifFile(filename); 1129 1130 else if(strcasecmp(filename+strlen(filename)-4, ".png") == 0) 1131 this->bitmap = (c_SWFBitmap) newSWFDBLBitmapData_fromPngFile( filename ); 1132 1133 else if(strcasecmp(filename+strlen(filename)-4, ".jpg") == 0 || 1134 (strlen(filename) > 5 && (strcasecmp(filename+strlen(filename)-5, ".jpeg") == 0))) 1135 { 1136 if(alpha != NULL) 1137 this->bitmap = (c_SWFBitmap) newSWFJpegWithAlpha(fopen(filename, "rb"), 1138 fopen(alpha, "rb")); 1139 else 1140 this->bitmap = (c_SWFBitmap) newSWFJpegBitmap(fopen(filename, "rb")); 1141 } 1142 1143 else 1144 bitmap = NULL; 1145 } 1146 if ( ! this->bitmap ) 1147 throw SWFException("SWFBitmap(const char *filename, const char *alpha=NULL)"); 1148 1149 this->character = (c_SWFCharacter)bitmap; 1150 } 1151 1152 SWFBitmap(unsigned char *raw, SWFRawImgFmt srcFmt, SWFBitmapFmt dstFmt, 1153 unsigned short width, unsigned short height) 1154 { 1155 this->bitmap = newSWFBitmap_fromRawImg(raw, srcFmt, dstFmt, width, height); 1156 if ( ! this->bitmap ) 1157 throw SWFException("SWFBitmap(const char *filename, const char *alpha=NULL)"); 1158 this->character = (c_SWFCharacter)bitmap; 1159 } 1160 1161 SWFBitmap(SWFInput *input) 1162 { 1163 this->bitmap = newSWFBitmap_fromInput(input->input); 1164 if(this->bitmap == NULL) 1165 throw SWFException("SWFBitmap(SWFInput *input)"); 1166 this->character = (c_SWFCharacter)bitmap; 1167 } 1168 1169 virtual ~SWFBitmap() 1170 { destroySWFBitmap(this->bitmap); } 1171 1172 int getWidth() 1173 { return SWFBitmap_getWidth(this->bitmap); } 1174 1175 int getHeight() 1176 { return SWFBitmap_getHeight(this->bitmap); } 1177 1178 SWF_DECLAREONLY(SWFBitmap); 1179 SWFBitmap(); 1180 }; 1181 1182 class SWFFillStyle 1183 { 1184 friend class SWFFill; 1185 public: 1186 c_SWFFillStyle fill; 1187 1188 virtual ~SWFFillStyle() { } 1189 1190 static SWFFillStyle *SolidFillStyle(byte r, byte g, byte b, byte a=255) 1191 { return new SWFFillStyle(newSWFSolidFillStyle(r, g, b, a)); } 1192 1193 static SWFFillStyle *GradientFillStyle(SWFGradient *gradient, byte flags) 1194 { return new SWFFillStyle(newSWFGradientFillStyle(gradient->gradient, flags)); } 1195 1196 static SWFFillStyle *BitmapFillStyle(SWFBitmap *bitmap, byte flags) 1197 { return new SWFFillStyle(newSWFBitmapFillStyle(bitmap ? bitmap->bitmap : 0, flags)); } 1198 1199 private: 1200 SWFFillStyle(c_SWFFillStyle fill) 1201 { 1202 this->fill = fill; 1203 if(this->fill == NULL) 1204 throw SWFException("SWFFillStyle"); 1205 } 1206 SWF_DECLAREONLY(SWFFillStyle); 1207 SWFFillStyle(); 1208 }; 1209 1210 /* SWFFill */ 1211 class SWFFill 1212 { 1213 friend class SWFShape; 1214 public: 1215 c_SWFFill fill; 1216 1217 SWFFill(SWFFillStyle *fs) 1218 { 1219 this->fill = newSWFFill(fs->fill); 1220 if(this->fill == NULL) 1221 throw SWFException("SWFFill"); 1222 } 1223 1224 // shape destroys c_SWFFill object 1225 virtual ~SWFFill() 1226 { destroySWFFill(this->fill); } 1227 1228 void skewX(float x) 1229 { SWFFill_skewX(this->fill, x); } 1230 1231 void skewXTo(float x) 1232 { SWFFill_skewXTo(this->fill, x); } 1233 1234 void skewY(float y) 1235 { SWFFill_skewY(this->fill, y); } 1236 1237 void skewYTo(float y) 1238 { SWFFill_skewYTo(this->fill, y); } 1239 1240 void scaleX(float x) 1241 { SWFFill_scaleX(this->fill, x); } 1242 1243 void scaleXTo(float x) 1244 { SWFFill_scaleXTo(this->fill, x); } 1245 1246 void scaleY(float y) 1247 { SWFFill_scaleY(this->fill, y); } 1248 1249 void scaleYTo(float y) 1250 { SWFFill_scaleYTo(this->fill, y); } 1251 1252 void scale(float x, float y) 1253 { SWFFill_scaleXY(this->fill, x, y); } 1254 1255 void scale(float scale) 1256 { SWFFill_scaleXY(this->fill, scale, scale); } 1257 1258 void scaleTo(float x, float y) 1259 { SWFFill_scaleXYTo(this->fill, x, y); } 1260 1261 void scaleTo(float scale) 1262 { SWFFill_scaleXYTo(this->fill, scale, scale); } 1263 1264 void rotate(float degrees) 1265 { SWFFill_rotate(this->fill, degrees); } 1266 1267 void rotateTo(float degrees) 1268 { SWFFill_rotateTo(this->fill, degrees); } 1269 1270 void move(float x, float y) 1271 { SWFFill_move(this->fill, x, y); } 1272 1273 void moveTo(float x, float y) 1274 { SWFFill_move(this->fill, x, y); } 1275 1276 void setMatrix( float a, float b, float c, float d, float x, float y) 1277 { SWFFill_setMatrix(this->fill, a, b, c, d, x, y); } 1278 1279 SWFFillStyle *getFillStyle() 1280 { return new SWFFillStyle(SWFFill_getFillStyle(this->fill)); } 1281 1282 SWF_DECLAREONLY(SWFFill); 1283 SWFFill(); 1284 1285 private: 1286 SWFFill(c_SWFFill fill) 1287 { 1288 this->fill = fill; 1289 if(this->fill == NULL) 1290 throw SWFException("SWFFill"); 1291 } 1292 }; 1293 1294 1295 /* SWFShape */ 1296 class SWFShape : public SWFCharacter 1297 { 1298 public: 1299 c_SWFShape shape; 1300 1301 SWFShape() 1302 { 1303 this->shape = newSWFShape(); 1304 if(this->shape == NULL) 1305 throw SWFException("SWFShape()"); 1306 1307 this->character = (c_SWFCharacter)shape; 1308 } 1309 1310 SWFShape(c_SWFShape shape) 1311 { 1312 this->shape = shape; 1313 if(this->shape == NULL) 1314 throw SWFException("SWFShape(c_SWFShape shape)"); 1315 } 1316 1317 virtual ~SWFShape() 1318 { destroySWFShape(this->shape); } 1319 1320 c_SWFBlock getBlock() 1321 { return (c_SWFBlock)this->shape; } 1322 1323 void movePen(double x, double y) 1324 { SWFShape_movePen(this->shape, x, y); } 1325 1326 void movePenTo(double x, double y) 1327 { SWFShape_movePenTo(this->shape, x, y); } 1328 1329 void drawLine(double x, double y) 1330 { SWFShape_drawLine(this->shape, x, y); } 1331 1332 void drawLineTo(double x, double y) 1333 { SWFShape_drawLineTo(this->shape, x, y); } 1334 1335 void drawCurve(double cx, double cy, double ax, double ay) 1336 { SWFShape_drawCurve(this->shape, cx, cy, ax, ay); } 1337 1338 void drawCurveTo(double cx, double cy, double ax, double ay) 1339 { SWFShape_drawCurveTo(this->shape, cx, cy, ax, ay); } 1340 1341 void drawCubic(double ax, double ay, double bx, double by, double cx, double cy) 1342 { SWFShape_drawCubic(this->shape, ax, ay, bx, by, cx, cy); } 1343 1344 void drawCubicTo(double ax, double ay, double bx, double by, double cx, double cy) 1345 { SWFShape_drawCubicTo(this->shape, ax, ay, bx, by, cx, cy); } 1346 1347 void getPen(double *x, double *y) 1348 { SWFShape_getPen(this->shape, x, y); } 1349 1350 void end() 1351 { SWFShape_end(this->shape); } 1352 1353 SWFFill *addSolidFill(byte r, byte g, byte b, byte a=0xff) 1354 { return new SWFFill(SWFShape_addSolidFill(this->shape, r, g, b, a)); } 1355 1356 SWFFill *addGradientFill(SWFGradient *gradient, byte flags=0x10) 1357 { return new SWFFill(SWFShape_addGradientFill(this->shape, gradient->gradient, flags)); } 1358 1359 SWFFill *addBitmapFill(SWFBitmap *bitmap, byte flags=0x40) 1360 { return new SWFFill(SWFShape_addBitmapFill(this->shape, bitmap ? bitmap->bitmap : 0, flags)); } 1361 1362 void setLeftFillStyle(SWFFillStyle *fill) 1363 { SWFShape_setLeftFillStyle(this->shape, fill->fill); } 1364 1365 void setRightFillStyle(SWFFillStyle *fill) 1366 { SWFShape_setRightFillStyle(this->shape, fill->fill); } 1367 1368 void setLeftFill(SWFFill *fill) 1369 { SWFShape_setLeftFill(this->shape, fill->fill); } 1370 1371 void setRightFill(SWFFill *fill) 1372 { SWFShape_setRightFill(this->shape, fill->fill); } 1373 1374 void setLine(unsigned short width, byte r, byte g, byte b, byte a=0xff) 1375 { SWFShape_setLine(this->shape, width, r, g, b, a); } 1376 1377 void drawCharacterBounds(SWFCharacter *character) 1378 { SWFShape_drawCharacterBounds(this->shape, character->character); } 1379 1380 void setLineStyle(unsigned short width, byte r, byte g, byte b, byte a=0xff) // alias for setline 1381 { setLine(width, r, g, b, a); } 1382 1383 void setLine2Filled(unsigned short width, SWFFillStyle *fill, int flags, float miterLimit) 1384 { SWFShape_setLine2Filled(this->shape, width, fill->fill, flags, miterLimit); } 1385 1386 void setLine2(unsigned short width, byte r, byte g, byte b, byte a, int flags, float miterLimit) 1387 { SWFShape_setLine2(this->shape, width, r, g, b, a, flags, miterLimit); } 1388 1389 void drawArc(double r, double startAngle, double endAngle) 1390 { SWFShape_drawArc(this->shape, r, startAngle, endAngle); } 1391 1392 void drawCircle(double r) 1393 { SWFShape_drawCircle(this->shape, r); } 1394 1395 void drawGlyph(SWFFont *font, unsigned short c, int size=0) 1396 { SWFShape_drawSizedGlyph(this->shape, font->font, c, size); } 1397 1398 void useVersion(int version) 1399 { SWFShape_useVersion(this->shape, version); } 1400 1401 int getVersion() 1402 { return SWFShape_getVersion(this->shape); } 1403 1404 void setRenderingHintingFlags(int flags) 1405 { SWFShape_setRenderHintingFlags(this->shape, flags); } 1406 1407 void hideLine() 1408 { SWFShape_hideLine(this->shape); } 1409 1410 void drawFontGlyph(SWFFont *font, unsigned short c) 1411 { SWFShape_drawGlyph(this->shape, font->font, c); } 1412 1413 char *dumpOutline() 1414 { return SWFShape_dumpOutline(this->shape); } 1415 1416 SWF_DECLAREONLY(SWFShape); 1417 }; 1418 1419 1420 /* SWFMovieClip */ 1421 class SWFMovieClip : public SWFCharacter 1422 { 1423 public: 1424 c_SWFMovieClip clip; 1425 1426 SWFMovieClip() 1427 { 1428 this->clip = newSWFMovieClip(); 1429 if(this->clip == NULL) 1430 throw SWFException("SWFMovieClip()"); 1431 1432 this->character = (c_SWFCharacter)clip; 1433 } 1434 1435 virtual ~SWFMovieClip() 1436 { destroySWFMovieClip(this->clip); } 1437 1438 c_SWFBlock getBlock() 1439 { return (c_SWFBlock)this->clip; } 1440 1441 void setNumberOfFrames(int nFrames) 1442 { SWFMovieClip_setNumberOfFrames(this->clip, nFrames); } 1443 1444 SWFDisplayItem *add(SWFBlock *character) 1445 { 1446 c_SWFDisplayItem item = SWFMovieClip_add(this->clip, character->getBlock()); 1447 if(item == NULL) 1448 return NULL; 1449 else 1450 return new SWFDisplayItem(item); 1451 } 1452 1453 void remove(SWFDisplayItem *item) 1454 { SWFMovieClip_remove(this->clip, item->item); } 1455 1456 void nextFrame() 1457 { SWFMovieClip_nextFrame(this->clip); } 1458 1459 void labelFrame(char *label) 1460 { SWFMovieClip_labelFrame(this->clip, label); } 1461 1462 void addInitAction(SWFAction* a) 1463 { SWFMovieClip_addInitAction(this->clip, a->action); } 1464 1465 void setScalingGrid(int x, int y, int w, int h) 1466 { SWFMovieClip_setScalingGrid(this->clip, x, y, w, h); } 1467 1468 void removeScalingGrid() 1469 { SWFMovieClip_removeScalingGrid(this->clip); } 1470 1471 SWFSoundInstance *startSound(SWFSound *sound) 1472 { return new SWFSoundInstance(SWFMovieClip_startSound(this->clip, sound->sound)); } 1473 1474 void stopSound(SWFSound *sound) 1475 { SWFMovieClip_stopSound(this->clip, sound->sound); } 1476 1477 void setSoundStream(SWFSoundStream *sound, float rate, float skip=0.0) 1478 { SWFMovieClip_setSoundStreamAt(this->clip, sound->sound, rate, skip); } 1479 1480 SWF_DECLAREONLY(SWFMovieClip); 1481 }; 1482 1483 /* SWFSprite */ 1484 /* deprecated ! */ 1485 class SWFSprite : public SWFMovieClip 1486 { 1487 SWF_DECLAREONLY(SWFSprite); 1488 }; 1489 1490 1491 /* SWFMorph */ 1492 1493 class SWFMorph : public SWFCharacter 1494 { 1495 public: 1496 c_SWFMorph morph; 1497 1498 SWFMorph() 1499 { 1500 this->morph = newSWFMorphShape(); 1501 if(this->morph == NULL) 1502 throw SWFException("SWFMorph()"); 1503 1504 this->character = (c_SWFCharacter)morph; 1505 } 1506 1507 virtual ~SWFMorph() 1508 { destroySWFMorph(this->morph); } 1509 1510 c_SWFBlock getBlock() 1511 { return (c_SWFBlock)this->morph; } 1512 1513 SWFShape *getShape1() 1514 { return new SWFShape(SWFMorph_getShape1(this->morph)); } 1515 1516 SWFShape *getShape2() 1517 { return new SWFShape(SWFMorph_getShape2(this->morph)); } 1518 SWF_DECLAREONLY(SWFMorph); 1519 }; 1520 1521 1522 /* SWFText */ 1523 1524 class SWFText : public SWFCharacter 1525 { 1526 public: 1527 c_SWFText text; 1528 1529 SWFText(int version = 1) 1530 { 1531 if(version == 2) 1532 this->text = newSWFText2(); 1533 else 1534 this->text = newSWFText(); 1535 if(this->text == NULL) 1536 throw SWFException("SWFText()"); 1537 this->character = (c_SWFCharacter)text; 1538 } 1539 1540 virtual ~SWFText() 1541 { destroySWFText(this->text); } 1542 1543 c_SWFBlock getBlock() 1544 { return (c_SWFBlock)this->text; } 1545 1546 void setFont(SWFFont *font) 1547 { SWFText_setFont(this->text, font->font); } 1548 1549 void setHeight(float height) 1550 { SWFText_setHeight(this->text, height); } 1551 1552 // I don't like this.. it's too easy to confuse with displayitem::moveTo 1553 void moveTo(float x, float y) 1554 { SWFText_moveTo(this->text, x, y); } 1555 1556 void setColor(byte r, byte g, byte b, byte a=0xff) 1557 { SWFText_setColor(this->text, r, g, b, a); } 1558 1559 void addString(const char *string, int *advance=NULL) 1560 { SWFText_addString(this->text, string, advance); } 1561 1562 void addUTF8String(const char *string, int *advance=NULL) 1563 { SWFText_addUTF8String(this->text, string, advance); } 1564 1565 void addWideString(const unsigned short *string, int len, int *advance = NULL) 1566 { SWFText_addWideString(this->text, string, len, advance); } 1567 1568 void setSpacing(float spacing) 1569 { SWFText_setSpacing(this->text, spacing); } 1570 1571 float getStringWidth(const char *string) 1572 { return SWFText_getStringWidth(this->text, string); } 1573 1574 float getWidth(const char *string) 1575 { return SWFText_getStringWidth(this->text, string); } 1576 1577 float getWideStringWidth(const unsigned short *string) 1578 { return SWFText_getWideStringWidth(this->text, string); } 1579 1580 float getUTF8Width(const char *string) 1581 { return SWFText_getUTF8StringWidth(this->text, string); } 1582 1583 float getAscent() 1584 { return SWFText_getAscent(this->text); } 1585 1586 float getDescent() 1587 { return SWFText_getDescent(this->text); } 1588 1589 float getLeading() 1590 { return SWFText_getLeading(this->text); } 1591 SWF_DECLAREONLY(SWFText); 1592 }; 1593 1594 /* SWFTextField */ 1595 1596 class SWFTextField : public SWFCharacter 1597 { 1598 public: 1599 c_SWFTextField textField; 1600 1601 SWFTextField() 1602 { 1603 this->textField = newSWFTextField(); 1604 if(this->textField == NULL) 1605 throw SWFException("SWFTextField()"); 1606 this->character = (c_SWFCharacter)textField; 1607 } 1608 1609 virtual ~SWFTextField() 1610 { destroySWFTextField(this->textField); } 1611 1612 c_SWFBlock getBlock() 1613 { return (c_SWFBlock)this->textField; } 1614 1615 void setFont(SWFBlock *font) 1616 { SWFTextField_setFont(this->textField, font->getBlock()); } 1617 1618 void setBounds(float width, float height) 1619 { SWFTextField_setBounds(this->textField, width, height); } 1620 1621 void setFlags(int flags) 1622 { SWFTextField_setFlags(this->textField, flags); } 1623 1624 void setColor(byte r, byte g, byte b, byte a=0xff) 1625 { SWFTextField_setColor(this->textField, r, g, b, a); } 1626 1627 void setVariableName(const char *name) 1628 { SWFTextField_setVariableName(this->textField, name); } 1629 1630 void addString(const char *string) 1631 { SWFTextField_addString(this->textField, string); } 1632 1633 void addUTF8String(const char *string) 1634 { SWFTextField_addUTF8String(this->textField, string); } 1635 1636 void setHeight(float height) 1637 { SWFTextField_setHeight(this->textField, height); } 1638 1639 void setLeftMargin(float margin) 1640 { SWFTextField_setLeftMargin(this->textField, margin); } 1641 1642 void setRightMargin(float margin) 1643 { SWFTextField_setRightMargin(this->textField, margin); } 1644 1645 void setIndentation(float indentation) 1646 { SWFTextField_setIndentation(this->textField, indentation); } 1647 1648 void setPadding(float padding) 1649 { SWFTextField_setPadding(this->textField, padding); } 1650 1651 void setLineSpacing(float lineSpacing) 1652 { SWFTextField_setLineSpacing(this->textField, lineSpacing); } 1653 1654 void setAlignment(SWFTextFieldAlignment alignment) 1655 { SWFTextField_setAlignment(this->textField, alignment); } 1656 1657 void align(SWFTextFieldAlignment alignment) 1658 { SWFTextField_setAlignment(this->textField, alignment); } 1659 1660 void setFieldHeight(int height) 1661 { SWFTextField_setFieldHeight(this->textField, height); } 1662 1663 void setLength(int length) 1664 { SWFTextField_setLength(this->textField, length); } 1665 1666 void addChars(const char *string) 1667 { SWFTextField_addChars(this->textField, string); } 1668 1669 SWF_DECLAREONLY(SWFTextField); 1670 }; 1671 1672 class SWFButtonRecord 1673 { 1674 friend class SWFButton; 1675 public: 1676 c_SWFButtonRecord record; 1677 1678 void addFilter(SWFFilter *f) 1679 { SWFButtonRecord_addFilter(this->record, f->filter); } 1680 1681 void setDepth(int depth) 1682 { SWFButtonRecord_setDepth(this->record, depth); } 1683 1684 void setBlendMode(int mode) 1685 { SWFButtonRecord_setBlendMode(this->record, mode); } 1686 1687 void move(float x, float y) 1688 { SWFButtonRecord_move(this->record, x, y); } 1689 1690 void moveTo(float x, float y) 1691 { SWFButtonRecord_moveTo(this->record, x, y); } 1692 1693 void rotate(float deg) 1694 { SWFButtonRecord_rotate(this->record, deg); } 1695 1696 void rotateTo(float deg) 1697 { SWFButtonRecord_rotateTo(this->record, deg); } 1698 1699 void scale(float scaleX, float scaleY) 1700 { SWFButtonRecord_scale(this->record, scaleX, scaleY); } 1701 1702 void scaleTo(float scaleX, float scaleY) 1703 { SWFButtonRecord_scaleTo(this->record, scaleX, scaleY); } 1704 1705 void skewX(float skewX) 1706 { SWFButtonRecord_skewX(this->record, skewX); } 1707 1708 void skewY(float skewY) 1709 { SWFButtonRecord_skewY(this->record, skewY); } 1710 1711 void skewXTo(float skewX) 1712 { SWFButtonRecord_skewXTo(this->record, skewX); } 1713 1714 void skewYTo(float skewY) 1715 { SWFButtonRecord_skewYTo(this->record, skewY); } 1716 1717 private: 1718 SWFButtonRecord(c_SWFButtonRecord record) 1719 { 1720 this->record = record; 1721 if(this->record == NULL) 1722 throw SWFException("ButtonRecord"); 1723 } 1724 SWF_DECLAREONLY(SWFButtonRecord); 1725 }; 1726 1727 /* SWFButton */ 1728 1729 class SWFButton : public SWFCharacter 1730 { 1731 public: 1732 c_SWFButton button; 1733 1734 SWFButton() 1735 { 1736 this->button = newSWFButton(); 1737 if(this->button == NULL) 1738 throw SWFException("SWFButton()"); 1739 this->character = (c_SWFCharacter)button; 1740 } 1741 1742 virtual ~SWFButton() 1743 { destroySWFButton(this->button); } 1744 1745 c_SWFBlock getBlock() 1746 { return (c_SWFBlock)this->button; } 1747 1748 SWFButtonRecord* addShape(SWFCharacter *character, byte flags) 1749 { return new SWFButtonRecord(SWFButton_addCharacter(this->button, (c_SWFCharacter)character->getBlock(), flags)); } 1750 1751 void addAction(SWFAction *action, int flags) 1752 { SWFButton_addAction(this->button, action->action, flags); } 1753 1754 void setMenu(int flag=0) 1755 { SWFButton_setMenu(this->button, flag); } 1756 1757 void addSound(SWFSound *sound, int flags) 1758 { SWFButton_addSound(this->button, sound->sound, flags); } 1759 1760 void setScalingGrid(int x, int y, int w, int h) 1761 { SWFButton_setScalingGrid(this->button, x, y, w, h); } 1762 1763 void removeScalingGrid() 1764 { SWFButton_removeScalingGrid(this->button); } 1765 1766 SWFButtonRecord* addCharacter(SWFCharacter *character, byte flags) 1767 { return new SWFButtonRecord( 1768 SWFButton_addCharacter(this->button, (c_SWFCharacter)character->getBlock(), flags)); } 1769 1770 SWF_DECLAREONLY(SWFButton); 1771 }; 1772 1773 /* SWFBinaryData */ 1774 class SWFBinaryData : public SWFBlock 1775 { 1776 public: 1777 c_SWFBinaryData data; 1778 1779 SWFBinaryData(unsigned char *data, int length) 1780 { 1781 this->data = newSWFBinaryData(data, length); 1782 if(this->data == NULL) 1783 throw SWFException("SWFBinaryData(char *data, int length)"); 1784 } 1785 1786 virtual ~SWFBinaryData() 1787 { destroySWFBinaryData(this->data); } 1788 1789 c_SWFBlock getBlock() 1790 { return (c_SWFBlock)this->data; } 1791 SWF_DECLAREONLY(SWFBinaryData); 1792 }; 1793 1794 /* SWFVideoStream */ 1795 class SWFVideoStream : public SWFCharacter 1796 { 1797 public: 1798 c_SWFVideoStream stream; 1799 1800 SWFVideoStream() 1801 { 1802 this->stream = newSWFVideoStream(); 1803 if(this->stream == NULL) 1804 throw SWFException("newSWFVideoStream()"); 1805 this->character = (c_SWFCharacter)stream; 1806 } 1807 1808 SWFVideoStream(const char *path) 1809 { 1810 this->stream = newSWFVideoStream_fromFile(fopen(path, "rb")); 1811 if(this->stream == NULL) 1812 throw SWFException("SWFVideoStream(const char *path)"); 1813 } 1814 1815 SWFVideoStream(FILE *file) 1816 { 1817 this->stream = newSWFVideoStream_fromFile(file); 1818 if(this->stream == NULL) 1819 throw SWFException(" SWFVideoStream(FILE *file)"); 1820 } 1821 1822 virtual ~SWFVideoStream() 1823 { destroySWFVideoStream(this->stream); } 1824 1825 void setDimension(int width, int height) 1826 { SWFVideoStream_setDimension(this->stream, width, height); } 1827 1828 int getNumFrames() 1829 { return SWFVideoStream_getNumFrames(this->stream); } 1830 1831 int hasAudio() 1832 { return SWFVideoStream_hasAudio(this->stream); } 1833 1834 int setFrameMode(int mode) 1835 { return SWFVideoStream_setFrameMode(this->stream, mode); } 1836 1837 int nextFrame() 1838 { return SWFVideoStream_nextFrame(this->stream); } 1839 1840 int seek(int frame, int whence) 1841 { return SWFVideoStream_seek(this->stream, frame, whence); } 1842 1843 c_SWFBlock getBlock() 1844 { return (c_SWFBlock)this->stream; } 1845 1846 SWF_DECLAREONLY(SWFVideoStream); 1847 1848 }; 1849 1850 #endif /* SWF_MINGPP_H_INCLUDED */ 1851