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 AGS_EVENTS_H
23 #define AGS_EVENTS_H
24 
25 #include "shared/ac/keycode.h"
26 #include "common/array.h"
27 #include "common/queue.h"
28 #include "common/events.h"
29 
30 namespace AGS {
31 
33 private:
34  Common::Queue<Common::Event> _pendingEvents;
36  Common::Array<bool> _keys;
37  Common::Point _mousePos;
38  int16 _joystickAxis[32];
39  bool _joystickButton[32];
40  byte _keyModifierFlags = 0;
41 
42  bool isModifierKey(const Common::KeyCode &keycode) const;
43  bool isExtendedKey(const Common::KeyCode &keycode) const;
44 
45  void updateKeys(const Common::Event &event, bool isDown);
46 public:
50  static bool ags_key_to_scancode(AGS3::eAGSKeyCode key, Common::KeyCode(&kc)[3]);
51 
52  /*
53  * Converts a ScummVM event to the ags keycode
54  */
55  static AGS3::eAGSKeyCode scummvm_key_to_ags_key(const Common::Event &event, int &ags_mod, bool old_keyhandle);
56 
57 public:
58  EventsManager();
59  ~EventsManager();
60 
64  void pollEvents();
65 
69  bool keyEventPending() const {
70  return !_keyEvents.empty();
71  }
72 
77  return _keyEvents.pop();
78  }
79 
83  uint getModifierFlags() const {
84  return _keyModifierFlags;
85  }
86 
91  void pushKeyboardEvent(const Common::Event &evt) {
92  _keyEvents.push(evt);
93  }
94 
99 
103  void warpMouse(const Common::Point &newPos);
104 
108  bool isKeyPressed(AGS3::eAGSKeyCode key, bool poll = true);
109 
110  void clearEvents() {
111  _pendingEvents.clear();
112  _keyEvents.clear();
113  }
114 
119  return _mousePos;
120  }
121 
125  int16 getJoystickAxis(byte axis) const {
126  assert(axis < 32);
127  return _joystickAxis[axis];
128  }
129 
133  bool getJoystickButton(byte button) const {
134  assert(button < 32);
135  return _joystickButton[button];
136  }
137 
141  bool getJoystickButtonOnce(byte button) {
142  assert(button < 32);
143  bool result = _joystickButton[button];
144  _joystickButton[button] = false;
145  return result;
146  }
147 };
148 
149 extern EventsManager *g_events;
150 
151 } // namespace AGS
152 
153 #endif
Definition: achievements_tables.h:27
Common::Event readEvent()
int16 getJoystickAxis(byte axis) const
Definition: events.h:125
bool isKeyPressed(AGS3::eAGSKeyCode key, bool poll=true)
Definition: events.h:32
bool getJoystickButtonOnce(byte button)
Definition: events.h:141
bool getJoystickButton(byte button) const
Definition: events.h:133
bool keyEventPending() const
Definition: events.h:69
void warpMouse(const Common::Point &newPos)
Definition: events.h:199
Definition: rect.h:45
Common::Event getPendingKeyEvent()
Definition: events.h:76
Common::Point getMousePos() const
Definition: events.h:118
void pushKeyboardEvent(const Common::Event &evt)
Definition: events.h:91
uint getModifierFlags() const
Definition: events.h:83
static bool ags_key_to_scancode(AGS3::eAGSKeyCode key, Common::KeyCode(&kc)[3])