22#ifndef SCI_GRAPHICS_HELPERS_H
23#define SCI_GRAPHICS_HELPERS_H
25#include "common/endian.h"
26#include "common/rect.h"
27#include "common/serializer.h"
29#include "common/rational.h"
30#include "graphics/pixelformat.h"
31#include "graphics/surface.h"
33#include "sci/detection.h"
34#include "sci/engine/vm_types.h"
35#include "sci/graphics/helpers_detection_enums.h"
40#define MAX_CACHED_CURSORS 10
41#define MAX_CACHED_FONTS 20
42#define MAX_CACHED_VIEWS 50
49typedef int GuiResourceId;
51typedef int16 TextAlignment;
53#define PORTS_FIRSTWINDOWID 2
54#define PORTS_FIRSTSCRIPTWINDOWID 3
60 int16 curTop, curLeft;
64 int16 penClr, backClr;
66 uint16 counterTillFree;
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) {
75 bool isWindow()
const {
return id >= PORTS_FIRSTWINDOWID &&
id != 0xFFFF; }
82 uint16 saveScreenMask;
89 wndStyle(0), saveScreenMask(0),
90 hSaved1(NULL_REG), hSaved2(NULL_REG),
95 ser.syncAsSint16LE(targetRect.top);
96 ser.syncAsSint16LE(targetRect.
left);
97 ser.syncAsSint16LE(targetRect.bottom);
98 ser.syncAsSint16LE(targetRect.
right);
102 ser.syncAsUint16LE(
id);
103 ser.syncAsSint16LE(top);
104 ser.syncAsSint16LE(left);
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);
116 syncRect(ser, restoreRect);
117 ser.syncAsUint16LE(wndStyle);
118 ser.syncAsUint16LE(saveScreenMask);
119 if (ser.isLoading()) {
125 ser.syncAsByte(bDrawn);
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();
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;
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()) {
163 return result - extra;
172 point.
x = mulru(point.
x, ratioX);
173 point.
y = mulru(point.
y, ratioY);
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;
200 if (r.top < other.top) {
203 t.bottom = other.top;
207 if (r.bottom > other.bottom) {
210 t.top = other.bottom;
211 r.bottom = other.bottom;
238 bool operator==(
const Color &other)
const {
239 return used == other.used && r == other.r && g == other.g && b == other.b;
241 inline bool operator!=(
const Color &other)
const {
242 return !operator==(other);
254 bool operator==(
const Palette &other)
const {
255 for (
int i = 0; i <
ARRAYSIZE(colors); ++i) {
256 if (colors[i] != other.colors[i]) {
263 inline bool operator!=(
const Palette &other)
const {
264 return !(*
this == other);
288 const int paletteModsSize;
290 const int picModsSize;
292 const int viewModsSize;
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
#define ARRAYSIZE(x)
Definition: util.h:114
T right
Definition: rect.h:171
bool intersects(const ConcreteRect &r) const
Definition: rect.h:291
T left
Definition: rect.h:170
Definition: helpers.h:233
Definition: helpers.h:295
Definition: helpers.h:247
Definition: helpers.h:269
Definition: helpers.h:273
Definition: helpers.h:285
Definition: helpers.h:278
Definition: vm_types.h:39