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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef MOHAWK_VIEW_H
24 #define MOHAWK_VIEW_H
25 
26 #include "mohawk/mohawk.h"
27 #include "common/rect.h"
28 
29 namespace Mohawk {
30 
31 class GraphicsManager;
32 
33 class Feature;
34 class View;
35 
36 enum {
37 	kFeatureObjectMask = 0xff, // both (sort of)
38 	kFeatureOldSortForeground = 0x1000, // old
39 	kFeatureOldDropSpot = 0x2000, // old
40 	kFeatureOldNoClip = 0x4000, // old
41 	kFeatureNewSortForeground = 0x4000, // new
42 	kFeatureSortBackground = 0x8000, // both
43 	kFeatureOldReset = 0x10000, // old
44 	kFeatureOldDisable = 0x20000, // old
45 	kFeatureOldAlternateScripts = 0x40000, // old
46 	kFeatureOldDisableOnReset = 0x80000, // old
47 	kFeatureDisableOnEnd = 0x100000, // both
48 	kFeatureNewDisable = 0x200000, // new
49 	kFeatureNewDisableOnReset = 0x400000, // new
50 	kFeatureOldAdjustByPos = 0x800000, // old
51 	kFeatureNewNoLoop = 0x800000, // new
52 	kFeatureOldDisabled = 0x1000000, // old
53 	kFeatureOldRandom = 0x2000000, // old
54 	kFeatureNewClip = 0x2000000, // new
55 	kFeatureSortStatic = 0x4000000, // both
56 	kFeatureInternalRegion = 0x8000000, // both
57 	kFeatureSortCheckRight = 0x10000000, // both
58 	kFeatureSortCheckTop = 0x20000000, // both
59 	kFeatureSortCheckLeft = 0x40000000, // both
60 	kFeatureNewInternalTiming = 0x80000000 // new
61 };
62 
63 class Module {
64 public:
65 	Module();
66 	virtual ~Module();
67 
68 	virtual void init() = 0;
69 	virtual void shutdown() = 0;
70 	virtual void update() = 0;
71 
72 	typedef void (Module::*HotspotProc)(uint);
73 	typedef void (Module::*FeatureProc)(Feature *);
74 	typedef bool (Module::*BooleanProc)(Feature *);
75 	typedef void (Module::*PickupProc)(Feature *, Common::Point, uint32, Common::Rect *);
76 };
77 
78 // This is memcpy()ed around, beware.
79 #define FEATURE_BITMAP_ITEMS 48 // this is 24 in old
80 struct FeatureData {
81 	uint16 bitmapIds[FEATURE_BITMAP_ITEMS];
82 	Common::Point bitmapPos[FEATURE_BITMAP_ITEMS];
83 
84 	uint16 unknown192; // old?
85 
86 	uint16 scrbIndex;
87 	uint16 compoundSHAPIndex;
88 	uint16 endFrame; // old?
89 	uint16 currFrame; // old?
90 	uint32 currOffset;
91 
92 	Common::Rect bounds;
93 
94 	Common::Point currentPos;
95 	Common::Point nextPos;
96 
97 	uint16 unknown220; // old?
98 
99 	uint16 syncChannel;
100 	uint16 enabled;
101 	byte paused; // new
102 	byte hidden; // new
103 
104 	uint16 useClipRect;
105 	Common::Rect clipRect;
106 };
107 
108 class Feature {
109 public:
110 	Feature(View *view);
111 	virtual ~Feature();
112 
113 	virtual void resetFrame() = 0;
114 
115 	virtual void setNodeDefaults(Feature *prev, Feature *next);
116 	virtual void resetFeatureScript(uint16 enabled, uint16 scrbId);
117 	virtual void resetFeature(bool notifyDone, Module::FeatureProc doneProc, uint16 scrbId);
118 
119 	void hide(bool clip);
120 	void show();
121 
122 	void moveAndUpdate(Common::Point newPos);
123 
124 	void defaultDraw();
125 
126 	Feature *_next, *_prev;
127 
128 	Module::FeatureProc _drawProc;
129 	Module::FeatureProc _moveProc;
130 	Module::FeatureProc _doneProc;
131 	Module::FeatureProc _frameProc;
132 	Module::BooleanProc _timeProc;
133 
134 	uint16 _region; // TODO
135 	uint16 _id;
136 	uint16 _scrbId;
137 	uint16 _storedScrbId; // old
138 	uint32 _flags;
139 	uint32 _nextTime;
140 	uint32 _delayTime;
141 	bool _dirty; // byte in old
142 	bool _needsReset;
143 	bool _justReset; // old
144 	bool _done; // new
145 
146 	FeatureData _data;
147 
148 protected:
149 	View *_view;
150 
151 	virtual void resetScript() = 0;
152 	virtual void finishResetFeatureScript() = 0;
153 };
154 
155 class OldFeature : public Feature {
156 public:
157 	OldFeature(View *view);
158 	~OldFeature();
159 
160 	void resetFrame();
161 	void resetFeatureScript(uint16 enabled, uint16 scrbId);
162 
163 protected:
164 	void resetScript();
165 	void finishResetFeatureScript();
166 };
167 
168 class NewFeature : public Feature {
169 public:
170 	NewFeature(View *view);
171 	~NewFeature();
172 
173 	void resetFrame();
174 	void resetFeatureScript(uint16 enabled, uint16 scrbId);
175 
176 	uint32 _unknown168;
177 
178 	// Drag/drop variables.
179 	Module::PickupProc _pickupProc;
180 	Module::FeatureProc _dropProc;
181 	Module::FeatureProc _dragMoveProc;
182 	Module::FeatureProc _oldMoveProc;
183 	uint32 _dragFlags;
184 	uint32 _oldFlags;
185 	Common::Point _oldPos;
186 	Common::Point _posDiff;
187 	Common::Point _currDragPos;
188 
189 protected:
190 	void resetScript();
191 	void finishResetFeatureScript();
192 };
193 
194 class View {
195 public:
196 	View(MohawkEngine *vm);
197 	virtual ~View();
198 
199 	virtual void idleView();
200 
201 	void setModule(Module *module);
getCurrentModule()202 	Module *getCurrentModule() { return _currentModule; }
getGfx()203 	GraphicsManager *getGfx() { return _gfx; }
204 
205 	Common::Array<uint16> getSHPL(uint16 id);
206 	void installBG(uint16 id);
207 	void setColors(Common::SeekableReadStream *tpalStream);
208 	void copyFadeColors(uint start, uint count);
209 
210 	uint16 getCompoundSHAPId(uint16 shapIndex);
211 
212 	void installGroupOfSCRBs(bool main, uint base, uint size, uint count = 0);
213 	virtual void freeScripts();
214 	void installFeatureShapes(bool regs, uint groupId, uint16 resourceBase);
215 	void freeFeatureShapes();
216 
217 	uint16 getGroupFromBaseId(uint16 baseId);
218 	void getnthScriptSetGroup(uint16 &scrbIndex, uint16 &shapIndex, uint16 scrbId);
219 	Common::SeekableReadStream *getSCRB(uint16 index, uint16 id = 0xffff);
220 
221 	Feature *getFeaturePtr(uint16 id);
222 	uint16 getNewFeatureId();
223 	void removeFeature(Feature *feature, bool free);
224 	void insertUnderCursor(Feature *feature);
225 	Feature *pointOnFeature(bool topdown, uint32 flags, Common::Point pos);
226 	void sortView();
227 
228 	uint32 _lastIdleTime;
229 
230 	virtual uint32 getTime() = 0;
231 
232 	bool _needsUpdate;
233 
234 protected:
235 	MohawkEngine *_vm;
236 	GraphicsManager *_gfx;
setGraphicsManager(GraphicsManager * gfx)237 	void setGraphicsManager(GraphicsManager *gfx) { _gfx = gfx; } // TODO
238 	Module *_currentModule;
239 
240 	uint16 _backgroundId;
241 
242 	Feature *_rootNode, *_cursorNode;
243 
244 	uint16 _numSCRBGroups;
245 	uint16 _SCRBGroupBases[14];
246 	uint16 _SCRBGroupSizes[14];
247 	Common::Array<uint16> _SCRBEntries;
248 	//uint16 _numCompoundSHAPGroups;
249 	uint16 _compoundSHAPGroups[14];
250 
251 	Feature *sortOneList(Feature *root);
252 	Feature *mergeLists(Feature *root, Feature *mergeRoot);
253 
finishDraw()254 	virtual void finishDraw() { }
255 };
256 
257 } // End of namespace Mohawk
258 
259 #endif
260