ScummVM API documentation
hotspots.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 * This file is dual-licensed.
22 * In addition to the GPLv3 license mentioned above, this code is also
23 * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24 * full text of the license.
25 *
26 */
27
28#ifndef GOB_HOTSPOTS_H
29#define GOB_HOTSPOTS_H
30
31#include "common/stack.h"
32
33#include "gob/util.h"
34
35namespace Gob {
36
37class Font;
38class Script;
39
40class Hotspots {
41public:
42 static const int kHotspotCount = 250;
43
44 enum Type {
45 kTypeNone = 0,
46 kTypeMove = 1,
47 kTypeClick = 2,
48 kTypeInput1NoLeave = 3,
49 kTypeInput1Leave = 4,
50 kTypeInput2NoLeave = 5,
51 kTypeInput2Leave = 6,
52 kTypeInput3NoLeave = 7,
53 kTypeInput3Leave = 8,
54 kTypeInputFloatNoLeave = 9,
55 kTypeInputFloatLeave = 10,
56 kTypeEnable2 = 11,
57 kTypeEnable1 = 12,
58 kTypeClickEnter = 21
59 };
60
61 enum State {
62 kStateFilledDisabled = 0xC,
63 kStateFilled = 0x8,
64 kStateDisabled = 0x4,
65 kStateType2 = 0x2,
66 kStateType1 = 0x1
67 };
68
70 ~Hotspots();
71
73 void clear();
74
76 uint16 add(uint16 id,
77 uint16 left, uint16 top, uint16 right, uint16 bottom,
78 uint16 flags, uint16 key,
79 uint16 funcEnter, uint16 funcLeave, uint16 funcPos);
80
82 void remove(uint16 id);
84 void removeState(uint8 state);
85
91 void push(uint8 all, bool force = false);
93 void pop();
94
96 uint16 check(uint8 handleMouse, int16 delay, uint16 &id, uint16 &index);
98 uint16 check(uint8 handleMouse, int16 delay);
99
101 void evaluate();
102
104 int16 findCursor(uint16 x, uint16 y) const;
105
108
109#ifdef USE_TTS
110 bool hoveringOverHotspot() const;
111 void addHotspotTTSText(const Common::String &text, uint16 x1, uint16 y1, uint16 x2, uint16 y2, int16 surf);
112 void voiceUnassignedHotspots();
113 void voiceHotspotTTSText(int16 x, int16 y);
114 void clearHotspotTTSText();
115 void clearUnassignedHotspotTTSText();
116 void clearPreviousSaid();
117 void adjustHotspotTTSTextRect(int16 oldLeft, int16 oldTop, int16 oldRight, int16 oldBottom, int16 newX, int16 newY, int16 surf);
118#endif
119
120private:
121 struct Hotspot {
122 uint16 id;
123 uint16 left;
124 uint16 top;
125 uint16 right;
126 uint16 bottom;
127 uint16 flags;
128 uint16 key;
129 uint16 funcEnter;
130 uint16 funcLeave;
131 uint16 funcPos;
132 Script *scriptFuncLeave;
133 Script *scriptFuncPos;
134
135 Hotspot();
136 Hotspot(uint16 i,
137 uint16 l, uint16 t, uint16 r, uint16 b, uint16 f, uint16 k,
138 uint16 enter, uint16 leave, uint16 pos);
139
140 void clear();
141
142 Type getType () const;
143 MouseButtons getButton() const;
144 uint16 getWindow() const;
145 uint8 getCursor() const;
146 uint8 getState () const;
147
149 bool isEnd() const;
150
151 bool isInput () const;
152 bool isActiveInput() const;
153 bool isInputLeave () const;
154
155 bool isFilled () const;
156 bool isFilledEnabled() const;
157 bool isFilledNew () const;
158 bool isDisabled () const;
159
161 bool isIn(uint16 x, uint16 y) const;
163 bool buttonMatch(MouseButtons button) const;
164
165 static uint8 getState(uint16 id);
166
167 void disable();
168 void enable ();
169 };
170
171#ifdef USE_TTS
172 struct HotspotTTSText {
173 Common::String str;
174 Common::Rect rect;
175 int16 hotspot;
176 bool voiced;
177 int16 surf;
178 };
179#endif
180
181 struct StackEntry {
182 bool shouldPush;
183 Hotspot *hotspots;
184 uint32 size;
185 uint32 key;
186 uint32 id;
187 uint32 index;
188 uint16 x;
189 uint16 y;
190 };
191
192 struct InputDesc {
193 uint16 fontIndex;
194 uint16 backColor;
195 uint16 frontColor;
196 uint16 length;
197 const char *str;
198 };
199
200 GobEngine *_vm;
201
202 Hotspot *_hotspots;
204
205 bool _shouldPush;
206
207 uint16 _currentKey;
208 uint16 _currentIndex;
209 uint16 _currentId;
210 uint16 _currentX;
211 uint16 _currentY;
212
213#ifdef USE_TTS
214 Common::String _previousSaid;
215 bool _hotspotSpokenLast;
216 Common::Array<HotspotTTSText> _hotspotTTSText;
217 int16 _currentHotspotTTSTextIndex;
218#endif
219
221 uint16 add(const Hotspot &hotspot);
222
227 void recalculate(bool force);
228
230 bool isValid(uint16 key, uint16 id, uint16 index) const;
231
233 void call(uint16 offset);
235 void enter(uint16 index);
237 void leave(uint16 index);
238
240 int16 windowCursor(int16 &dx, int16 &dy) const;
241
243 uint16 checkMouse(Type type, uint16 &id, uint16 &index) const;
244
246 bool checkHotspotChanged();
247
249 uint16 updateInput(uint16 xPos, uint16 yPos, uint16 width, uint16 height,
250 uint16 backColor, uint16 frontColor, char *str, uint16 fontIndex,
251 Type type, int16 &duration, uint16 &id, uint16 &index);
252
254 uint16 handleInputs(int16 time, uint16 inputCount, uint16 &curInput,
255 InputDesc *inputs, uint16 &id, uint16 &index);
256
258 void evaluateNew(uint16 i, uint16 *ids, InputDesc *inputs,
259 uint16 &inputId, bool &hasInput, uint16 &inputCount);
261 bool evaluateFind(uint16 key, int16 timeVal, const uint16 *ids,
262 uint16 leaveWindowIndex, uint16 hotspotIndex1, uint16 hotspotIndex2,
263 uint16 endIndex, int16 &duration, uint16 &id, uint16 &index, bool &finished);
264
265 // Finding specific hotspots
267 uint16 inputToHotspot(uint16 input) const;
269 uint16 hotspotToInput(uint16 hotspot) const;
271 uint16 findClickedInput(uint16 index) const;
273 bool findFirstInputLeave(uint16 &id, uint16 &inputId, uint16 &index) const;
275 bool findKey(uint16 key, uint16 &id, uint16 &index) const;
277 bool findKeyCaseInsensitive(uint16 key, uint16 &id, uint16 &index) const;
279 bool findNthPlain(uint16 n, uint16 startIndex, uint16 &id, uint16 &index) const;
280
282 bool leaveNthPlain(uint16 n, uint16 startIndex, int16 timeVal, const uint16 *ids,
283 uint16 &id, uint16 &index, int16 &duration);
284
285 // Hotspot ID variable access
286 void setCurrentHotspot(const uint16 *ids, uint16 id) const;
287 uint32 getCurrentHotspot() const;
288
289 // String input functions
290 void cleanFloatString(const Hotspot &spot) const;
291 void checkStringMatch(const Hotspot &spot, const InputDesc &input,
292 uint16 inputPos) const;
293 void matchInputStrings(const InputDesc *inputs) const;
294
295 uint16 convertSpecialKey(uint16 key) const;
296
298 void getTextCursorPos(const Font &font, const char *str,
299 uint32 pos, uint16 x, uint16 y, uint16 width, uint16 height,
300 uint16 &cursorX, uint16 &cursorY, uint16 &cursorWidth, uint16 &cursorHeight) const;
301
303 void fillRect(uint16 x, uint16 y, uint16 width, uint16 height, uint16 color) const;
305 void printText(uint16 x, uint16 y, const char *str, uint16 fontIndex, uint16 color) const;
306
308 void updateAllTexts(const InputDesc *inputs) const;
309
310#ifdef USE_TTS
311 void expandHotspotTTSText(uint16 spotID);
312 void removeHotspotTTSText(uint16 spotID);
313#endif
314};
315
316} // End of namespace Gob
317
318#endif // GOB_HOTSPOTS_H
Definition: str.h:59
Definition: gob.h:166
Definition: hotspots.h:40
void remove(uint16 id)
void removeState(uint8 state)
uint16 check(uint8 handleMouse, int16 delay)
uint16 add(uint16 id, uint16 left, uint16 top, uint16 right, uint16 bottom, uint16 flags, uint16 key, uint16 funcEnter, uint16 funcLeave, uint16 funcPos)
int16 findCursor(uint16 x, uint16 y) const
uint16 check(uint8 handleMouse, int16 delay, uint16 &id, uint16 &index)
void push(uint8 all, bool force=false)
void createButton()
Definition: script.h:41
Definition: rect.h:536