home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / flash078.zip / flashsource-r0_7_8.zip / FButton.cpp < prev    next >
C/C++ Source or Header  |  2001-07-26  |  5KB  |  197 lines

  1. #include <strstream>
  2. #include "FButton.h"
  3.  
  4. FlashButtonRecord::FlashButtonRecord(UWORD _charID, UWORD _depth, char _validstates, 
  5.                                      FlashMatrix &_matrix, FlashColorTransform &_cfx) :
  6.                                      charID(_charID), depth(_depth), validstates(_validstates),
  7.                                          matrix(_matrix), cfx(_cfx)
  8. {
  9.  
  10. }
  11.  
  12. std::ostream &operator<< (std::ostream &out, FlashButtonRecord &data)
  13. {
  14.     out.put(data.validstates);
  15.     WRITE_UWORD(data.charID);
  16.     WRITE_UWORD(data.depth);
  17.     out << data.matrix;
  18.     if(data.GetTagVersion() > 1) out << data.cfx;
  19.     data.cfx.SetTagVersion(data.GetTagVersion());
  20.     return out;
  21. }
  22. std::istream &operator>> (std::istream &in,  FlashButtonRecord &data)
  23. {
  24.     data.validstates = in.get();
  25.     READ_UWORD(data.charID);
  26.     READ_UWORD(data.depth);
  27.     in >> data.matrix;
  28.     data.cfx.SetTagVersion(data.GetTagVersion());
  29.     if(data.GetTagVersion() > 1) in >> data.cfx;
  30.     return in;
  31. }
  32.  
  33. void FlashTagDefineButton::AddButtonRecord(FlashButtonRecord *r)
  34. {
  35.     buttonrecords.push_back(r);
  36. }
  37. void FlashTagDefineButton::AddActionRecord(FlashActionRecord *r)
  38. {
  39.     actionrecords.push_back(r);
  40. }
  41.  
  42. std::ostream &operator<< (std::ostream &out, FlashTagDefineButton &data)
  43. {
  44.     
  45.     std::ostrstream tmp;
  46.     
  47.     for(std::vector<FlashButtonRecord*>::iterator ib=data.buttonrecords.begin();
  48.         ib != data.buttonrecords.end(); ib++)
  49.         {
  50.             (*ib)->SetTagVersion(0);
  51.             tmp << *(*ib);
  52.         }
  53.         tmp.put( (char) 0);
  54.     
  55.     for(std::vector<FlashActionRecord*>::iterator ir=data.actionrecords.begin();
  56.         ir != data.actionrecords.end(); ir++)
  57.         {
  58.             (*ir)->Write(tmp);
  59.         }
  60.         tmp.put( (char) 0);
  61.     
  62.         
  63.     out << FlashTagHeader(7,tmp.pcount()+2);
  64.     WRITE_UWORD(data.GetID());
  65.     
  66.     out.write(tmp.rdbuf()->str(), tmp.pcount());
  67.     
  68.     return out;
  69. }
  70.  
  71. std::istream &operator>> (std::istream &in,  FlashTagDefineButton &data)
  72. {
  73.     
  74.     UWORD d;
  75.     READ_UWORD(d);
  76.     data.SetID(d);
  77.     
  78.     int i;
  79.     int count = 0;
  80.     for(i = in.get(); i != 0; i=in.get())
  81.     {
  82.         in.putback(i);
  83.         data.buttonrecords.push_back(new FlashButtonRecord());
  84.         data.gcbuttonrecords.push_back(data.buttonrecords[count]);
  85.         data.buttonrecords[i]->SetTagVersion(0);
  86.         in >> *data.buttonrecords[i];
  87.         count ++;
  88.     }
  89.     count = 0;
  90.  
  91.     FlashActionVectorImporter import;
  92.     import.Import(in, data.actionrecords, data.gcactionrecords);
  93.     
  94.     return in;
  95. }
  96.  
  97. FlashTagDefineButton2::~FlashTagDefineButton2() 
  98. {     
  99. }
  100. void FlashTagDefineButton2::AddButtonRecord(FlashButtonRecord *r)
  101. {
  102.     buttonrecords.push_back(r);
  103. }
  104. void FlashTagDefineButton2::AddActionRecords(std::vector<FlashActionRecord *> &r, UWORD conditionflags)
  105. {
  106.     actionrecords.push_back(flash_pair<std::vector<FlashActionRecord *>, UWORD>(r,conditionflags));
  107. }
  108. std::ostream &operator<< (std::ostream &out, FlashTagDefineButton2 &data)
  109. {
  110.     std::ostrstream tmp;
  111.     for(std::vector<FlashButtonRecord*>::iterator ib=data.buttonrecords.begin();
  112.         ib != data.buttonrecords.end(); ib++)
  113.         {
  114.             (*ib)->SetTagVersion(2);
  115.             tmp << *(*ib);
  116.         }
  117.         tmp.put((char)0);
  118.     
  119.     UWORD offset = tmp.pcount();
  120.         
  121.     for(std::vector<flash_pair<std::vector<FlashActionRecord *>,UWORD> >::iterator ir
  122.             = data.actionrecords.begin();
  123.         ir != data.actionrecords.end(); ir++)
  124.         {
  125.             std::ostrstream tmp2;
  126.             WRITE_UWORD2((*ir).second,tmp2);
  127.             
  128.             for(std::vector<FlashActionRecord *>::iterator i = (*ir).first.begin(); 
  129.                 i != (*ir).first.end();
  130.                 i++)
  131.                 {
  132.                     (*i)->Write(tmp2);            
  133.                 }
  134.             tmp2.put((char)0);
  135.  
  136.             std::vector<flash_pair<std::vector<FlashActionRecord *>,UWORD> >::iterator irt = ir;
  137.             irt++;
  138.             if(irt != (data.actionrecords.end()))
  139.             {
  140.                 WRITE_UWORD2(tmp2.pcount(), tmp);
  141.             }
  142.             else 
  143.             {
  144.                 WRITE_UWORD2(0, tmp);
  145.             }
  146.             tmp.write(tmp2.rdbuf()->str(), tmp2.pcount());
  147.         }        
  148.     out << FlashTagHeader(34,tmp.pcount()+5);    
  149.     WRITE_UWORD(data.GetID());
  150.     out.put((char)data.menu);
  151.     WRITE_UWORD(offset+2);
  152.     out.write(tmp.rdbuf()->str(), tmp.pcount());
  153.     return out;
  154. }
  155.  
  156. std::istream &operator>> (std::istream &in,  FlashTagDefineButton2 &data)
  157. {
  158.     std::ostrstream tmp;
  159.         
  160.     UWORD d;
  161.     READ_UWORD(d);
  162.     data.SetID(d);
  163.     data.menu = (in.get()==1);
  164.     int i;
  165.     int count = 0;
  166.     for(i = in.get(); i != 0; i=in.get())
  167.     {
  168.         in.putback(i);
  169.         data.buttonrecords.push_back(new FlashButtonRecord());
  170.         data.gcbuttonrecords.push_back(data.buttonrecords[count]);
  171.         data.buttonrecords[count]->SetTagVersion(2);
  172.         in >> *data.buttonrecords[count];
  173.         count ++;
  174.     }
  175.  
  176.     
  177.     int count2 = 0;
  178.     do
  179.     {
  180.         READ_UWORD(d);
  181.         UWORD d2;
  182.         READ_UWORD(d2);
  183.         
  184.         std::vector<FlashActionRecord *> x;
  185.         flash_pair<std::vector<FlashActionRecord *>,UWORD> tmp(x,d2);
  186.         data.actionrecords.push_back(tmp);
  187.         
  188.         FlashActionVectorImporter import;
  189.         import.Import(in, data.actionrecords[count2].first, data.gcactionrecords);
  190.         
  191.         count2++;
  192.  
  193.     } while (d != 0);
  194.  
  195.     return in;
  196. }
  197.