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/stream.h"
27 
28 #include "graphics/managed_surface.h"
29 
30 namespace Nancy {
31 
33 
34 public:
35  enum CursorType {
36  kNormal = 0, // Eyeglass (except in TVD), non-highlighted
37  kHotspot = 1, // Eyeglass (except in TVD), highlighted
38  kMove = 2, // Used for movement in early games
39  kExit = 3, // Used for movement, some games use it for exiting puzzles
40  kRotateCW = 4, // Used in puzzles only
41  kRotateCCW = 5, // Used in puzzles only
42  kMoveLeft = 6, // Used for movement, some games used it for turning in 360 scenes
43  kMoveRight = 7, // Used for movement, some games used it for turning in 360 scenes
44  kMoveForward = 8, // Used for movement
45  kMoveBackward = 9, // Used for movement, some games use it for exiting puzzles
46  kMoveUp = 10, // Used for movement
47  kMoveDown = 11, // Used for movement
48  kRotateLeft = 12, // Used in 360 scenes in nancy6 and up
49  kRotateRight = 13, // Used in 360 scenes in nancy6 and up
50  kInvertedRotateRight = 14, // Used in 360 scenes with inverted rotation; nancy6 and up
51  kInvertedRotateLeft = 15, // Used in 360 scenes with inverted rotation; nancy6 and up
52  kCustom1 = 16, // Custom cursors change between games; Likely used in puzzles
53  kCustom1Hotspot = 17,
54  kCustom2 = 18,
55  kCustom2Hotspot = 19,
56  kNormalArrow = 20,
57  kHotspotArrow = 21,
58  kHotspotTalk = 22, // Speech-bubble hover cursor (Nancy 10+)
59  kDragHand = 23, // Hand cursor used when dragging an item (Nancy 10+)
60  kDropHand = 24, // Drop-hand cursor used while a piece is held over a target (Nancy 10+)
61  kPuzzleArrow = 25, // Puzzle arrow cursor shown when hovering a clickable puzzle hotspot (Nancy 10+)
62 
63  // Cursors in Nancy10 and newer games. The CURS chunk holds 37 system
64  // cursor types in pairs; type T's idle slot is (T*2) and its hotspot
65  // slot is (T*2 + 1). Types 0–4 and 18–26 have visually distinct idle
66  // vs. hotspot sprites; types 5–17 and 27–36 use the same sprite for
67  // both. Types 18+ are Nancy 10-specific puzzle/inventory cursors.
68  kNewNormal = 0, // Type 0 — Eyeglass
69  kNewHotspot = 1, // Type 0 hotspot — Eyeglass highlighted
70  kNewUse = 2, // Type 1 — Open-hand "use" cursor (interact with characters/objects)
71  kNewHotspotUse = 3, // Type 1 hotspot
72  kNewLockedUse = 4, // Type 2 — Locked variant of the use hand
73  kNewHotspotLockedUse = 5, // Type 2 hotspot
74  kNewTalk = 6, // Type 3 — Speech-bubble (talking to characters)
75  kNewHotspotTalk = 7, // Type 3 hotspot
76  kNewNormalArrow = 8, // Type 4 — Taskbar arrow
77  kNewHotspotArrow = 9, // Type 4 hotspot
78  kNewExit = 10, // Type 5 — Exit / back movement
79  kNewMoveLeft = 12, // Type 6 — Movement / 360 turn
80  kNewMoveRight = 14, // Type 7 — Movement / 360 turn
81  kNewMoveForward = 16, // Type 8 — Movement
82  kNewMoveBackward = 18, // Type 9 — Movement / exit puzzles
83  kNewMoveUp = 20, // Type 10 — Movement
84  kNewMoveDown = 22, // Type 11 — Movement
85  kNewRotateCW = 24, // Type 12 — Puzzle rotation
86  kNewRotateCCW = 26, // Type 13 — Puzzle rotation
87  kNewRotateRight = 28, // Type 14 — 360 scenes
88  kNewRotateLeft = 30, // Type 15 — 360 scenes
89  kNewInvertedRotateRight = 32, // Type 16 — Inverted 360 rotation
90  kNewInvertedRotateLeft = 34, // Type 17 — Inverted 360 rotation
91  kNewUseHand = 36, // Type 18 — Hand used while using items
92  kNewDragHand = 38, // Type 19 — Hand used while dragging puzzle pieces (e.g. SortPuzzle pickup action sets this)
93  kNewPuzzleArrow = 45, // Type 22 hotspot — Arrow cursor shown when hovering a clickable puzzle hotspot
94  kNewDropHand = 64, // Type 32 — Hand shown when a held piece is dropped (briefly set on the drop action)
95 
96  // Cursor types in Nancy13 and newer games. Nancy13 rebuilt the CURS
97  // sheet with 45 system cursor types, each stored as an [idle, hotspot]
98  // pair at slots (type * 2, type * 2 + 1). These constants are Nancy13
99  // system TYPE indices (not slot indices); resolveNancy13CursorID turns a
100  // type into the idle or hotspot slot.
101  kNancy13Normal = 0, // Eyeglass (kHotspot is the same type's hotspot slot)
102  kNancy13MoveUp = 6, // Scene-change: look/move up
103  kNancy13MoveDown = 7, // Scene-change: look/move down
104  kNancy13MoveLeft = 8, // Scene-change: move left
105  kNancy13MoveRight = 9, // Scene-change: move right
106  kNancy13MoveBackward = 10, // Scene-change: move back / exit puzzle
107  kNancy13MoveForward = 12, // Scene-change: move forward
108  kNancy13Arrow = 14, // Frame / taskbar arrow
109  kNancy13Exit = 19, // Exit
110  kNancy13DropHand = 24, // Hand shown while carrying a puzzle piece
111  kNancy13RotateCCW = 25, // Dial / turn cursor
112  kNancy13RotateCW = 26, // Dial / turn cursor
113  kNancy13PuzzleArrow = 29 // Generic clickable puzzle hotspot
114  };
115 
116  CursorManager();
117 
118  void init(Common::SeekableReadStream *chunkStream);
119 
120  // Change the current cursor ID. Does not change the graphic.
121  // When setFromScript is set, type is a raw Nancy 10+ system cursor type
122  // index resolved to its flat slot; hotspotVariant then picks the hotspot
123  // (type*2 + 1) or idle (type*2) sprite of the pair.
124  void setCursor(CursorType type, int16 itemID, bool setFromScript, bool hotspotVariant = true);
125  void setCursorType(CursorType type, bool setFromScript = false, bool hotspotVariant = true);
126  void setCursorItemID(int16 itemID);
127  void showCursor(bool shouldShow);
128 
129  void warpCursor(const Common::Point &pos);
130 
131  // Change the cursor graphic. Should be called right before drawing to screen
132  void applyCursor();
133 
134  const Common::Point &getCurrentCursorHotspot() { return _cursors[_curCursorID].hotspot;}
135  const Common::Rect &getPrimaryVideoInactiveZone() { return _primaryVideoInactiveZone; }
136  const Common::Point &getPrimaryVideoInitialPos() { return _primaryVideoInitialPos; }
137 
138  const CursorType _puzzleExitCursor;
139 
140 private:
141  void adjustCursorHotspot();
142 
143  // Resolve a CursorType + held-item pair to a Nancy 10+ cursor ID.
144  uint resolveNancy10CursorID(CursorType type, int16 itemID, bool setFromScript, bool hotspotVariant);
145 
146  // Nancy13 rebuilt the cursor sheet (45 system types, new layout) and split
147  // held-item cursors into _invCursorsSurface. System cursors use a dedicated
148  // Nancy13 slot table.
149  uint resolveNancy13CursorID(CursorType type, int16 itemID, bool setFromScript, bool hotspotVariant);
150 
151  struct Cursor {
152  Common::Rect bounds;
153  Common::Point hotspot;
154  };
155 
156  // CURS data
157  Common::Array<Cursor> _cursors;
158 
159  Common::Rect _primaryVideoInactiveZone;
160  Common::Point _primaryVideoInitialPos;
161 
162  Graphics::ManagedSurface _invCursorsSurface;
163  Graphics::ManagedSurface _uiCursorsSurface; // Nancy13+
164 
165  Common::Point _warpedMousePos;
166  CursorType _curCursorType;
167  int16 _curItemID;
168  uint _curCursorID;
169  uint _lastCursorID;
170  bool _hasItem;
171  bool _isInitialized;
172  int _numCursorTypes;
173 };
174 
175 } // End of namespace Nancy
176 
177 #endif // NANCY_CURSOR_H
Definition: managed_surface.h:51
Definition: cursor.h:32
Definition: rect.h:536
Definition: stream.h:745
Definition: rect.h:144
Definition: actionmanager.h:32