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