shapeset.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. ** Command & Conquer Generals(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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /Commando/Code/wwlib/shapeset.h $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 11/28/00 2:44p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * ShapeSet::Fetch_Data -- Fetches pointer to raw shape data. *
  35. * ShapeSet::Fetch_Rect -- Fetch the sub-rectangle of a shape. *
  36. * ShapeSet::Is_Transparent -- Is the specified shape containing transparent pixels? *
  37. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  38. #ifndef SHAPESET_H
  39. #define SHAPESET_H
  40. #include "bool.h"
  41. #include "trect.h"
  42. /*
  43. ** This is the header that appears at the beginning of the ShapeSet file. The header
  44. ** is a multiple of 8 bytes long to facilitate data alignment. The shape header is
  45. ** immediately followed by an N length array of ShapeRecord objects. The actual
  46. ** shape data follows this array.
  47. */
  48. class ShapeSet
  49. {
  50. public:
  51. /*
  52. ** Fetch pointer to raw shape data (NULL if not present or empty).
  53. */
  54. void * Get_Data(int shape) const;
  55. /*
  56. ** Fetch sub-rectangle that the shape data represents.
  57. */
  58. Rect Get_Rect(int shape) const;
  59. /*
  60. ** Are there any transparent pixels within the shape?
  61. */
  62. bool Is_Transparent(int shape) const;
  63. /*
  64. ** Determines if the specified shape is RLE compressed.
  65. */
  66. bool Is_RLE_Compressed(int shape) const;
  67. /*
  68. ** Logical width of the shape set.
  69. */
  70. int Get_Width(void) const {return(Width);}
  71. /*
  72. ** Logical height of the shape set.
  73. */
  74. int Get_Height(void) const {return(Height);}
  75. /*
  76. ** Number of shapes in this shape set.
  77. */
  78. int Get_Count(void) const{return(Count);}
  79. /*
  80. ** Gets the raw data size for a particular shape.
  81. */
  82. int Get_Size(int shape) const;
  83. protected:
  84. /*
  85. ** QShape information flags.
  86. */
  87. short Flags;
  88. /*
  89. ** The nominal width and height of the shape (in pixels).
  90. */
  91. short Width;
  92. short Height;
  93. /*
  94. ** The total number of shapes in the file.
  95. */
  96. short Count;
  97. /*
  98. ** Each shape is represented by this structure. It appears in a linear array near the
  99. ** beginning of the file.
  100. */
  101. class ShapeRecord
  102. {
  103. public:
  104. /*
  105. ** The sub-offset (relative to logical 0,0 at upper left corner) for this
  106. ** shape's data.
  107. */
  108. short X;
  109. short Y;
  110. /*
  111. ** The dimensions of this shape's data.
  112. */
  113. short Width;
  114. short Height;
  115. /*
  116. ** Flags that indicate some aspect of this particular shape image.
  117. */
  118. short Flags;
  119. enum {
  120. SFLAG_TRANSPARENT=0x01, // Are there are any transparent pixels present?
  121. SFLAG_RLE=0x02 // Is it RLE compressed?
  122. };
  123. /*
  124. ** Size of the data for this frame.
  125. */
  126. short Size;
  127. /*
  128. ** Offset from the start of the shape data file to where the first pixel
  129. ** of this shape image data is located.
  130. */
  131. long Data;
  132. bool Is_Transparent(void) const {return((Flags & SFLAG_TRANSPARENT) != 0);}
  133. bool Is_RLE_Compressed(void) const {return((Flags & SFLAG_RLE) != 0);}
  134. short Get_Size(void) const {return(Size);}
  135. void Flag_Transparent(void) {Flags |= SFLAG_TRANSPARENT;}
  136. void Flag_RLE_Compressed(void) {Flags |= SFLAG_RLE;}
  137. void Set_Size(short size) {Size = size;}
  138. };
  139. bool Is_Shape_Index_Valid(int index) const {return(unsigned(index) < unsigned(Count));}
  140. ShapeRecord const * Fetch_Record_Pointer(int shape) const
  141. {
  142. if (Is_Shape_Index_Valid(shape)) {
  143. return((ShapeRecord const *)(((char *)this) + sizeof(ShapeSet) + sizeof(ShapeRecord) * shape));
  144. }
  145. return(NULL);
  146. }
  147. /*
  148. ** Prevents a shape object from being constructed illegally.
  149. */
  150. ShapeSet(void) {};
  151. ShapeSet(ShapeSet const & rvalue);
  152. ShapeSet const & operator = (ShapeSet const & rvalue);
  153. };
  154. /***********************************************************************************************
  155. * ShapeSet::Get_Data -- Fetches pointer to raw shape data. *
  156. * *
  157. * This routine will return a pointer to the shape data. The data is actually a sub- *
  158. * rectangle within the logical shape rectangle. The sub-rectangle holds the non- *
  159. * transparent pixels. This fact, as retrieved by the Fetch_Rect function must be used *
  160. * for proper rendering of the shape. *
  161. * *
  162. * INPUT: shape -- The shape number to extract the pointer for. *
  163. * *
  164. * OUTPUT: Returns with a pointer to the raw shape data. If the shape does not exist in the *
  165. * data file, the returned value will be NULL. If the shape contains no pixels, then *
  166. * NULL is also returned. *
  167. * *
  168. * WARNINGS: none *
  169. * *
  170. * HISTORY: *
  171. * 02/26/1997 JLB : Created. *
  172. *=============================================================================================*/
  173. inline void * ShapeSet::Get_Data(int shape) const
  174. {
  175. ShapeRecord const * record = Fetch_Record_Pointer(shape);
  176. if (record != NULL && record->Data != 0) return(((char *)this) + record->Data);
  177. return(NULL);
  178. }
  179. /***********************************************************************************************
  180. * ShapeSet::Get_Rect -- Fetch the sub-rectangle of a shape. *
  181. * *
  182. * This routine will fetch the sub-rectangle for a particular shape. This rectangle is *
  183. * used to properly position the shape when rendering. *
  184. * *
  185. * INPUT: shape -- The shape number to fetch the rectangle for. *
  186. * *
  187. * OUTPUT: Returns with the rectangle of the shape number specified. *
  188. * *
  189. * WARNINGS: If the shape number is invalid or the shape has no pixels, the returned *
  190. * rectangle will not pass the Is_Valid() test. *
  191. * *
  192. * HISTORY: *
  193. * 02/26/1997 JLB : Created. *
  194. *=============================================================================================*/
  195. inline Rect ShapeSet::Get_Rect(int shape) const
  196. {
  197. ShapeRecord const * record = Fetch_Record_Pointer(shape);
  198. if (record != NULL) {
  199. return(Rect(record->X, record->Y, record->Width, record->Height));
  200. }
  201. return(Rect(0,0,0,0));
  202. }
  203. /***********************************************************************************************
  204. * ShapeSet::Is_Transparent -- Is the specified shape containing transparent pixels? *
  205. * *
  206. * This routine will check to see if the specified shape has any transparent pixels. If it *
  207. * doesn't, then faster blitting code can be used. *
  208. * *
  209. * INPUT: shape -- The shape to examine. *
  210. * *
  211. * OUTPUT: bool; Does the shape contain any transparent pixels? The answer is also false if *
  212. * the shape number is invalid. *
  213. * *
  214. * WARNINGS: none *
  215. * *
  216. * HISTORY: *
  217. * 02/26/1997 JLB : Created. *
  218. *=============================================================================================*/
  219. inline bool ShapeSet::Is_Transparent(int shape) const
  220. {
  221. ShapeRecord const * record = Fetch_Record_Pointer(shape);
  222. if (record != NULL) {
  223. return(record->Is_Transparent());
  224. }
  225. return(false);
  226. }
  227. inline bool ShapeSet::Is_RLE_Compressed(int shape) const
  228. {
  229. ShapeRecord const * record = Fetch_Record_Pointer(shape);
  230. if (record != NULL) {
  231. return(record->Is_RLE_Compressed());
  232. }
  233. return(false);
  234. }
  235. #endif