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 ASYLUM_SYSTEM_CURSOR_H
24 #define ASYLUM_SYSTEM_CURSOR_H
25 
26 #include "common/events.h"
27 #include "common/rect.h"
28 
29 #include "asylum/shared.h"
30 
31 namespace Asylum {
32 
33 class AsylumEngine;
34 class GraphicResource;
35 
36 enum CursorState {
37 	kCursorStateLeft = 1,
38 	kCursorStateRight = 2,
39 	kCursorMiddle = 3
40 };
41 
42 enum CursorAnimation {
43 	kCursorAnimationNone   = 0,
44 	kCursorAnimationLinear = 1,
45 	kCursorAnimationMirror = 2
46 };
47 
48 /**
49  * Asylum cursors are GraphicResources, and are stored in
50  * ResourcePacks, as are all game assets.
51  */
52 class Cursor {
53 public:
54 	Cursor(AsylumEngine *engine);
55 	virtual ~Cursor();
56 
57 	/**
58 	 * Show the current cursor
59 	 */
60 	void show() const;
61 
62 	/**
63 	 * Hide the current cursor
64 	 */
65 	void hide() const;
66 
67 	/**
68 	 * Query if the cursor is hidden.
69 	 *
70 	 * @return true if hidden, false if not.
71 	 */
72 	bool isHidden() const;
73 
74 	/**
75 	 * Set the current cursor instance to the graphic resource provide. The frames parameter defaults to -1, which in this case means that the frame count
76 	 * should be derived from the graphic resource as opposed to being explicitly set.
77 	 *
78 	 * @param resourceId  Identifier for the resource.
79 	 * @param cnt         The counter.
80 	 * @param anim        The animation type
81 	 * @param frames      The frames.
82 	 */
83 	void set(ResourceId resourceId, int32 cnt = 0, CursorAnimation anim = kCursorAnimationMirror, int32 frames = -1);
84 
85 	/**
86 	 * Get the next logical frame from the currently loaded
87 	 * cursorResource and draw it
88 	 */
89 	void animate();
90 
91 	// Accessors
92 	void setState(const Common::Event &evt);
getState()93 	byte getState() { return _state; }
setForceHide(bool state)94 	void setForceHide(bool state) { _forceHide = state; }
getResourceId()95 	ResourceId getResourceId() { return _graphicResourceId; }
getAnimation()96 	CursorAnimation getAnimation() { return _animation; }
97 
98 	/**
99 	 * Return the cursor's position on the screen
100 	 */
101 	const Common::Point position() const;
102 
103 private:
104 	AsylumEngine *_vm;
105 
106 	byte _state;
107 
108 	// Cursor resource
109 	GraphicResource *_cursorRes;
110 
111 	/** the point on the screen the cursor is at */
112 	Common::Point _pos;
113 
114 	/** the point of the cursor that triggers click hits */
115 	Common::Point _hotspot;
116 
117 	// The number of milliseconds between cursor gfx updates
118 	uint32 _nextTick;
119 
120 	int32 _frameStep;
121 
122 	// NOTE: The original engine contains a function that assigns global variables to a
123 	// struct associated with cursor graphics info. Since this functionality only
124 	// ever seems to be used to reference cursor info, the struct members
125 	// may as well be class members in order to simplify the logic a bit
126 	ResourceId _graphicResourceId;
127 	uint32 _currentFrame;
128 	uint32 _lastFrameIndex;
129 	int32 _counter;
130 	CursorAnimation _animation;
131 
132 	/**
133 	 * Since the cursor is updated by various event handlers, if an action is
134 	 * currently being processed that requires the cursor to remain hidden, another
135 	 * event may override that request and show the cursor regardless
136 	 *
137 	 * This is currently used during the intro speech in Scene 1 after the intro
138 	 * video plays
139 	 *
140 	 * @default false
141 	 */
142 	bool _forceHide;
143 
144 	/**
145 	 * Updates the cursor
146 	 */
147 	void update();
148 
149 	/**
150 	 * Updates the cursor current frame.
151 	 */
152 	void updateFrame();
153 
154 	/**
155 	 * Gets the hotspot for a specific frame.
156 	 *
157 	 * @param frameIndex Zero-based index of the frame.
158 	 *
159 	 * @return The hotspot.
160 	 */
161 	Common::Point getHotspot(uint32 frameIndex);
162 };
163 
164 } // end of namespace Asylum
165 
166 #endif // ASYLUM_SYSTEM_CURSOR_H
167