home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2002 April / Game.EXE_04_2002.iso / Alawar / TwinPictureFormat.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-25  |  1.4 KB  |  62 lines

  1. #include "PictureFormatManagerPtr.h"
  2. #include "TwinPictureFormat.h"
  3. #include "AutoPtr.h"
  4. #include "Color.h"
  5. #include "ResourceManagerPtr.h"
  6. #include "Resource.h"
  7. #include "String.h"
  8. #include "safe_new.h"
  9.  
  10. bool TwinPictureFormat::recursion = false;
  11.  
  12. TwinPictureFormat::TwinPictureFormat(const String & name)
  13. :    data( 0 ),
  14.     sx( 0 ),
  15.     sy( 0 )
  16. {
  17.     if( recursion )
  18.         return;
  19.     recursion = true; // êºíáó½∩Ѽß∩ «Γ »«»δΓ¬¿ ß«ºñáΓ∞ TwinResource, ß«ßΓ«∩Θ¿⌐ ¿º ñαπú¿σ TwinResource'«ó
  20.     AutoPtr<PictureFormat> cfor = PictureFormatManagerPtr()->create_format( name );
  21.     AutoPtr<PictureFormat> afor = PictureFormatManagerPtr()->create_format( name + "_a" );
  22.     recursion = false;
  23.     if( !cfor || !afor )
  24.         return;
  25.     if( cfor->width() != afor->width() || cfor->height() != afor->height() )
  26.         return;
  27.     sx = cfor->width();
  28.     sy = afor->height();
  29.  
  30.     data = new Color[sx*sy];
  31.  
  32.     const Color * cd = cfor->colors();
  33.     const Color * ad = afor->colors();
  34.     Color * curr = data;
  35.     const Color * data_end = curr + sx*sy;
  36.     for( ; curr != data_end; ++curr, ++cd, ++ad )
  37.     {
  38.         *curr = *cd;
  39.         curr->a = ad->r;
  40.     }
  41. }
  42.  
  43. TwinPictureFormat::~TwinPictureFormat()
  44. {
  45.     delete data; data = 0;
  46. }
  47.  
  48. unsigned TwinPictureFormat::width()const
  49. {
  50.     return sx;
  51. }
  52.  
  53. unsigned TwinPictureFormat::height()const
  54. {
  55.     return sy;
  56. }
  57.  
  58. const Color * TwinPictureFormat::colors()const
  59. {
  60.     return data;
  61. }
  62.