AlphaAnimType.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // AlphaAnimType.h
  19. // Project: Postal
  20. //
  21. ////////////////////////////////////////////////////////////////////////////////
  22. #ifndef ALPHAANIMTYPE_H
  23. #define ALPHAANIMTYPE_H
  24. // Simple wrapper class for each frame of alpha animation
  25. class CAlphaAnim
  26. {
  27. public:
  28. short m_sNumAlphas; // Number of alpha images (could be 0!)
  29. short m_sX; // Offset from hotspot to upper-left corner of image
  30. short m_sY; // Offset from hotspot to upper-left corner of image
  31. RImage m_imColor; // "Normal" 8-bit color image
  32. RImage* m_pimAlphaArray; // Array of alpha image's (could be empty!)
  33. public:
  34. CAlphaAnim()
  35. {
  36. m_pimAlphaArray = 0;
  37. Reset();
  38. };
  39. ~CAlphaAnim()
  40. {
  41. Reset();
  42. };
  43. CAlphaAnim& operator=(const CAlphaAnim& rhs)
  44. {
  45. Reset();
  46. m_sNumAlphas = rhs.m_sNumAlphas;
  47. m_sX = rhs.m_sX;
  48. m_sY = rhs.m_sY;
  49. m_imColor = rhs.m_imColor;
  50. Alloc(m_sNumAlphas);
  51. rspObjCpy(m_pimAlphaArray, rhs.m_pimAlphaArray, m_sNumAlphas);
  52. return *this;
  53. }
  54. bool operator==(const CAlphaAnim& rhs) const
  55. {
  56. // Comparing two of these objects is a major undertaking. Instead,
  57. // we'll always say that they are different. This is not a great
  58. // solution. In fact, it sucks. But what the hell...
  59. return false;
  60. }
  61. void Reset(void)
  62. {
  63. Free();
  64. m_sNumAlphas = 0;
  65. m_sX = 0;
  66. m_sY = 0;
  67. }
  68. void Alloc(short sNumAlphas)
  69. {
  70. Free();
  71. if (sNumAlphas > 0)
  72. {
  73. m_pimAlphaArray = new RImage[sNumAlphas];
  74. ASSERT(m_pimAlphaArray != 0);
  75. }
  76. m_sNumAlphas = sNumAlphas;
  77. }
  78. void Free(void)
  79. {
  80. delete []m_pimAlphaArray;
  81. m_pimAlphaArray = 0;
  82. }
  83. short Load(RFile* pFile)
  84. {
  85. pFile->Read(&m_sNumAlphas);
  86. pFile->Read(&m_sX);
  87. pFile->Read(&m_sY);
  88. m_imColor.Load(pFile);
  89. Alloc(m_sNumAlphas);
  90. for (short s = 0; s < m_sNumAlphas; s++)
  91. m_pimAlphaArray[s].Load(pFile);
  92. return pFile->Error();
  93. }
  94. short Save(RFile* pFile)
  95. {
  96. pFile->Write(m_sNumAlphas);
  97. pFile->Write(m_sX);
  98. pFile->Write(m_sY);
  99. m_imColor.Save(pFile);
  100. for (short s = 0; s < m_sNumAlphas; s++)
  101. m_pimAlphaArray[s].Save(pFile);
  102. return pFile->Error();
  103. }
  104. };
  105. #endif //ALPHAANIMTYPE_H
  106. ////////////////////////////////////////////////////////////////////////////////
  107. // EOF
  108. ////////////////////////////////////////////////////////////////////////////////