home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / flash078.zip / flashsource-r0_7_8.zip / FBase.h < prev    next >
C/C++ Source or Header  |  2001-08-02  |  21KB  |  821 lines

  1. #ifndef FBASE_H_FILE
  2. #define FBASE_H_FILE
  3.  
  4.  
  5. #include <iostream>
  6. #include <vector>
  7. #include <math.h>
  8.  
  9. /*static unsigned long arr1[] = {
  10.         0x0, 0x1, 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff,
  11.         0x1ff, 0x3ff, 0x7ff, 0xfff, 0x1fff, 0x3fff, 0x7fff, 0xffff,
  12.         0x1ffff, 0x3ffff, 0x7ffff, 0xfffff, 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff,
  13.         0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff
  14. };*/
  15.  
  16. class FlashImporter;
  17.  
  18. typedef unsigned char UBYTE;
  19. typedef char SBYTE;
  20.  
  21. typedef unsigned short UWORD;
  22. typedef short SWORD;
  23.  
  24. typedef unsigned int UDWORD;
  25. typedef int SDWORD;
  26.  
  27. #define WRITE_UBYTE(x) { UBYTE s = (x); out.write((char*)&s,1); }
  28. #define WRITE_SBYTE(x) { SBYTE s = (x); out.write((char*)&s,1); }
  29.  
  30. #define WRITE_UWORD(x) { UWORD s = (x); out.write((char*)&s,2); }
  31. #define WRITE_SWORD(x) { SWORD s = (x); out.write((char*)&s,2); }
  32.  
  33. #define WRITE_UDWORD(x) { UDWORD s = (x); out.write((char*)&s,4); }
  34. #define WRITE_SDWORD(x) { SDWORD s = (x); out.write((char*)&s,4); }
  35.  
  36. #define WRITE_UBYTE2(x,f) { UBYTE s = (x); f.write((char*)&s,1); }
  37. #define WRITE_SBYTE2(x,f) { SBYTE s = (x); f.write((char*)&s,1); }
  38.  
  39. #define WRITE_UWORD2(x,f) { UWORD s = (x); f.write((char*)&s,2); }
  40. #define WRITE_SWORD2(x,f) { SWORD s = (x); f.write((char*)&s,2); }
  41.  
  42. #define WRITE_UDWORD2(x,f) { UDWORD s = (x); f.write((char*)&s,4); }
  43. #define WRITE_SDWORD2(x,f) { SDWORD s = (x); f.write((char*)&s,4); }
  44.  
  45. #define READ_UBYTE(x) { in.read((char*)&x,1); }
  46. #define READ_SBYTE(x) { in.read((char*)&x,1); }
  47.  
  48. #define READ_UWORD(x) { in.read((char*)&x,2); }
  49. #define READ_SWORD(x) { in.read((char*)&x,2); }
  50.  
  51. #define READ_UDWORD(x) { in.read((char*)&x,4); }
  52. #define READ_SDWORD(x) { in.read((char*)&x,4); }
  53.  
  54. #define READ_UBYTE2(x,f) { f.read((char*)&x,1); }
  55. #define READ_SBYTE2(x,f) { f.read((char*)&x,1); }
  56.  
  57. #define READ_UWORD2(x,f) { f.read((char*)&x,2); }
  58. #define READ_SWORD2(x,f) { f.read((char*)&x,2); }
  59.  
  60. #define READ_UDWORD2(x,f) { f.read((char*)&x,4); }
  61. #define READ_SDWORD2(x,f) { f.read((char*)&x,4); }
  62.  
  63. #define DEFINE_RW_INTERFACE                                \
  64. public:                                                    \
  65. virtual void Write(std::ostream &out) { out << *this; } \
  66. virtual void Read(std::istream &in) { in >> *this; }    \
  67.  
  68. template <class T> T max(T a, T b)  {return (((a) > (b)) ? (a) : (b)); } 
  69. template <class T> T min(T a, T b)  {return (((a) < (b)) ? (a) : (b)); } 
  70.  
  71. template<class T, class U>
  72.     struct flash_pair {
  73.     typedef T first_type;
  74.     typedef U second_type;
  75.     T first;
  76.     U second;
  77.     flash_pair() {}
  78.     flash_pair(const T& x, const U& y) : first(x), second(y) {}
  79.     template<class V, class W>
  80.         flash_pair(const flash_pair<V, W>& pr) : first(pr.first), second(pr.second) {}
  81.     };
  82.  
  83. class FlashVersionEnabled
  84. {
  85. public:
  86.     FlashVersionEnabled() : version(1) {}
  87.     virtual void SetTagVersion(int v) { version = v; }
  88.     virtual int GetTagVersion(void) const { return version; }
  89. private:
  90.     int version;
  91. };
  92.  
  93. template<class T> T LSHR(T x, int num);
  94.  
  95. template<class T> int GetBitSize(T x)
  96. {
  97.     int size=0;
  98.     while(x > 0)
  99.     {
  100.       x=LSHR(x,1);
  101.       size++;
  102.     } 
  103.     return size;
  104. }
  105.  
  106. template<class T> int GetBitSizeSigned(T x)
  107. {
  108.     int size=0;
  109.     int sign = (long(x) < 0);
  110.     T tmp=x;
  111.     if(sign) tmp = tmp*(-1);
  112.     size = GetBitSize(tmp);
  113.     return (size+1);
  114. }
  115.  
  116. template<class T> T PackBitsSigned(T x)
  117. {    
  118.     UDWORD v=0x0;
  119.     int sign = (long(x) < 0);
  120.     if(sign) x=~x + 1;
  121.  
  122.     int i = GetBitSizeSigned(x);
  123. //    v = arr1[i];
  124.     for(int b=0; b < i; b++)
  125.     {
  126.         v = (v << 1) | 0x01;
  127.     }
  128.     v = (x & v) | (GetBit(x,sizeof(T)*8-1));
  129.     if(sign) return (T)(~v + 1);
  130.     return (v); 
  131. }
  132.  
  133. template<class T> T UnPackBitsSigned(T x, int size)
  134. {
  135.     int sign = GetBit(x,size-1);
  136.     
  137.     x = GetIsolatedBits(x,0,size);
  138.     
  139.     T v = 0;
  140.     if(sign == 1) 
  141.     {
  142.         int bit1 = size;
  143.         int bit2 = sizeof(T)*8;
  144. //        v = arr1[bit2-bit1];
  145.         for(int b=0; b < bit2-bit1; b++)
  146.           {
  147.             v = (v << 1) | 0x01;
  148.         }
  149. //        v <<= bit1;
  150.         for(int b2=0; b2 < bit1; b2++)
  151.         {
  152.             v = (v << 1);
  153.         }
  154.  
  155.     }
  156.     return (x | v); 
  157. }
  158.  
  159. template<class T> char GetBit(T x, int bit)
  160. {   
  161.     T y = 1 << bit;
  162.     if((x & y)==0) return (char)0;
  163.     return((char)1);
  164. }
  165.  
  166. template<class T> T IsolateBits(T x, int bit1, int bit2)
  167. {
  168.     T v=0;
  169.     //v = arr1[bit2-bit1];
  170.     for(int b=0; b < bit2-bit1; b++)
  171.     {
  172.         v = (v << 1) | 0x01;
  173.     }
  174.     //v <<= bit1;
  175.     for(int b2=0; b2 < bit1; b2++)
  176.     {
  177.         v = (v << 1);
  178.     }   
  179.     return (x & v);
  180. }
  181. template<class T> T LSHR(T x, int num)
  182. {
  183.     char sign = (GetBit(x,sizeof(T)*8-1));
  184.     T v = IsolateBits(x, 0, sizeof(T)*8-1);
  185.     v >>= num;
  186.     if(sign==1) 
  187.     {
  188.         v |= (((T)0x1) << (sizeof(T)*8-1));
  189.     }
  190.     return v;
  191. }
  192.  
  193. template<class T> T GetIsolatedBits(T x, int bit1, int bit2)
  194. {
  195.     T r = IsolateBits(x,bit1,bit2);
  196.     return ((T)(LSHR(r, bit1)));
  197. }
  198.  
  199.  
  200.  
  201. class BitStreamIn
  202. {
  203. public:
  204.     BitStreamIn(std::istream *i, int off=0) :
  205.       in(i), offset(off) {}
  206.     ~BitStreamIn()
  207.     {
  208.         Align();
  209.     }
  210.     //TODO Add Exception handling for nbits > bitsizeof()
  211.     template <class T> void Read(T &r, int nbits)
  212.     {
  213.         if (nbits == 0) return;
  214.         std::vector<int> tmp;
  215.  
  216.         int count   = 0;
  217.         int read     = 0-offset;
  218.         int to_go    = nbits;
  219.         int last;
  220.         do
  221.         {       
  222.             last = in->get();
  223.             tmp.push_back(last);
  224.             read += 8;
  225.             count++;
  226.         } while(read < to_go);
  227.         
  228.         
  229.         UDWORD bits=0;
  230.  
  231.         int bitsleft = (count*8)-(offset+nbits);
  232.         int bitsright = (count*8)-offset;
  233.         
  234.         int count2 = 0;
  235.         for(std::vector<int>::iterator i = tmp.begin(); i != tmp.end(); i++)
  236.         {
  237.  
  238.             count2++;
  239.             int shift = 8*(count-(count2));
  240.  
  241.             int b1 = max(bitsleft-shift,0);
  242.             int b2 = min(bitsright-shift,8);
  243.             
  244.             int c = GetIsolatedBits(*i, b1, b2);
  245.             
  246.             bits = bits << (b2-b1);
  247.             bits |= (T)(c & 0xff);
  248.             
  249.         }
  250.         offset = (offset+nbits)%8;
  251.         
  252.         if(offset != 0)
  253.         {       
  254.             in->putback(last);      
  255.         }
  256.         r = (T)bits;
  257.     }
  258.     
  259.     void Align() { if(offset != 0) in->get(); }
  260.     std::istream &GetStream() { return *in; }
  261. private:
  262.     std::istream *in;
  263.     int offset;
  264. };
  265.  
  266. class BitStreamOut
  267. {
  268.  
  269. public:
  270.     
  271.  
  272.     BitStreamOut(std::ostream *o) :
  273.       out (o), displace(0), curchar(0), remaining(false){ }
  274.     ~BitStreamOut() 
  275.     { 
  276.         if(remaining) (*out).put(curchar); 
  277.     }
  278.     
  279.     std::ostream *out;
  280. public:
  281.     template <class T>
  282.     void Write(T data, int bitsize)
  283.     {
  284.  
  285.         for(int i = 0; i < bitsize; i++)
  286.         {           
  287.             remaining = true;
  288.             int offset = 7-(displace%8);
  289.  
  290.             unsigned char val = GetBit(data, (bitsize)-1-i);        
  291.             unsigned char set = 0x01 << (offset);
  292.  
  293.             curchar = (curchar & ~set) | (val << (offset));
  294.             displace++;         
  295.             
  296.             offset = 7-(displace%8);
  297.             if(offset%8==7)
  298.             {
  299.                 (*out).put((char)curchar);
  300.                 curchar=0;
  301.                 remaining=false;
  302.                 displace=0;
  303.             }
  304.  
  305.         }
  306.  
  307.     }
  308.     void Align()
  309.     {
  310.         int offset = 7-(displace%8);
  311.         displace+=offset;
  312.         (*out).put((char)curchar);
  313.         curchar=0;      
  314.         remaining=false;
  315.         displace=0;
  316.     }
  317.     
  318. private:
  319.     int displace;
  320.     char curchar;
  321.     bool remaining; 
  322. };
  323.  
  324. template<class T> BitStreamOut &operator<< (BitStreamOut &o, const T t)
  325. {
  326.     o.Write(t,sizeof(T)*8);
  327. }
  328.  
  329. class BitBuffer
  330. {
  331. public:
  332.     BitBuffer() : displace(0) {}
  333.     ~BitBuffer() {}
  334.  
  335.     void WriteBytes(char *c, int numbytes)
  336.     {
  337.         for(int i=0; i < numbytes; i++)
  338.         {
  339.             Write(c[i],8);
  340.         }
  341.     }
  342.     void Write(UDWORD data, int bitsize)
  343.     {
  344.         for(int i = 0; i < bitsize; i++)
  345.         {
  346.             int pos    = displace/8;
  347.             int offset = 7-(displace%8);
  348.  
  349.             if(offset==7)
  350.             {
  351.                 v.push_back(0);
  352.             }
  353.             unsigned char val = GetBit(data, (bitsize)-1-i);        
  354.             unsigned char set = 0x01 << (offset);
  355.  
  356.             v[pos] = (v[pos] & ~set) | (val << (offset));
  357.             displace++;         
  358.         }
  359.     }
  360.     void Align()
  361.     {
  362.         int offset = 8-(displace%8);
  363.  
  364.         displace+=offset;
  365.     }
  366.  
  367. private:
  368.     long displace;
  369.     std::vector<char> v;
  370.     
  371.     friend BitStreamOut &operator<< (BitStreamOut &out, BitBuffer &data);
  372.     friend std::ostream &operator<< (std::ostream &out, BitBuffer &data);
  373.     friend std::istream &operator>> (std::istream &in,  BitBuffer &data);
  374. };
  375.  
  376. class FlashFixed
  377. {
  378. //private:
  379. public:
  380.     SWORD upperval;
  381.     UWORD lowerval;
  382. public: 
  383.     FlashFixed(void); 
  384.     FlashFixed(SWORD u, UWORD l); 
  385.     FlashFixed(double f); 
  386.  
  387.     UDWORD ConvertToRaw () const
  388.     {
  389.         UDWORD r = ((SDWORD)upperval)<<16;
  390.         r |= lowerval;
  391.         return r;
  392.     }
  393.     void GetFromRaw(SDWORD raw)
  394.     {
  395.         upperval = raw >> 16;
  396.         lowerval = (raw & 0xffff);
  397.     }
  398.     double ConvertToDouble() const
  399.     {
  400.         return upperval + double(lowerval) / 0x10000;
  401.     }
  402.     void GetFromDouble(double x)
  403.     {
  404.         upperval = (UWORD)floor(x);
  405.         lowerval = (UWORD)((x-floor(x))*0x10000);
  406.     }
  407.     
  408.     friend std::ostream &operator<< (std::ostream &out, const FlashFixed &data);
  409.     friend std::istream &operator>> (std::istream &in,  FlashFixed &data);
  410.  
  411. };
  412.  
  413. class FlashFixed16
  414. {
  415. //private
  416. public:
  417.     SBYTE upperval;
  418.     UBYTE lowerval;
  419. public: 
  420.     FlashFixed16(void); 
  421.     FlashFixed16(SBYTE u, UBYTE l); 
  422.     FlashFixed16(double f); 
  423.     
  424.     UWORD ConvertToRaw() const
  425.     {
  426.         UWORD r = ((SWORD)upperval)<<8;
  427.         r |= lowerval;
  428.         return r;
  429.     }
  430.     void GetFromRaw(SWORD raw)
  431.     {
  432.         upperval = raw >> 8;
  433.         lowerval = (raw & 0xff);
  434.     }
  435.     double ConvertToDouble()
  436.     {
  437.         return upperval + double(lowerval) / 0x100;
  438.     }
  439.     void GetFromDouble(double x)
  440.     {
  441.         upperval = (UBYTE)floor(x);
  442.         lowerval = (UBYTE)((x-floor(x))*0x100);
  443.     }
  444.     
  445.     friend std::ostream &operator<< (std::ostream &out, const FlashFixed16 &data);
  446.     friend std::istream &operator>> (std::istream &in,  FlashFixed16 &data);    
  447. };
  448.  
  449. class FlashMatrix
  450. {
  451. public:
  452.     FlashMatrix() : scale(false), scalex(0), scaley(0),
  453.                   rotate(false), rotatex(0), rotatey(0),
  454.                   translatex(0), translatey(0)
  455.     {
  456.     }
  457.     FlashMatrix(bool _scale, FlashFixed _scalex, FlashFixed _scaley,
  458.                 bool _rotate, FlashFixed _rotatex, FlashFixed _rotatey,
  459.                 SWORD _translatex, SWORD _translatey)
  460.                 : scale(_scale), scalex(_scalex), scaley(_scaley),
  461.                   rotate(_rotate), rotatex(_rotatex), rotatey(_rotatey),
  462.                   translatex(_translatex), translatey(_translatey)
  463.     {
  464.     }
  465.     
  466.     void SetScale(FlashFixed _scalex, FlashFixed _scaley) { scalex=_scalex; scaley=_scaley; scale=true;}
  467.     void SetRotate(FlashFixed _rotatex, FlashFixed _rotatey) { rotatex=_rotatex; rotatey=_rotatey; rotate = true;}
  468.     void SetTranslate(SWORD _translatex, SWORD _translatey) { translatex=_translatex; translatey=_translatey;}
  469.  
  470.     bool HasScale() const { return scale; }
  471.     bool HasRotate() const { return rotate; }
  472.  
  473.     FlashFixed GetRotateX() const { return rotatex; }
  474.     FlashFixed GetRotateY() const { return rotatey; }
  475.  
  476.     FlashFixed GetScaleX() const { return scalex; }
  477.     FlashFixed GetScaleY() const { return scaley; }
  478.  
  479.     FlashFixed GetTranslateX() const { return translatex; }
  480.     FlashFixed GetTranslateY() const { return translatey; }
  481.  
  482. private:
  483.     bool scale;
  484.     FlashFixed scalex;
  485.     FlashFixed scaley;
  486.     bool rotate;
  487.     FlashFixed rotatex;
  488.     FlashFixed rotatey;
  489.     SWORD translatex;
  490.     SWORD translatey;
  491.  
  492.     friend std::ostream &operator<< (std::ostream &out, const FlashMatrix &data);
  493.     friend std::istream &operator>> (std::istream &in,  FlashMatrix &data);
  494. };
  495.  
  496. class FlashMatrixScale : public FlashMatrix
  497. {
  498.     FlashMatrixScale(FlashFixed _scalex, FlashFixed _scaley) : 
  499.         FlashMatrix(true, _scalex, _scaley, false, 0, 0, 0, 0)
  500.     {
  501.         
  502.     }       
  503. };
  504.  
  505. class FlashMatrixRotate : public FlashMatrix
  506. {
  507.     FlashMatrixRotate(FlashFixed _rotatex, FlashFixed _rotatey) : 
  508.         FlashMatrix(false, 0, 0, true, _rotatex, _rotatey, 0, 0)
  509.     {
  510.         
  511.     }       
  512. };
  513.  
  514. class FlashMatrixTranslate : public FlashMatrix
  515. {
  516.     FlashMatrixTranslate(SWORD x, SWORD y) : 
  517.         FlashMatrix(false, 0, 0, false, 0, 0, x, y)
  518.     {
  519.         
  520.     }       
  521. };
  522.  
  523. class FlashRGB
  524. {
  525. public: 
  526.     FlashRGB() : r(0), g(0), b(0), a(0xff), alpha(false) { }
  527.     FlashRGB(SWORD _r, SWORD _g, SWORD _b) : r(_r), g(_g), b(_b), a(0xff), alpha(false){ }
  528.     FlashRGB(SWORD _r, SWORD _g, SWORD _b, SWORD _a) : r(_r), g(_g), b(_b), a(_a), alpha(true){ }
  529.  
  530.     void Write(BitBuffer &out, int num=-1);
  531.     
  532.     void Read(BitStreamIn &in, int num=-1);
  533.  
  534.     bool GetAlphaWriteMode(void)   { return (alpha); }
  535.     void SetAlphaWriteMode(bool a) { alpha=a; }
  536.  
  537.     int GetNumBits() 
  538.     { 
  539.         if(alpha) return max(max(GetBitSizeSigned(a),GetBitSizeSigned(b)),max(GetBitSizeSigned(r),GetBitSizeSigned(g)));
  540.         return max(GetBitSizeSigned(b),max(GetBitSizeSigned(r),GetBitSizeSigned(g)));
  541.     }
  542.     
  543.     SWORD GetR() { return r; }
  544.     SWORD GetG() { return g; }
  545.     SWORD GetB() { return b; }
  546.     SWORD GetA() { return a; }
  547.     void SetR(SWORD _r) {r = _r; }
  548.     void SetG(SWORD _g) {g = _g; }
  549.     void SetB(SWORD _b) {b = _b; }
  550.     void SetA(SWORD _a) {a = _a; }
  551.     void SetRGBA(SWORD _r, SWORD _g, SWORD _b, SWORD _a)
  552.     {
  553.         r = _r;
  554.         g = _g;
  555.         b = _b;
  556.         a = _a;
  557.     }
  558.     void SetRGB(SWORD _r, SWORD _g, SWORD _b)
  559.     {
  560.         r = _r;
  561.         g = _g;
  562.         b = _b;
  563.     }
  564.  
  565. private:    
  566.     SWORD r;
  567.     SWORD g;
  568.     SWORD b;
  569.     SWORD a;
  570.     bool alpha;
  571.     friend std::ostream &operator<< (std::ostream &out, const FlashRGB &data);
  572.     friend std::istream &operator>> (std::istream &in,  FlashRGB &data);
  573. };
  574.  
  575. class FlashColorTransform : public FlashVersionEnabled
  576. {
  577. public:
  578.     FlashColorTransform() : add(false), mult(false){}
  579.     
  580.     FlashColorTransform(bool _add, FlashRGB& _addFlashRGB, bool _mult, FlashRGB& _multFlashRGB)
  581.         : add(_add), mult(_mult), addFlashRGB(_addFlashRGB), multFlashRGB(_multFlashRGB){}
  582.         
  583.     friend std::ostream& operator<<(std::ostream& out, FlashColorTransform &data);
  584.     friend std::istream& operator>>(std::istream& in, FlashColorTransform &data);
  585.  
  586.     bool HasAdd() const { return add; }
  587.     bool HasMult() const { return mult; }
  588.     
  589.     FlashRGB GetAddRGB() const { return addFlashRGB; }
  590.     FlashRGB GetMultRGB() const { return multFlashRGB; }
  591.  
  592.     void SetAddRGB(FlashRGB _addFlashRGB) 
  593.     {
  594.         addFlashRGB = _addFlashRGB;
  595.         add = true;
  596.     }
  597.     void SetMultRGB(FlashRGB _multFlashRGB) 
  598.     {
  599.         multFlashRGB = _multFlashRGB;
  600.         mult = true;
  601.     }
  602.  
  603.     void SetAdd(short _addFlashR, short _addFlashG, short _addFlashB) 
  604.     {
  605.         addFlashRGB = FlashRGB(_addFlashR, _addFlashG, _addFlashB);
  606.         add = true;
  607.     }
  608.     void SetMult(FlashFixed16 _multFlashR, FlashFixed16 _multFlashG, FlashFixed16 _multFlashB) 
  609.     {
  610.         multFlashRGB = FlashRGB(_multFlashR.ConvertToRaw(), _multFlashG.ConvertToRaw(), _multFlashB.ConvertToRaw());
  611.         mult = true;
  612.     }
  613.  
  614. private:
  615.     bool add;
  616.     bool mult;
  617.     FlashRGB addFlashRGB;
  618.     FlashRGB multFlashRGB;
  619. };
  620.  
  621. class FlashRect
  622. {
  623. public:
  624.     FlashRect(int _x1, int _y1, int _x2, int _y2) : 
  625.       x1(_x1), y1(_y1), x2(_x2), y2(_y2), defined(true) {}
  626.     
  627.     FlashRect() : x1(0), y1(0), x2(0), y2(0), defined(false) {}
  628.     
  629.     ~FlashRect() {}
  630.  
  631.     bool IsDefined() { return(defined); }
  632.     
  633.     void SetRect(int _x1, int _y1, int _x2, int _y2)
  634.     {
  635.       x1 = _x1;
  636.       y1 = _y1;
  637.       x2 = _x2;
  638.       y2 = _y2;
  639.     }
  640.     
  641.     SWORD GetX1() const { return x1; }
  642.     SWORD GetX2() const { return x2; }
  643.     SWORD GetY1() const { return y1; }
  644.     SWORD GetY2() const { return y2; }
  645.  
  646.     void BoundWith(const FlashRect &r) { x1 = min(x1,r.x1); x2 = max(x2, r.x2); y1 = min(y1,r.y1); y2 = max(y2, r.y2); };
  647. private:
  648.     int x1; 
  649.     int y1;
  650.     int x2;
  651.     int y2;
  652.     bool defined;
  653.  
  654.     friend std::ostream &operator<< (std::ostream &out, const FlashRect &data);
  655.     friend std::istream &operator>> (std::istream &in,  FlashRect &data);
  656. };
  657.  
  658.  
  659. class FlashHeader
  660. {
  661. public:
  662.     FlashHeader(UBYTE _version, UDWORD _filesize, int width, int height, UWORD _framerate, UWORD _framecount);
  663.     FlashHeader(UBYTE _version, UDWORD _filesize, int width, int height, double _framerate, UWORD _framecount);
  664.  
  665.     ~FlashHeader() {}
  666.  
  667.     UBYTE  GetVersion(void) { return version; }
  668.     UDWORD GetFilesize(void) { return filesize; }
  669.     FlashRect GetScreenSize(void) { return size; }
  670.     FlashFixed16 GetFrameRate(void) { return frameRate; }
  671.     UWORD GetFrameCount(void) { return frameCount; }
  672.  
  673. private:
  674.     
  675.     friend std::ostream &operator << (std::ostream &out, const FlashHeader &data);
  676.     friend std::istream &operator >> (std::istream &in,  FlashHeader &data);
  677.  
  678.     UBYTE  version;
  679.     UDWORD filesize;
  680.     FlashRect size;
  681.     FlashFixed16 frameRate;
  682.     UWORD frameCount;
  683. protected:
  684.     FlashHeader() {};
  685.     friend class FlashImporter;
  686.  
  687. };
  688.  
  689. class FlashTagHeader
  690. {
  691. DEFINE_RW_INTERFACE
  692. public:
  693.     FlashTagHeader(UWORD _tagID, UDWORD _length) : tagID(_tagID), length(_length) {}
  694.     virtual ~FlashTagHeader() {}
  695.  
  696.     UWORD GetTagID(void) { return tagID; }
  697.     UDWORD GetTagLength(void) { return length; }
  698.  
  699. private:
  700.     UWORD  tagID;
  701.     UDWORD length;
  702.  
  703.     friend std::ostream &operator << (std::ostream &out, const FlashTagHeader &data);
  704.     friend std::istream &operator >> (std::istream &in,  FlashTagHeader &data);
  705. protected:
  706.     FlashTagHeader() {}
  707.     friend class FlashImporter;
  708. };
  709.  
  710.  
  711. class FlashTag
  712. {
  713. DEFINE_RW_INTERFACE
  714. public:
  715.     FlashTag() {}
  716.     virtual ~FlashTag() {}
  717.  
  718.     void SetImportSize(UDWORD i) { importsize = i; }    
  719. protected:
  720.     UDWORD importsize;
  721. private:        
  722.     friend std::ostream &operator << (std::ostream &out, const FlashTag &data);
  723.     friend std::istream &operator >> (std::istream &in,  FlashTag &data);
  724. };
  725.  
  726. class FlashSpriteEnabled : public FlashTag
  727. {
  728. public:
  729.     FlashSpriteEnabled() {}
  730.     virtual ~FlashSpriteEnabled() {}
  731.     virtual bool isFrame() { return false; }
  732.  
  733. };
  734.  
  735. class FlashIDFactory
  736. {
  737. public: 
  738.     FlashIDFactory() {};
  739.  
  740.     UWORD GetCharacterID() 
  741.     { 
  742.         UWORD _IDCharacter = IDCharacter; 
  743.         IDCharacter++; 
  744.         return (_IDCharacter); 
  745.     }
  746.     static void ResetCount()
  747.     {
  748.         IDCharacter=0;
  749.     }
  750. private:    
  751.     static UWORD IDCharacter;
  752. };
  753.  
  754. class FlashIDEnabled
  755. {
  756. public:
  757.     FlashIDEnabled(bool count=true) { if(count) charID = idFactory.GetCharacterID(); }
  758.     
  759.     void SetID(UWORD i) { charID=i; }
  760.     UWORD GetID(void) const { return (charID); }
  761. private:
  762.     FlashIDFactory idFactory;
  763.     UWORD charID;
  764. };
  765.  
  766. #define DEFINE_SIMPLE_TAG(x, n) \
  767. std::ostream &operator << (std::ostream &out, const x &data) \
  768. { \
  769.     return (out << FlashTagHeader(n,0)); \
  770. } \
  771. std::istream &operator >> (std::istream &in,  x &data) \
  772. { \
  773.     return in; \
  774. }
  775.  
  776. #define DECLARE_SIMPLE_TAG(x) \
  777. class x : public FlashTag \
  778. {                               \
  779.     DEFINE_RW_INTERFACE            \
  780. public:                         \
  781.     x() {} \
  782.     ~x() {} \
  783.     friend std::ostream &operator << (std::ostream &out, const x &data); \
  784.     friend std::istream &operator >> (std::istream &in,  x &data); \
  785. };
  786.  
  787. #define DECLARE_SIMPLE_TAG2(x) \
  788. class x : public FlashSpriteEnabled \
  789. {                               \
  790.     DEFINE_RW_INTERFACE            \
  791. public:                         \
  792.     x() {} \
  793.     ~x() {} \
  794.     friend std::ostream &operator << (std::ostream &out, const x &data); \
  795.     friend std::istream &operator >> (std::istream &in,  x &data); \
  796. };
  797.  
  798. #define DECLARE_SIMPLE_TAG3(x) \
  799. class x : public FlashSpriteEnabled \
  800. {                               \
  801.     DEFINE_RW_INTERFACE            \
  802. public:                         \
  803.     x() {} \
  804.     ~x() {} \
  805.     virtual bool isFrame() { return true; }\
  806.     friend std::ostream &operator << (std::ostream &out, const x &data); \
  807.     friend std::istream &operator >> (std::istream &in,  x &data); \
  808. };
  809.  
  810. template<class T> class gc_vector: public std::vector<T>
  811. {
  812. public:    
  813.     gc_vector() {}
  814.     gc_vector(const gc_vector &c) {}
  815.     ~gc_vector() { for(std::vector<T>::iterator i = begin(); i != end(); i++) { delete *i; }}
  816. };
  817.  
  818. FlashMatrix CreateMatrix(FlashRect bounds,float scaleX,float scaleY,float rotation,float translateX,float translateY,bool bScale, bool bRotate);
  819.  
  820. #endif
  821.