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 XEEN_EVENTS_H
23 #define XEEN_EVENTS_H
24 
25 #include "common/scummsys.h"
26 #include "common/events.h"
27 #include "common/queue.h"
28 #include "mm/xeen/sprites.h"
29 
30 namespace MM {
31 namespace Xeen {
32 
33 #define GAME_FRAME_RATE (1000 / 50)
34 #define GAME_FRAME_TIME 50
35 #define SCREEN_UPDATE_TIME 10
36 #define MAX_PENDING_EVENTS 5
37 
38 class XeenEngine;
39 
40 struct PendingEvent {
41  Common::KeyState _keyState;
42  bool _leftButton;
43  bool _rightButton;
44 
45  PendingEvent() : _leftButton(false), _rightButton(false) {}
46  PendingEvent(const Common::KeyState &keyState) : _keyState(keyState), _leftButton(false), _rightButton(false) {}
47  PendingEvent(bool leftButton, bool rightButton) : _leftButton(leftButton), _rightButton(rightButton) {}
48 
52  bool isKeyboard() const { return _keyState.keycode != Common::KEYCODE_INVALID; }
53 
57  bool isMouse() const { return _leftButton || _rightButton; }
58 };
59 
61 private:
62  XeenEngine *_vm;
63  uint32 _frameCounter;
64  uint32 _priorFrameCounterTime;
65  uint32 _priorScreenRefreshTime;
66  uint32 _gameCounter;
67  uint32 _gameCounters[6];
68  uint32 _playTime;
69  Common::Queue<PendingEvent> _pendingEvents;
70  SpriteResource _sprites;
71  bool _mousePressed;
72 
76  void nextFrame();
77 
81  bool isModifierKey(const Common::KeyCode &keycode) const;
82 public:
83  Common::Point _mousePos;
84 public:
86  ~EventsManager();
87 
88  /*
89  * Set the cursor
90  */
91  void setCursor(int cursorId);
92 
96  void showCursor();
97 
101  void hideCursor();
102 
106  bool isCursorVisible();
107 
111  void pollEvents();
112 
116  void pollEventsAndWait();
117 
121  void clearEvents();
122 
126  void debounceMouse();
127 
131  void addEvent(const Common::KeyState &keyState);
132 
136  void addEvent(bool leftButton, bool rightButton);
137 
141  bool getEvent(PendingEvent &pe);
142 
146  bool isEventPending() const { return !_pendingEvents.empty(); }
147 
151  bool isKeyMousePressed();
152 
153  void updateGameCounter() { _gameCounter = _frameCounter; }
154  void timeMark1() { _gameCounters[1] = _frameCounter; }
155  void timeMark2() { _gameCounters[2] = _frameCounter; }
156  void timeMark3() { _gameCounters[3] = _frameCounter; }
157  void timeMark4() { _gameCounters[4] = _frameCounter; }
158  void timeMark5() { _gameCounters[5] = _frameCounter; }
159 
160  uint32 timeElapsed() const { return _frameCounter - _gameCounter; }
161  uint32 timeElapsed1() const { return _frameCounter - _gameCounters[1]; }
162  uint32 timeElapsed2() const { return _frameCounter - _gameCounters[2]; }
163  uint32 timeElapsed3() const { return _frameCounter - _gameCounters[3]; }
164  uint32 timeElapsed4() const { return _frameCounter - _gameCounters[4]; }
165  uint32 timeElapsed5() const { return _frameCounter - _gameCounters[5]; }
166  uint32 getTicks() { return _frameCounter; }
167  uint32 playTime() const { return _playTime; }
168  void setPlayTime(uint32 time) { _playTime = time; }
169 
176  bool wait(uint numFrames, bool interruptable = true);
177 
181  void ipause(uint amount);
182 
186  void ipause5(uint amount);
187 
191  void waitForPressAnimated();
192 
196  void waitForPress();
197 };
198 
199 } // End of namespace Xeen
200 } // End of namespace MM
201 
202 #endif
Definition: sprites.h:52
Definition: queue.h:42
bool isEventPending() const
Definition: events.h:146
KeyCode keycode
Definition: keyboard.h:299
Definition: xeen.h:93
Definition: detection.h:27
Definition: rect.h:45
bool isMouse() const
Definition: events.h:57
Definition: keyboard.h:294
bool isKeyboard() const
Definition: events.h:52
Definition: events.h:40
Definition: events.h:60