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