ScummVM API documentation
cursor.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
22#ifndef NANCY_CURSOR_H
23#define NANCY_CURSOR_H
24
25#include "common/array.h"
26#include "common/ptr.h"
27#include "common/stream.h"
28
29#include "graphics/managed_surface.h"
30
31#include "engines/nancy/enginedata.h"
32
33namespace Nancy {
34
36
37public:
38 enum CursorType {
39 kNormal = 0, // Eyeglass (except in TVD), non-highlighted
40 kHotspot = 1, // Eyeglass (except in TVD), highlighted
41 kMove = 2, // Used for movement in early games
42 kExit = 3, // Used for movement, some games use it for exiting puzzles
43 kRotateCW = 4, // Used in puzzles only
44 kRotateCCW = 5, // Used in puzzles only
45 kMoveLeft = 6, // Used for movement, some games used it for turning in 360 scenes
46 kMoveRight = 7, // Used for movement, some games used it for turning in 360 scenes
47 kMoveForward = 8, // Used for movement
48 kMoveBackward = 9, // Used for movement, some games use it for exiting puzzles
49 kMoveUp = 10, // Used for movement
50 kMoveDown = 11, // Used for movement
51 kRotateLeft = 12, // Used in 360 scenes in nancy6 and up
52 kRotateRight = 13, // Used in 360 scenes in nancy6 and up
53 kInvertedRotateRight = 14, // Used in 360 scenes with inverted rotation; nancy6 and up
54 kInvertedRotateLeft = 15, // Used in 360 scenes with inverted rotation; nancy6 and up
55 kCustom1 = 16, // Custom cursors change between games; Likely used in puzzles
56 kCustom1Hotspot = 17,
57 kCustom2 = 18,
58 kCustom2Hotspot = 19,
59 kNormalArrow = 20,
60 kHotspotArrow = 21,
61 kHotspotTalk = 22, // Speech-bubble hover cursor (Nancy 10+)
62 kDragHand = 23, // Hand cursor used when dragging an item (Nancy 10+)
63 kDropHand = 24, // Drop-hand cursor used while a piece is held over a target (Nancy 10+)
64 kPuzzleArrow = 25, // Puzzle arrow cursor shown when hovering a clickable puzzle hotspot (Nancy 10+)
65 kDialCW = 26, // Dial turn cursors used by SafeDialPuzzle (Nancy 10+); the older
66 kDialCCW = 27, // games use kRotateCW / kRotateCCW instead
67
68 // Cursors in Nancy10 and newer games. The CURS chunk holds 37 system
69 // cursor types in pairs; type T's idle slot is (T*2) and its hotspot
70 // slot is (T*2 + 1). Types 0–4 and 18–26 have visually distinct idle
71 // vs. hotspot sprites; types 5–17 and 27–36 use the same sprite for
72 // both. Types 18+ are Nancy 10-specific puzzle/inventory cursors.
73 kNewNormal = 0, // Type 0 — Eyeglass
74 kNewHotspot = 1, // Type 0 hotspot — Eyeglass highlighted
75 kNewUse = 2, // Type 1 — Open-hand "use" cursor (interact with characters/objects)
76 kNewHotspotUse = 3, // Type 1 hotspot
77 kNewLockedUse = 4, // Type 2 — Locked variant of the use hand
78 kNewHotspotLockedUse = 5, // Type 2 hotspot
79 kNewTalk = 6, // Type 3 — Speech-bubble (talking to characters)
80 kNewHotspotTalk = 7, // Type 3 hotspot
81 kNewNormalArrow = 8, // Type 4 — Taskbar arrow
82 kNewHotspotArrow = 9, // Type 4 hotspot
83 kNewExit = 10, // Type 5 — Exit / back movement
84 kNewMoveLeft = 12, // Type 6 — Movement / 360 turn
85 kNewMoveRight = 14, // Type 7 — Movement / 360 turn
86 kNewMoveForward = 16, // Type 8 — Movement
87 kNewMoveBackward = 18, // Type 9 — Movement / exit puzzles
88 kNewMoveUp = 20, // Type 10 — Movement
89 kNewMoveDown = 22, // Type 11 — Movement
90 kNewRotateCW = 24, // Type 12 — Puzzle rotation
91 kNewRotateCCW = 26, // Type 13 — Puzzle rotation
92 kNewRotateRight = 28, // Type 14 — 360 scenes
93 kNewRotateLeft = 30, // Type 15 — 360 scenes
94 kNewInvertedRotateRight = 32, // Type 16 — Inverted 360 rotation
95 kNewInvertedRotateLeft = 34, // Type 17 — Inverted 360 rotation
96 kNewUseHand = 36, // Type 18 — Open hand, used while using items and while carrying a puzzle piece
97 kNewUseHandHotspot = 37, // Type 18 hotspot — Open hand shown over a slot a carried piece can be dropped into
98 kNewDragHand = 38, // Type 19 — Closed hand, used while dragging puzzle pieces
99 kNewDragHandHotspot = 39, // Type 19 hotspot — Closed hand shown over a piece that can be picked up
100 kNewRotatePiece = 40, // Type 20 — Rotate arrows shown over a rotatable puzzle piece
101 kNewDialCW = 41, // Type 20 hotspot — Dial turn cursors, used by SafeDialPuzzle
102 kNewDialCCW = 43, // Type 21 hotspot
103 kNewPuzzleArrow = 45, // Type 22 hotspot — Arrow cursor shown when hovering a clickable puzzle hotspot
104 kNewPuzzleSlideUp = 47, // Type 23 hotspot — Slide-arrow shown over a movable tile in CollisionPuzzle/TileMovePuzzle
105 kNewPuzzleSlideDown = 49, // Type 24 hotspot
106 kNewPuzzleSlideLeft = 51, // Type 25 hotspot
107 kNewPuzzleSlideRight = 53, // Type 26 hotspot
108 kNewDropHand = 64, // Type 32 — Hand shown when a held piece is dropped (briefly set on the drop action)
109 kNewDropHandHotspot = 65, // Type 32 hotspot — Hand shown over a slot a held piece can be dropped into
110 kNewBlank = 72, // Type 36 — Empty sprite, used while a puzzle draws a carried piece at the mouse itself
111
112 // Cursor types in Nancy13 and newer games. Nancy13 rebuilt the CURS
113 // sheet with 45 system cursor types, each stored as an [idle, hotspot]
114 // pair at slots (type * 2, type * 2 + 1). These constants are Nancy13
115 // system TYPE indices (not slot indices); resolveNancy13CursorID turns a
116 // type into the idle or hotspot slot.
117 // Types 25-34 are the blue in-puzzle variants of the plain ones.
118 kNancy13Normal = 0, // Eyeglass
119 kNancy13Talk = 5,
120 kNancy13MoveUp = 6,
121 kNancy13MoveDown = 7,
122 kNancy13MoveLeft = 8,
123 kNancy13MoveRight = 9,
124 kNancy13MoveBackward = 10,
125 kNancy13MoveForward = 12,
126 kNancy13Arrow = 14,
127 kNancy13RotateRight = 17,
128 kNancy13RotateLeft = 18,
129 kNancy13Exit = 19,
130 kNancy13InvertedRotateRight = 20,
131 kNancy13InvertedRotateLeft = 21,
132 // Empty. Selected while the cell phone's camera viewfinder is up, so
133 // only the viewfinder is seen.
134 kNancy13Blank = 24,
135 kNancy13PuzzleRotateCW = 25,
136 kNancy13PuzzleRotateCCW = 26,
137 kNancy13PuzzleDragHand = 28,
138 kNancy13PuzzleDropHand = 29,
139 kNancy13PuzzleMoveUp = 30,
140 kNancy13PuzzleMoveDown = 31,
141 kNancy13PuzzleArrow = 34
142 };
143
145
146 void init(Common::SeekableReadStream *chunkStream);
147
148 // Nancy19 and up describe their cursors in a boot script, and call them by name.
149 // A script picks one by passing the place of the name in the list as the type.
150 void init(const ScriptBootData &boot);
151 int getCursorTypeByName(const Common::String &name) const;
152
153 // The cursors of the items come after the others, one for every item
154 uint getItemCursorType(int16 itemID) const { return _numCursorTypes + itemID; }
155
156 // Change the current cursor ID. Does not change the graphic.
157 // When setFromScript is set, type is a raw Nancy 10+ system cursor type
158 // index resolved to its flat slot; hotspotVariant then picks the hotspot
159 // (type*2 + 1) or idle (type*2) sprite of the pair.
160 void setCursor(CursorType type, int16 itemID, bool setFromScript, bool hotspotVariant = true);
161 void setCursorType(CursorType type, bool setFromScript = false, bool hotspotVariant = true);
162 void setCursorItemID(int16 itemID);
163 bool isHoldingItem() const { return _curItemID != -1; }
164 void showCursor(bool shouldShow);
165
166 void warpCursor(const Common::Point &pos);
167
168 // Change the cursor graphic. Should be called right before drawing to screen
169 void applyCursor();
170
171 const Common::Point &getCurrentCursorHotspot() { return _cursors[_curCursorID].hotspot;}
172 const Common::Rect &getCurrentCursorBounds() { return _cursors[_curCursorID].bounds; }
173 const Common::Rect &getPrimaryVideoInactiveZone() { return _primaryVideoInactiveZone; }
174 const Common::Point &getPrimaryVideoInitialPos() { return _primaryVideoInitialPos; }
175
176 const CursorType _puzzleExitCursor;
177
178private:
179 void adjustCursorHotspot();
180
181 // Resolve a CursorType + held-item pair to a Nancy 10+ cursor ID.
182 uint resolveNancy10CursorID(CursorType type, int16 itemID, bool setFromScript, bool hotspotVariant);
183
184 // Nancy13 rebuilt the cursor sheet (45 system types, new layout) and split
185 // held-item cursors into _invCursorsSurface. System cursors use a dedicated
186 // Nancy13 slot table.
187 uint resolveNancy13CursorID(CursorType type, int16 itemID, bool setFromScript, bool hotspotVariant);
188
189 uint resolveScriptedCursorID(CursorType type, int16 itemID, bool setFromScript, bool hotspotVariant);
190 void addScriptedCursors(const Common::Array<ScriptBootData::Cursor> &cursors);
191 int getScriptedCursorImage(const Common::Path &name);
192
193 struct Cursor {
194 Common::Rect bounds;
195 Common::Point hotspot;
196 int image = -1; // Nancy26: the one of _scriptedCursorImages it is in
197 };
198
199 // CURS data
200 Common::Array<Cursor> _cursors;
201
202 // Nancy19+
204 Common::Array<bool> _cursorOverridesItem;
205 uint _defaultCursorType = 0;
206
207 Common::Rect _primaryVideoInactiveZone;
208 Common::Point _primaryVideoInitialPos;
209
210 Graphics::ManagedSurface _invCursorsSurface;
211 Graphics::ManagedSurface _uiCursorsSurface; // Nancy13+
212
213 // Nancy26: every cursor names its picture, and the cursor of an item has
214 // the name of the item
215 Common::Array<Common::Path> _scriptedCursorImageNames;
217 Common::Array<int> _itemCursorTypes; // by item; -1 for none
218
219 Common::Point _warpedMousePos;
220 CursorType _curCursorType;
221 bool _curSetFromScript;
222 bool _curHotspotVariant;
223 int16 _curItemID;
224 uint _curCursorID;
225 uint _lastCursorID;
226 bool _hasItem;
227 bool _isInitialized;
228 int _numCursorTypes;
229};
230
231} // End of namespace Nancy
232
233#endif // NANCY_CURSOR_H
Definition: array.h:52
Definition: path.h:52
Definition: stream.h:745
Definition: str.h:59
Definition: managed_surface.h:51
Definition: cursor.h:35
Definition: actionmanager.h:32
Definition: rect.h:144
Definition: rect.h:536
Definition: enginedata.h:1101