aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk/view.h
blob: 463715b765cdd2eccbba23dff4c061a91c5e0458 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef MOHAWK_VIEW_H
#define MOHAWK_VIEW_H

#include "mohawk/mohawk.h"
#include "common/rect.h"

namespace Mohawk {

class GraphicsManager;

class Feature;
class View;

enum {
	kFeatureObjectMask = 0xff, // both (sort of)
	kFeatureOldSortForeground = 0x1000, // old
	kFeatureOldDropSpot = 0x2000, // old
	kFeatureOldNoClip = 0x4000, // old
	kFeatureNewSortForeground = 0x4000, // new
	kFeatureSortBackground = 0x8000, // both
	kFeatureOldReset = 0x10000, // old
	kFeatureOldDisable = 0x20000, // old
	kFeatureOldAlternateScripts = 0x40000, // old
	kFeatureOldDisableOnReset = 0x80000, // old
	kFeatureDisableOnEnd = 0x100000, // both
	kFeatureNewDisable = 0x200000, // new
	kFeatureNewDisableOnReset = 0x400000, // new
	kFeatureOldAdjustByPos = 0x800000, // old
	kFeatureNewNoLoop = 0x800000, // new
	kFeatureOldDisabled = 0x1000000, // old
	kFeatureOldRandom = 0x2000000, // old
	kFeatureNewClip = 0x2000000, // new
	kFeatureSortStatic = 0x4000000, // both
	kFeatureInternalRegion = 0x8000000, // both
	kFeatureSortCheckRight = 0x10000000, // both
	kFeatureSortCheckTop = 0x20000000, // both
	kFeatureSortCheckLeft = 0x40000000, // both
	kFeatureNewInternalTiming = 0x80000000 // new
};

class Module {
public:
	Module();
	virtual ~Module();

	virtual void init() = 0;
	virtual void shutdown() = 0;
	virtual void update() = 0;

	typedef void (Module::*HotspotProc)(uint);
	typedef void (Module::*FeatureProc)(Feature *);
	typedef bool (Module::*BooleanProc)(Feature *);
	typedef void (Module::*PickupProc)(Feature *, Common::Point, uint32, Common::Rect *);
};

// This is memcpy()ed around, beware.
#define FEATURE_BITMAP_ITEMS 48 // this is 24 in old
struct FeatureData {
	uint16 bitmapIds[FEATURE_BITMAP_ITEMS];
	Common::Point bitmapPos[FEATURE_BITMAP_ITEMS];

	uint16 unknown192; // old?

	uint16 scrbIndex;
	uint16 compoundSHAPIndex;
	uint16 endFrame; // old?
	uint16 currFrame; // old?
	uint32 currOffset;

	Common::Rect bounds;

	Common::Point currentPos;
	Common::Point nextPos;

	uint16 unknown220; // old?

	uint16 syncChannel;
	uint16 enabled;
	byte paused; // new
	byte hidden; // new

	uint16 useClipRect;
	Common::Rect clipRect;
};

class Feature {
public:
	Feature(View *view);
	virtual ~Feature();

	virtual void resetFrame() = 0;

	virtual void setNodeDefaults(Feature *prev, Feature *next);
	virtual void resetFeatureScript(uint16 enabled, uint16 scrbId);
	virtual void resetFeature(bool notifyDone, Module::FeatureProc doneProc, uint16 scrbId);

	void hide(bool clip);
	void show();

	void moveAndUpdate(Common::Point newPos);

	void defaultDraw();

	Feature *_next, *_prev;

	Module::FeatureProc _drawProc;
	Module::FeatureProc _moveProc;
	Module::FeatureProc _doneProc;
	Module::FeatureProc _frameProc;
	Module::BooleanProc _timeProc;

	uint16 _region; // TODO
	uint16 _id;
	uint16 _scrbId;
	uint16 _storedScrbId; // old
	uint32 _flags;
	uint32 _nextTime;
	uint32 _delayTime;
	bool _dirty; // byte in old
	bool _needsReset;
	bool _justReset; // old
	bool _done; // new

	FeatureData _data;

protected:
	View *_view;

	virtual void resetScript() = 0;
	virtual void finishResetFeatureScript() = 0;
};

class OldFeature : public Feature {
public:
	OldFeature(View *view);
	~OldFeature();

	void resetFrame();
	void resetFeatureScript(uint16 enabled, uint16 scrbId);

protected:
	void resetScript();
	void finishResetFeatureScript();
};

class NewFeature : public Feature {
public:
	NewFeature(View *view);
	~NewFeature();

	void resetFrame();
	void resetFeatureScript(uint16 enabled, uint16 scrbId);

	uint32 _unknown168;

	// Drag/drop variables.
	Module::PickupProc _pickupProc;
	Module::FeatureProc _dropProc;
	Module::FeatureProc _dragMoveProc;
	Module::FeatureProc _oldMoveProc;
	uint32 _dragFlags;
	uint32 _oldFlags;
	Common::Point _oldPos;
	Common::Point _posDiff;
	Common::Point _currDragPos;

protected:
	void resetScript();
	void finishResetFeatureScript();
};

class View {
public:
	View(MohawkEngine *vm);
	virtual ~View();

	virtual void idleView();

	void setModule(Module *module);
	Module *getCurrentModule() { return _currentModule; }
	GraphicsManager *getGfx() { return _gfx; }

	Common::Array<uint16> getSHPL(uint16 id);
	void installBG(uint16 id);
	void setColors(Common::SeekableReadStream *tpalStream);
	void copyFadeColors(uint start, uint count);

	uint16 getCompoundSHAPId(uint16 shapIndex);

	void installGroupOfSCRBs(bool main, uint base, uint size, uint count = 0);
	virtual void freeScripts();
	void installFeatureShapes(bool regs, uint groupId, uint16 resourceBase);
	void freeFeatureShapes();

	uint16 getGroupFromBaseId(uint16 baseId);
	void getnthScriptSetGroup(uint16 &scrbIndex, uint16 &shapIndex, uint16 scrbId);
	Common::SeekableReadStream *getSCRB(uint16 index, uint16 id = 0xffff);

	Feature *getFeaturePtr(uint16 id);
	uint16 getNewFeatureId();
	void removeFeature(Feature *feature, bool free);
	void insertUnderCursor(Feature *feature);
	Feature *pointOnFeature(bool topdown, uint32 flags, Common::Point pos);
	void sortView();

	uint32 _lastIdleTime;

	virtual uint32 getTime() = 0;

	bool _needsUpdate;

protected:
	MohawkEngine *_vm;
	GraphicsManager *_gfx;
	void setGraphicsManager(GraphicsManager *gfx) { _gfx = gfx; } // TODO
	Module *_currentModule;

	uint16 _backgroundId;

	Feature *_rootNode, *_cursorNode;

	uint16 _numSCRBGroups;
	uint16 _SCRBGroupBases[14];
	uint16 _SCRBGroupSizes[14];
	Common::Array<uint16> _SCRBEntries;
	//uint16 _numCompoundSHAPGroups;
	uint16 _compoundSHAPGroups[14];

	Feature *sortOneList(Feature *root);
	Feature *mergeLists(Feature *root, Feature *mergeRoot);

	virtual void finishDraw() { }
};

} // End of namespace Mohawk

#endif