Image.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program 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
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: Image.h //////////////////////////////////////////////////////////////////////////////////
  24. // Created: Colin Day, June 2001
  25. // Desc: High level representation of images, this is currently being
  26. // written so we have a way to refer to images in the windows GUI.
  27. ///////////////////////////////////////////////////////////////////////////////////////////////////
  28. #pragma once
  29. #ifndef __IMAGE_H_
  30. #define __IMAGE_H_
  31. #include "Common/AsciiString.h"
  32. #include "Common/GameMemory.h"
  33. #include "Common/SubsystemInterface.h"
  34. #include <map>
  35. struct FieldParse;
  36. class INI;
  37. //-------------------------------------------------------------------------------------------------
  38. /** Image status bits. Keep in sync with imageStatusNames[] */
  39. //-------------------------------------------------------------------------------------------------
  40. typedef enum
  41. {
  42. IMAGE_STATUS_NONE = 0x00000000,
  43. IMAGE_STATUS_ROTATED_90_CLOCKWISE = 0x00000001, // image should be treated as rotated
  44. IMAGE_STATUS_RAW_TEXTURE = 0x00000002, // image struct contains raw texture data
  45. } ImageStatus;
  46. #ifdef DEFINE_IMAGE_STATUS_NAMES
  47. static const char *imageStatusNames[] =
  48. {
  49. "ROTATED_90_CLOCKWISE",
  50. "RAW_TEXTURE",
  51. NULL
  52. };
  53. #endif // end DEFINE_IMAGE_STATUS_NAMES
  54. //-------------------------------------------------------------------------------------------------
  55. /** Image bitmap information */
  56. //-------------------------------------------------------------------------------------------------
  57. class Image : public MemoryPoolObject
  58. {
  59. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( Image, "Image" );
  60. public:
  61. Image( void );
  62. // virtual desctructor defined by memory pool object
  63. void setName( AsciiString name ); ///< set image name
  64. AsciiString getName( void ) const; ///< return name
  65. void setFilename( AsciiString filename ); ///< set filename
  66. AsciiString getFilename( void ) const; ///< return filename
  67. void setUV( Region2D *uv ); ///< set UV coord range
  68. const Region2D *getUV( void ) const; ///< get UV coords
  69. void setTextureWidth( Int width ); ///< set width of texture page this image is on
  70. void setTextureHeight( Int height ); ///< set height of texture page this image is on
  71. const ICoord2D *getTextureSize( void ) const; ///< return the texture size defined
  72. void setImageSize( ICoord2D *size ); ///< set image width and height
  73. const ICoord2D *getImageSize( void ) const; ///< get size
  74. Int getImageWidth( void ) const; ///< get width
  75. Int getImageHeight( void ) const; ///< get height
  76. void setRawTextureData( void *data ); ///< set raw texture data
  77. const void *getRawTextureData( void ) const; ///< get raw texture data
  78. UnsignedInt setStatus( UnsignedInt bit ); ///< set status bit
  79. UnsignedInt clearStatus( UnsignedInt bit ); ///< clear status bit
  80. UnsignedInt getStatus( void ) const; ///< get status bits
  81. // for parsing from INI
  82. const FieldParse *getFieldParse( void ) const { return m_imageFieldParseTable; }
  83. static void parseImageCoords( INI* ini, void *instance, void *store, const void* /*userData*/ );
  84. static void parseImageStatus( INI* ini, void *instance, void *store, const void* /*userData*/ );
  85. protected:
  86. friend class ImageCollection;
  87. AsciiString m_name; ///< name for this image
  88. AsciiString m_filename; ///< texture filename this image is in
  89. ICoord2D m_textureSize; ///< size of the texture this image is a part of
  90. Region2D m_UVCoords; ///< texture UV coords for image
  91. ICoord2D m_imageSize; ///< dimensions of image
  92. void *m_rawTextureData; ///< raw texture data
  93. UnsignedInt m_status; ///< status bits from ImageStatus
  94. static const FieldParse m_imageFieldParseTable[]; ///< the parse table for INI definition
  95. }; // end Image
  96. //-------------------------------------------------------------------------------------------------
  97. /** A collection of images */
  98. //-------------------------------------------------------------------------------------------------
  99. class ImageCollection : public SubsystemInterface
  100. {
  101. public:
  102. ImageCollection( void );
  103. virtual ~ImageCollection( void );
  104. virtual void init( void ) { }; ///< initialize system
  105. virtual void reset( void ) { }; ///< reset system
  106. virtual void update( void ) { }; ///< update system
  107. void load( Int textureSize ); ///< load images
  108. const Image *findImageByName( const AsciiString& name ); ///< find image based on name
  109. /// adds the given image to the collection, transfers ownership to this object
  110. void addImage(Image *image);
  111. /// enumerates the list of existing images
  112. Image *Enum(unsigned index)
  113. {
  114. for (std::map<unsigned,Image *>::iterator i=m_imageMap.begin();i!=m_imageMap.end();++i)
  115. if (!index--)
  116. return i->second;
  117. return NULL;
  118. }
  119. protected:
  120. std::map<unsigned,Image *> m_imageMap; ///< maps named keys to images
  121. }; // end ImageCollection
  122. // INLINING ///////////////////////////////////////////////////////////////////////////////////////
  123. inline void Image::setName( AsciiString name ) { m_name = name; }
  124. inline AsciiString Image::getName( void ) const { return m_name; }
  125. inline void Image::setFilename( AsciiString name ) { m_filename = name; }
  126. inline AsciiString Image::getFilename( void ) const { return m_filename; }
  127. inline void Image::setUV( Region2D *uv ) { if( uv ) m_UVCoords = *uv; }
  128. inline const Region2D *Image::getUV( void ) const { return &m_UVCoords; }
  129. inline void Image::setTextureWidth( Int width ) { m_textureSize.x = width; }
  130. inline void Image::setTextureHeight( Int height ) { m_textureSize.y = height; }
  131. inline void Image::setImageSize( ICoord2D *size ) { m_imageSize = *size; }
  132. inline const ICoord2D *Image::getImageSize( void ) const { return &m_imageSize; }
  133. inline const ICoord2D *Image::getTextureSize( void ) const { return &m_textureSize; }
  134. inline Int Image::getImageWidth( void ) const { return m_imageSize.x; }
  135. inline Int Image::getImageHeight( void ) const { return m_imageSize.y; }
  136. inline void Image::setRawTextureData( void *data ) { m_rawTextureData = data; }
  137. inline const void *Image::getRawTextureData( void ) const { return m_rawTextureData; }
  138. inline UnsignedInt Image::getStatus( void ) const { return m_status; }
  139. // EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
  140. extern ImageCollection *TheMappedImageCollection; ///< mapped images
  141. #endif // __IMAGE_H_