ScummVM API documentation
helpers.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_HELPERS_H
23#define SCI_GRAPHICS_HELPERS_H
24
25#include "common/endian.h" // for READ_LE_UINT16
26#include "common/rect.h"
27#include "common/serializer.h"
28#ifdef ENABLE_SCI32
29#include "common/rational.h"
30#include "graphics/pixelformat.h"
31#include "graphics/surface.h"
32#endif
33#include "sci/detection.h"
34#include "sci/engine/vm_types.h"
35#include "sci/graphics/helpers_detection_enums.h" // for enum ViewType
36
37namespace Sci {
38
39// Cache limits
40#define MAX_CACHED_CURSORS 10
41#define MAX_CACHED_FONTS 20
42#define MAX_CACHED_VIEWS 50
43
44enum ShakeDirection {
45 kShakeVertical = 1,
46 kShakeHorizontal = 2
47};
48
49typedef int GuiResourceId; // is a resource-number and -1 means no parameter given
50
51typedef int16 TextAlignment;
52
53#define PORTS_FIRSTWINDOWID 2
54#define PORTS_FIRSTSCRIPTWINDOWID 3
55
56struct Port {
57 uint16 id;
58 int16 top, left;
59 Common::Rect rect;
60 int16 curTop, curLeft;
61 int16 fontHeight;
62 GuiResourceId fontId;
63 bool greyedOutput;
64 int16 penClr, backClr;
65 int16 penMode;
66 uint16 counterTillFree;
67
68 Port(uint16 theId) : id(theId), top(0), left(0),
69 curTop(0), curLeft(0),
70 fontHeight(0), fontId(0), greyedOutput(false),
71 penClr(0), backClr(0xFF), penMode(0), counterTillFree(0) {
72 }
73 virtual ~Port() {}
74
75 bool isWindow() const { return id >= PORTS_FIRSTWINDOWID && id != 0xFFFF; }
76};
77
78struct Window : public Port, public Common::Serializable {
79 Common::Rect dims; // client area of window
80 Common::Rect restoreRect; // total area of window including borders
81 uint16 wndStyle;
82 uint16 saveScreenMask;
83 reg_t hSaved1;
84 reg_t hSaved2;
85 Common::String title;
86 bool bDrawn;
87
88 Window(uint16 theId) : Port(theId),
89 wndStyle(0), saveScreenMask(0),
90 hSaved1(NULL_REG), hSaved2(NULL_REG),
91 bDrawn(false) {
92 }
93
94 void syncRect(Common::Serializer &ser, Common::Rect &targetRect) {
95 ser.syncAsSint16LE(targetRect.top);
96 ser.syncAsSint16LE(targetRect.left);
97 ser.syncAsSint16LE(targetRect.bottom);
98 ser.syncAsSint16LE(targetRect.right);
99 }
100
101 void saveLoadWithSerializer(Common::Serializer &ser) override {
102 ser.syncAsUint16LE(id);
103 ser.syncAsSint16LE(top);
104 ser.syncAsSint16LE(left);
105 syncRect(ser, rect);
106 ser.syncAsSint16LE(curTop);
107 ser.syncAsSint16LE(curLeft);
108 ser.syncAsSint16LE(fontHeight);
109 ser.syncAsSint32LE(fontId);
110 ser.syncAsByte(greyedOutput);
111 ser.syncAsSint16LE(penClr);
112 ser.syncAsSint16LE(backClr);
113 ser.syncAsSint16LE(penMode);
114 ser.syncAsUint16LE(counterTillFree);
115 syncRect(ser, dims);
116 syncRect(ser, restoreRect);
117 ser.syncAsUint16LE(wndStyle);
118 ser.syncAsUint16LE(saveScreenMask);
119 if (ser.isLoading()) {
120 // The hunk table isn't saved, so we just set both pointers to NULL
121 hSaved1 = NULL_REG;
122 hSaved2 = NULL_REG;
123 }
124 ser.syncString(title);
125 ser.syncAsByte(bDrawn);
126 }
127};
128
129#ifdef ENABLE_SCI32
134inline void mul(Common::Rect &rect, const Common::Rational &ratioX, const Common::Rational &ratioY) {
135 rect.left = (rect.left * ratioX).toInt();
136 rect.top = (rect.top * ratioY).toInt();
137 rect.right = (rect.right * ratioX).toInt();
138 rect.bottom = (rect.bottom * ratioY).toInt();
139}
140
146inline void mulinc(Common::Rect &rect, const Common::Rational &ratioX, const Common::Rational &ratioY) {
147 rect.left = (rect.left * ratioX).toInt();
148 rect.top = (rect.top * ratioY).toInt();
149 rect.right = ((rect.right - 1) * ratioX).toInt() + 1;
150 rect.bottom = ((rect.bottom - 1) * ratioY).toInt() + 1;
151}
152
157inline int mulru(const int value, const Common::Rational &ratio, const int extra = 0) {
158 int num = (value + extra) * ratio.getNumerator();
159 int result = num / ratio.getDenominator();
160 if (num > ratio.getDenominator() && num % ratio.getDenominator()) {
161 ++result;
162 }
163 return result - extra;
164}
165
171inline void mulru(Common::Point &point, const Common::Rational &ratioX, const Common::Rational &ratioY) {
172 point.x = mulru(point.x, ratioX);
173 point.y = mulru(point.y, ratioY);
174}
175
181inline void mulru(Common::Rect &rect, const Common::Rational &ratioX, const Common::Rational &ratioY, const int extra) {
182 rect.left = mulru(rect.left, ratioX);
183 rect.top = mulru(rect.top, ratioY);
184 rect.right = mulru(rect.right - 1, ratioX, extra) + 1;
185 rect.bottom = mulru(rect.bottom - 1, ratioY, extra) + 1;
186}
187
194inline int splitRects(Common::Rect r, const Common::Rect &other, Common::Rect(&outRects)[4]) {
195 if (!r.intersects(other)) {
196 return -1;
197 }
198
199 int splitCount = 0;
200 if (r.top < other.top) {
201 Common::Rect &t = outRects[splitCount++];
202 t = r;
203 t.bottom = other.top;
204 r.top = other.top;
205 }
206
207 if (r.bottom > other.bottom) {
208 Common::Rect &t = outRects[splitCount++];
209 t = r;
210 t.top = other.bottom;
211 r.bottom = other.bottom;
212 }
213
214 if (r.left < other.left) {
215 Common::Rect &t = outRects[splitCount++];
216 t = r;
217 t.right = other.left;
218 r.left = other.left;
219 }
220
221 if (r.right > other.right) {
222 Common::Rect &t = outRects[splitCount++];
223 t = r;
224 t.left = other.right;
225 }
226
227 return splitCount;
228}
229
231#endif
232
233struct Color {
234 byte used;
235 byte r, g, b;
236
237#ifdef ENABLE_SCI32
238 bool operator==(const Color &other) const {
239 return used == other.used && r == other.r && g == other.g && b == other.b;
240 }
241 inline bool operator!=(const Color &other) const {
242 return !operator==(other);
243 }
244#endif
245};
246
247struct Palette {
248 byte mapping[256];
249 uint32 timestamp;
250 Color colors[256];
251 byte intensity[256];
252
253#ifdef ENABLE_SCI32
254 bool operator==(const Palette &other) const {
255 for (int i = 0; i < ARRAYSIZE(colors); ++i) {
256 if (colors[i] != other.colors[i]) {
257 return false;
258 }
259 }
260
261 return true;
262 }
263 inline bool operator!=(const Palette &other) const {
264 return !(*this == other);
265 }
266#endif
267};
268
270 int8 r, g, b;
271};
272
273struct PicMod {
274 uint16 id;
275 byte multiplier;
276};
277
278struct ViewMod {
279 uint16 id;
280 int16 loop;
281 int16 cel;
282 byte multiplier;
283};
284
285struct SciFxMod {
286 SciGameId gameId;
287 const PaletteMod *paletteMods;
288 const int paletteModsSize;
289 const PicMod *picMods;
290 const int picModsSize;
291 const ViewMod *viewMods;
292 const int viewModsSize;
293};
294
296 byte from;
297 uint32 schedule;
298};
299
300} // End of namespace Sci
301
302#endif // SCI_GRAPHICS_HELPERS_H
Definition: display_client.h:113
Definition: rational.h:40
Definition: serializer.h:352
Definition: serializer.h:80
void syncString(String &str, Version minVersion=0, Version maxVersion=kLastVersion)
Definition: serializer.h:249
Definition: str.h:59
#define ARRAYSIZE(x)
Definition: util.h:114
Definition: console.h:28
T y
Definition: rect.h:49
T x
Definition: rect.h:48
Definition: rect.h:144
T right
Definition: rect.h:171
bool intersects(const ConcreteRect &r) const
Definition: rect.h:291
T left
Definition: rect.h:170
Definition: rect.h:536
Definition: surface.h:67
Definition: helpers.h:233
Definition: helpers.h:295
Definition: helpers.h:247
Definition: helpers.h:269
Definition: helpers.h:273
Definition: helpers.h:56
Definition: helpers.h:285
Definition: helpers.h:278
Definition: helpers.h:78
Definition: vm_types.h:39