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 
35 namespace Gob {
36 
37 class Font;
38 class Script;
39 
40 class Hotspots {
41 public:
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 
69  Hotspots(GobEngine *vm);
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 
107  void oPlaytoons_F_1B();
108 
109 private:
110  struct Hotspot {
111  uint16 id;
112  uint16 left;
113  uint16 top;
114  uint16 right;
115  uint16 bottom;
116  uint16 flags;
117  uint16 key;
118  uint16 funcEnter;
119  uint16 funcLeave;
120  uint16 funcPos;
121  Script *script;
122 
123  Hotspot();
124  Hotspot(uint16 i,
125  uint16 l, uint16 t, uint16 r, uint16 b, uint16 f, uint16 k,
126  uint16 enter, uint16 leave, uint16 pos);
127 
128  void clear();
129 
130  Type getType () const;
131  MouseButtons getButton() const;
132  uint16 getWindow() const;
133  uint8 getCursor() const;
134  uint8 getState () const;
135 
137  bool isEnd() const;
138 
139  bool isInput () const;
140  bool isActiveInput() const;
141  bool isInputLeave () const;
142 
143  bool isFilled () const;
144  bool isFilledEnabled() const;
145  bool isFilledNew () const;
146  bool isDisabled () const;
147 
149  bool isIn(uint16 x, uint16 y) const;
151  bool buttonMatch(MouseButtons button) const;
152 
153  static uint8 getState(uint16 id);
154 
155  void disable();
156  void enable ();
157  };
158 
159  struct StackEntry {
160  bool shouldPush;
161  Hotspot *hotspots;
162  uint32 size;
163  uint32 key;
164  uint32 id;
165  uint32 index;
166  uint16 x;
167  uint16 y;
168  };
169 
170  struct InputDesc {
171  uint16 fontIndex;
172  uint16 backColor;
173  uint16 frontColor;
174  uint16 length;
175  const char *str;
176  };
177 
178  GobEngine *_vm;
179 
180  Hotspot *_hotspots;
182 
183  bool _shouldPush;
184 
185  uint16 _currentKey;
186  uint16 _currentIndex;
187  uint16 _currentId;
188  uint16 _currentX;
189  uint16 _currentY;
190 
192  uint16 add(const Hotspot &hotspot);
193 
198  void recalculate(bool force);
199 
201  bool isValid(uint16 key, uint16 id, uint16 index) const;
202 
204  void call(uint16 offset);
206  void enter(uint16 index);
208  void leave(uint16 index);
209 
211  int16 windowCursor(int16 &dx, int16 &dy) const;
212 
214  uint16 checkMouse(Type type, uint16 &id, uint16 &index) const;
215 
217  bool checkHotspotChanged();
218 
220  uint16 updateInput(uint16 xPos, uint16 yPos, uint16 width, uint16 height,
221  uint16 backColor, uint16 frontColor, char *str, uint16 fontIndex,
222  Type type, int16 &duration, uint16 &id, uint16 &index);
223 
225  uint16 handleInputs(int16 time, uint16 inputCount, uint16 &curInput,
226  InputDesc *inputs, uint16 &id, uint16 &index);
227 
229  void evaluateNew(uint16 i, uint16 *ids, InputDesc *inputs,
230  uint16 &inputId, bool &hasInput, uint16 &inputCount);
232  bool evaluateFind(uint16 key, int16 timeVal, const uint16 *ids,
233  uint16 leaveWindowIndex, uint16 hotspotIndex1, uint16 hotspotIndex2,
234  uint16 endIndex, int16 &duration, uint16 &id, uint16 &index, bool &finished);
235 
236  // Finding specific hotspots
238  uint16 inputToHotspot(uint16 input) const;
240  uint16 hotspotToInput(uint16 hotspot) const;
242  uint16 findClickedInput(uint16 index) const;
244  bool findFirstInputLeave(uint16 &id, uint16 &inputId, uint16 &index) const;
246  bool findKey(uint16 key, uint16 &id, uint16 &index) const;
248  bool findKeyCaseInsensitive(uint16 key, uint16 &id, uint16 &index) const;
250  bool findNthPlain(uint16 n, uint16 startIndex, uint16 &id, uint16 &index) const;
251 
253  bool leaveNthPlain(uint16 n, uint16 startIndex, int16 timeVal, const uint16 *ids,
254  uint16 &id, uint16 &index, int16 &duration);
255 
256  // Hotspot ID variable access
257  void setCurrentHotspot(const uint16 *ids, uint16 id) const;
258  uint32 getCurrentHotspot() const;
259 
260  // String input functions
261  void cleanFloatString(const Hotspot &spot) const;
262  void checkStringMatch(const Hotspot &spot, const InputDesc &input,
263  uint16 inputPos) const;
264  void matchInputStrings(const InputDesc *inputs) const;
265 
266  uint16 convertSpecialKey(uint16 key) const;
267 
269  void getTextCursorPos(const Font &font, const char *str,
270  uint32 pos, uint16 x, uint16 y, uint16 width, uint16 height,
271  uint16 &cursorX, uint16 &cursorY, uint16 &cursorWidth, uint16 &cursorHeight) const;
272 
274  void fillRect(uint16 x, uint16 y, uint16 width, uint16 height, uint16 color) const;
276  void printText(uint16 x, uint16 y, const char *str, uint16 fontIndex, uint16 color) const;
277 
279  void updateAllTexts(const InputDesc *inputs) const;
280 };
281 
282 } // End of namespace Gob
283 
284 #endif // GOB_HOTSPOTS_H
void removeState(uint8 state)
uint16 add(uint16 id, uint16 left, uint16 top, uint16 right, uint16 bottom, uint16 flags, uint16 key, uint16 funcEnter, uint16 funcLeave, uint16 funcPos)
Definition: gob.h:163
Definition: script.h:41
Definition: video.h:40
void oPlaytoons_F_1B()
void push(uint8 all, bool force=false)
int16 findCursor(uint16 x, uint16 y) const
Definition: anifile.h:40
uint16 check(uint8 handleMouse, int16 delay, uint16 &id, uint16 &index)
Definition: hotspots.h:40