ScummVM API documentation
screen_item32.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef SCI_GRAPHICS_SCREEN_ITEM32_H
23#define SCI_GRAPHICS_SCREEN_ITEM32_H
24
25#include "common/rect.h"
26#include "sci/graphics/celobj32.h"
27#include "sci/graphics/lists32.h"
28
29namespace Sci {
30
31enum ScaleSignals32 {
32 kScaleSignalNone = 0,
33 kScaleSignalManual = 1,
34 kScaleSignalVanishingPoint = 2
35};
36
37struct ScaleInfo {
38 int x, y, max;
39 ScaleSignals32 signal;
40 ScaleInfo() : x(128), y(128), max(100), signal(kScaleSignalNone) {}
41};
42
43class CelObj;
44class Plane;
45class SegManager;
46
47#pragma mark -
48#pragma mark ScreenItem
49
54private:
59 static uint16 _nextObjectId;
60
66 static uint32 _nextCreationId;
67
68public:
73
79
80private:
86 Common::Rect _screenItemRect;
87
96 bool _useInsetRect;
97
104 Common::Rect _insetRect;
105
110 int _z;
111
116 void setFromObject(SegManager *segMan, const reg_t object, const bool updateCel, const bool updateBitmap);
117
118public:
125
130
136
143
150
156
163
168 GuiResourceId _pictureId;
169
179 int _created, _updated, _deleted;
180
190
196 Ratio _ratioX, _ratioY;
197
202
209
216
220 static void init();
221
222 ScreenItem(const reg_t screenItem);
223 ScreenItem(const reg_t plane, const CelInfo32 &celInfo);
224 ScreenItem(const reg_t plane, const CelInfo32 &celInfo, const Common::Rect &rect);
225 ScreenItem(const reg_t plane, const CelInfo32 &celInfo, const Common::Point &position, const ScaleInfo &scaleInfo);
226 ScreenItem(const ScreenItem &other);
227 void operator=(const ScreenItem &);
228
229 inline bool operator<(const ScreenItem &other) const {
230 if (_priority < other._priority) {
231 return true;
232 }
233
234 if (_priority == other._priority) {
235 if (_position.y + _z < other._position.y + other._z) {
236 return true;
237 }
238
239 if (_position.y + _z == other._position.y + other._z) {
240 // Synthetic object IDs (numeric IDs) are used for screen items
241 // generated by the kernel, like the screen items generated by
242 // plane pics. In SSCI, these synthetic IDs started at 20000 so
243 // would deterministically always sort higher than any
244 // script-generated view in SSCI at the same position and
245 // priority.
246 if (other._object.isNumber() && !_object.isNumber()) {
247 return true;
248 }
249
250 // SSCI's last resort comparison here is to compare the _object
251 // IDs, but this is wrong and randomly breaks (at least):
252 //
253 // (1) the death dialog at the end of Phant1, where the ID of
254 // the text is often higher than the ID of the border;
255 // (2) text-based buttons and dialogues in Hoyle5, where the ID
256 // of the text is often lower than the ID of the
257 // button/dialogue background.
258 //
259 // This occurs because object IDs (in both ScummVM and SSCI) are
260 // reused, so objects created later may receive a lower ID,
261 // which makes them sort lower when the programmer intended them
262 // to sort higher.
263 //
264 // To fix this problem, we give each ScreenItem a monotonically
265 // increasing insertion ID at construction time, and compare
266 // these insertion IDs instead. They are more stable and cause
267 // objects with identical priority and z-index to be rendered in
268 // the order that they were created.
269 //
270 // This also applies to ScreenItem::hasPriorityAbove.
271 return _creationId < other._creationId;
272 }
273 }
274
275 return false;
276 }
277
278 inline bool operator>(const ScreenItem &other) const {
279 if (_priority > other._priority) {
280 return true;
281 }
282
283 if (_priority == other._priority) {
284 if (_position.y + _z > other._position.y + other._z) {
285 return true;
286 }
287
288 if (_position.y + _z == other._position.y + other._z) {
289 if (_object.isNumber() && !other._object.isNumber()) {
290 return true;
291 }
292
293 // This is different than SSCI; see ScreenItem::operator< for an
294 // explanation
295 return _creationId > other._creationId;
296 }
297 }
298
299 return false;
300 }
301
302 inline bool hasPriorityAbove(const ScreenItem &other) const {
303 if (_priority > other._priority) {
304 return true;
305 }
306
307 if (_priority == other._priority) {
308 if (_object.isNumber() && !other._object.isNumber()) {
309 return true;
310 }
311
312 // This is different than SSCI; see ScreenItem::operator< for an
313 // explanation
314 return _creationId > other._creationId;
315 }
316
317 return false;
318 }
319
326 void calcRects(const Plane &plane);
327
333
334 void printDebugInfo(Console *con) const;
335
339 void update(const reg_t object);
340
345 void update();
346
352 Common::Rect getNowSeenRect(const Plane &plane) const;
353};
354
355#pragma mark -
356#pragma mark ScreenItemList
357
360private:
361 size_type _unsorted[250];
362
363public:
364 ScreenItem *findByObject(const reg_t object) const;
365 void sort();
366 void unsort();
367};
368
369} // End of namespace Sci
370
371#endif // SCI_GRAPHICS_SCREEN_ITEM32_H
Definition: rational.h:40
Definition: ptr.h:572
Definition: celobj32.h:242
Definition: console.h:36
Definition: plane32.h:103
Definition: screen_item32.h:53
void calcRects(const Plane &plane)
bool _drawBlackLines
Definition: screen_item32.h:215
Common::Point _scaledPosition
Definition: screen_item32.h:201
Common::ScopedPtr< CelObj > _celObj
Definition: screen_item32.h:135
Common::Rect getNowSeenRect(const Plane &plane) const
Ratio _ratioX
Definition: screen_item32.h:196
Common::Point _position
Definition: screen_item32.h:155
uint32 _creationId
Definition: screen_item32.h:124
int16 _priority
Definition: screen_item32.h:149
Common::Rect _screenRect
Definition: screen_item32.h:208
bool _fixedPriority
Definition: screen_item32.h:142
CelObj & getCelObj() const
GuiResourceId _pictureId
Definition: screen_item32.h:168
reg_t _plane
Definition: screen_item32.h:72
bool _mirrorX
Definition: screen_item32.h:189
int _created
Definition: screen_item32.h:179
static void init()
ScaleInfo _scale
Definition: screen_item32.h:78
void update(const reg_t object)
CelInfo32 _celInfo
Definition: screen_item32.h:129
reg_t _object
Definition: screen_item32.h:162
Definition: screen_item32.h:359
Definition: seg_manager.h:48
Definition: lists32.h:43
Definition: console.h:28
T y
Definition: rect.h:49
Definition: rect.h:144
Definition: rect.h:536
Definition: celobj32.h:64
Definition: screen_item32.h:37
Definition: vm_types.h:39