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 "xeen/sprites.h"
29 
30 namespace Xeen {
31 
32 #define GAME_FRAME_RATE (1000 / 50)
33 #define GAME_FRAME_TIME 50
34 #define SCREEN_UPDATE_TIME 10
35 #define MAX_PENDING_EVENTS 5
36 
37 class XeenEngine;
38 
39 struct PendingEvent {
40  Common::KeyState _keyState;
41  bool _leftButton;
42  bool _rightButton;
43 
44  PendingEvent() : _leftButton(false), _rightButton(false) {}
45  PendingEvent(const Common::KeyState &keyState) : _keyState(keyState), _leftButton(false), _rightButton(false) {}
46  PendingEvent(bool leftButton, bool rightButton) : _leftButton(leftButton), _rightButton(rightButton) {}
47 
51  bool isKeyboard() const { return _keyState.keycode != Common::KEYCODE_INVALID; }
52 
56  bool isMouse() const { return _leftButton || _rightButton; }
57 };
58 
60 private:
61  XeenEngine *_vm;
62  uint32 _frameCounter;
63  uint32 _priorFrameCounterTime;
64  uint32 _priorScreenRefreshTime;
65  uint32 _gameCounter;
66  uint32 _gameCounters[6];
67  uint32 _playTime;
68  Common::Queue<PendingEvent> _pendingEvents;
69  SpriteResource _sprites;
70  bool _mousePressed;
71 
75  void nextFrame();
76 
80  bool isModifierKey(const Common::KeyCode &keycode) const;
81 public:
82  Common::Point _mousePos;
83 public:
85  ~EventsManager();
86 
87  /*
88  * Set the cursor
89  */
90  void setCursor(int cursorId);
91 
95  void showCursor();
96 
100  void hideCursor();
101 
105  bool isCursorVisible();
106 
110  void pollEvents();
111 
115  void pollEventsAndWait();
116 
120  void clearEvents();
121 
125  void debounceMouse();
126 
130  void addEvent(const Common::KeyState &keyState);
131 
135  void addEvent(bool leftButton, bool rightButton);
136 
140  bool getEvent(PendingEvent &pe);
141 
145  bool isEventPending() const { return !_pendingEvents.empty(); }
146 
150  bool isKeyMousePressed();
151 
152  void updateGameCounter() { _gameCounter = _frameCounter; }
153  void timeMark1() { _gameCounters[1] = _frameCounter; }
154  void timeMark2() { _gameCounters[2] = _frameCounter; }
155  void timeMark3() { _gameCounters[3] = _frameCounter; }
156  void timeMark4() { _gameCounters[4] = _frameCounter; }
157  void timeMark5() { _gameCounters[5] = _frameCounter; }
158 
159  uint32 timeElapsed() const { return _frameCounter - _gameCounter; }
160  uint32 timeElapsed1() const { return _frameCounter - _gameCounters[1]; }
161  uint32 timeElapsed2() const { return _frameCounter - _gameCounters[2]; }
162  uint32 timeElapsed3() const { return _frameCounter - _gameCounters[3]; }
163  uint32 timeElapsed4() const { return _frameCounter - _gameCounters[4]; }
164  uint32 timeElapsed5() const { return _frameCounter - _gameCounters[5]; }
165  uint32 getTicks() { return _frameCounter; }
166  uint32 playTime() const { return _playTime; }
167  void setPlayTime(uint32 time) { _playTime = time; }
168 
175  bool wait(uint numFrames, bool interruptable = true);
176 
180  void ipause(uint amount);
181 
185  void ipause5(uint amount);
186 
190  void waitForPressAnimated();
191 
195  void waitForPress();
196 };
197 
198 } // End of namespace Xeen
199 
200 #endif /* XEEN_EVENTS_H */
Definition: events.h:59
Definition: sprites.h:48
bool isKeyboard() const
Definition: events.h:51
bool isMouse() const
Definition: events.h:56
Definition: queue.h:42
Definition: events.h:39
KeyCode keycode
Definition: keyboard.h:299
bool isEventPending() const
Definition: events.h:145
Definition: rect.h:45
Definition: xeen.h:100
Definition: keyboard.h:294
Definition: character.h:33