ScummVM API documentation
events.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 ULTIMA_SHARED_ENGINE_EVENTS_H
23#define ULTIMA_SHARED_ENGINE_EVENTS_H
24
25#include "common/scummsys.h"
26#include "common/events.h"
27#include "common/stack.h"
28#include "gui/debugger.h"
29#include "graphics/screen.h"
30#include "ultima/shared/core/rect.h"
31
32namespace Ultima {
33namespace Shared {
34
35#define GAME_FRAME_RATE (1000 / 50)
36#define GAME_FRAME_TIME 50
37#define SCREEN_UPDATE_TIME 10
38#define BUTTON_MASK(MB) (1 << ((int)(MB) - 1))
39#define DOUBLE_CLICK_TIME 100
40
41enum MouseButton {
42 BUTTON_NONE = 0,
43 BUTTON_LEFT = 1,
44 BUTTON_RIGHT = 2,
45 BUTTON_MIDDLE = 3,
46 MOUSE_LAST
47};
48
49enum SpecialButtons {
50 MK_LBUTTON = 1, MK_RBUTTON = 2, MK_MBUTTON = 4, MK_SHIFT = 8, MK_CONTROL = 0x10
51};
52
57public:
58 virtual ~EventTarget() {
59 }
60
64 virtual void onIdle() {
65 }
66
70 virtual void mouseMove(const Common::Point &mousePos) {
71 }
72 virtual void leftButtonDown(const Common::Point &mousePos) {
73 }
74 virtual void leftButtonUp(const Common::Point &mousePos) {
75 }
76 virtual void leftButtonDoubleClick(const Common::Point &mousePos) {
77 }
78 virtual void middleButtonDown(const Common::Point &mousePos) {
79 }
80 virtual void middleButtonUp(const Common::Point &mousePos) {
81 }
82 virtual void middleButtonDoubleClick(const Common::Point &mousePos) {
83 }
84 virtual void rightButtonDown(const Common::Point &mousePos) {
85 }
86 virtual void rightButtonUp(const Common::Point &mousePos) {
87 }
88 virtual void mouseWheel(const Common::Point &mousePos, bool wheelUp) {
89 }
90 virtual void keyDown(Common::KeyState keyState) {
91 }
92 virtual void keyUp(Common::KeyState keyState) {
93 }
94};
95
99class CPressTarget : public EventTarget {
100public:
101 bool _pressed;
102public:
103 CPressTarget() : _pressed(false) {
104 }
105 ~CPressTarget() override {
106 }
107 void leftButtonDown(const Common::Point &mousePos) override {
108 _pressed = true;
109 }
110 void middleButtonDown(const Common::Point &mousePos) override {
111 _pressed = true;
112 }
113 void rightButtonDown(const Common::Point &mousePos) override {
114 _pressed = true;
115 }
116 void keyDown(Common::KeyState keyState) override {
117 _pressed = true;
118 }
119};
120
125public:
129 virtual ~EventsCallback() {}
130
134 virtual Graphics::Screen *getScreen() const {
135 return nullptr;
136 }
137};
138
140private:
141 EventsCallback *_callback;
142 Common::Stack<EventTarget *> _eventTargets;
143 uint32 _frameCounter;
144 uint32 _priorFrameTime;
145 uint32 _priorFrameCounterTime;
146 uint32 _gameCounter;
147 uint32 _playTime;
148 Point _mousePos;
149 uint _specialButtons;
150 uint8 _buttonsDown;
151
155 bool checkForNextFrameCounter();
156
160 EventTarget *eventTarget() const {
161 return _eventTargets.top();
162 }
163
167 void handleKbdSpecial(Common::KeyState keyState);
168
172 void setButtonDown(MouseButton button, bool isDown);
173protected:
177 virtual void nextFrame();
178public:
179 EventsManager(EventsCallback *callback);
180 virtual ~EventsManager() {}
181
187 void addTarget(EventTarget *target) {
188 _eventTargets.push(target);
189 }
190
195 _eventTargets.pop();
196 }
197
202 virtual bool pollEvent(Common::Event &event);
203
210
216
220 uint32 getFrameCounter() const {
221 return _frameCounter;
222 }
223
227 uint32 getTicksCount() const;
228
232 void sleep(uint time);
233
237 bool waitForPress(uint expiry);
238
242 void setMousePos(const Point &pt);
243
244 /*
245 * Return whether a given special key is currently pressed
246 */
247 bool isSpecialPressed(SpecialButtons btn) const {
248 return (_specialButtons & btn) != 0;
249 }
250
254 uint getSpecialButtons() const {
255 return _specialButtons;
256 }
257
258 /*
259 * Set the cursor
260 */
261 virtual void setCursor(int cursorId) {
262 }
263
268
273
278
282 uint32 getTicks() {
283 return _frameCounter;
284 }
285
289 uint32 playTime() const {
290 return _playTime;
291 }
292
296 void setPlayTime(uint32 time) {
297 _playTime = time;
298 }
299
303 inline bool isButtonDown(MouseButton button) const {
304 return (_buttonsDown & BUTTON_MASK(button)) != 0;
305 }
306
310 bool isButtonDown() const {
311 return isButtonDown(BUTTON_LEFT) || isButtonDown(BUTTON_RIGHT) || isButtonDown(BUTTON_MIDDLE);
312 }
313
317 byte getButtonState() const {
318 return _buttonsDown;
319 }
320
325 return _mousePos;
326 }
327};
328
329extern bool isMouseDownEvent(Common::EventType type);
330
331extern bool isMouseUpEvent(Common::EventType type);
332
333extern MouseButton whichButton(Common::EventType type);
334
335} // End of namespace Shared
336} // End of namespace Ultima
337
338#endif
Definition: stack.h:102
Definition: screen.h:47
Definition: events.h:99
Definition: events.h:56
virtual void mouseMove(const Common::Point &mousePos)
Definition: events.h:70
virtual void onIdle()
Definition: events.h:64
Definition: events.h:124
virtual ~EventsCallback()
Definition: events.h:129
virtual Graphics::Screen * getScreen() const
Definition: events.h:134
Definition: events.h:139
void setMousePos(const Point &pt)
uint32 getTicks()
Definition: events.h:282
void addTarget(EventTarget *target)
Definition: events.h:187
uint32 playTime() const
Definition: events.h:289
uint getSpecialButtons() const
Definition: events.h:254
bool waitForPress(uint expiry)
bool isButtonDown(MouseButton button) const
Definition: events.h:303
uint32 getFrameCounter() const
Definition: events.h:220
virtual bool pollEvent(Common::Event &event)
void setPlayTime(uint32 time)
Definition: events.h:296
void removeTarget()
Definition: events.h:194
bool isButtonDown() const
Definition: events.h:310
byte getButtonState() const
Definition: events.h:317
Common::Point getMousePos() const
Definition: events.h:324
EventType
Definition: events.h:49
MouseButton
Definition: events.h:202
Definition: events.h:218
Definition: keyboard.h:294
Definition: rect.h:144