ScummVM API documentation
keymapper.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 COMMON_KEYMAPPER_H
23#define COMMON_KEYMAPPER_H
24
25#include "common/scummsys.h"
26
27#include "backends/keymapper/keymap.h"
28
29#include "common/array.h"
30#include "common/config-manager.h"
31#include "common/events.h"
32
33namespace Common {
34
35const char *const kGuiKeymapName = "gui";
36const char *const kGlobalKeymapName = "global";
37
38struct Action;
39class DelayedEventSource;
40struct HardwareInput;
41class HardwareInputSet;
42class KeymapperDefaultBindings;
43
45public:
46
47 Keymapper(EventManager *eventMan);
48 ~Keymapper();
49
50 // EventMapper interface
51 bool mapEvent(const Event &ev, List<Event> &mappedEvents) override;
52
59
67 void addGlobalKeymap(Keymap *keymap);
68
77 void addGameKeymap(Keymap *keymap);
78
84
90 void setGameKeymapState(const String &id, bool enable);
91
96
102 Keymap *getKeymap(const String &id) const;
103
107 const KeymapArray &getKeymaps() const { return _keymaps; }
108
113
119 void setEnabledKeymapType(Keymap::KeymapType type);
120 Keymap::KeymapType enabledKeymapType() const { return _enabledKeymapType; }
121
125 void setEnabled(bool enabled) { _enabled = enabled; }
126
130 bool isEnabled() const { return _enabled; }
131
135 void clear();
136
141
142 void initKeymap(Keymap *keymap, ConfigManager::Domain *domain);
143 void reloadKeymapMappings(Keymap *keymap);
144
145private:
146 EventManager *_eventMan;
147 HardwareInputSet *_hardwareInputs;
148 KeymapperDefaultBindings *_backendDefaultBindings;
149 DelayedEventSource *_delayedEventSource;
150
151 enum IncomingEventType {
152 kIncomingEventIgnored,
153 kIncomingEventStart,
154 kIncomingEventEnd,
155 kIncomingEventInstant
156 };
157
158 enum {
159 kJoyAxisPressedTreshold = Common::JOYAXIS_MAX / 2,
160 kJoyAxisUnpressedTreshold = Common::JOYAXIS_MAX / 4
161 };
162
163 bool _enabled;
164 Keymap::KeymapType _enabledKeymapType;
165
166 KeymapArray _keymaps;
167
168 bool _joystickAxisPreviouslyPressed[8]; // size should match the number of valid axis entries of defaultJoystickAxes (in hardware-input.cpp)
169
170 Keymap::KeymapMatch getMappedActions(const Event &event, Keymap::ActionArray &actions, Keymap::KeymapType keymapType) const;
171 Event executeAction(const Action *act, const Event &incomingEvent);
172 EventType convertStartToEnd(EventType eventType);
173 IncomingEventType convertToIncomingEventType(const Event &ev) const;
174
175 void hardcodedEventMapping(Event ev);
176 void resetInputState();
177};
178
183public:
184 KeymapTypeEnabler(Keymapper *keymapper, Keymap::KeymapType keymapType) :
185 _keymapper(keymapper) {
186 assert(keymapper);
187 _previousKeymapType = keymapper->enabledKeymapType();
188 keymapper->setEnabledKeymapType(keymapType);
189 }
190
192 _keymapper->setEnabledKeymapType(_previousKeymapType);
193 }
194
195private:
196 Keymapper *_keymapper;
197 Keymap::KeymapType _previousKeymapType;
198};
199
201public:
202 // EventSource API
203 bool pollEvent(Event &event) override;
204 bool allowMapping() const override;
205
209 void scheduleEvent(const Event &ev, uint32 delayMillis);
210
211private:
212 struct DelayedEventsEntry {
213 const uint32 timerOffset;
214 const Event event;
215 DelayedEventsEntry(const uint32 offset, const Event ev) : timerOffset(offset), event(ev) { }
216 };
217
218 Queue<DelayedEventsEntry> _delayedEvents;
219 uint32 _delayedEffectiveTime;
220};
221
222} // End of namespace Common
223
224#endif // #ifndef COMMON_KEYMAPPER_H
Definition: config-manager.h:59
Definition: keymapper.h:200
bool pollEvent(Event &event) override
void scheduleEvent(const Event &ev, uint32 delayMillis)
bool allowMapping() const override
Definition: events.h:491
Definition: events.h:367
Definition: events.h:278
Definition: hardware-input.h:199
Definition: keymap.h:66
Definition: keymapper.h:182
Definition: keymapper-defaults.h:32
Definition: keymapper.h:44
void cleanupGameKeymaps()
void reloadAllMappings()
void disableAllGameKeymaps()
bool mapEvent(const Event &ev, List< Event > &mappedEvents) override
Keymap * getKeymap(const String &id) const
bool isEnabled() const
Definition: keymapper.h:130
void registerHardwareInputSet(HardwareInputSet *inputs, KeymapperDefaultBindings *backendDefaultBindings)
void addGameKeymap(Keymap *keymap)
void setGameKeymapState(const String &id, bool enable)
void setEnabledKeymapType(Keymap::KeymapType type)
void setEnabled(bool enabled)
Definition: keymapper.h:125
HardwareInput findHardwareInput(const Event &event)
void addGlobalKeymap(Keymap *keymap)
const KeymapArray & getKeymaps() const
Definition: keymapper.h:107
Definition: list.h:44
Definition: str.h:59
EventType
Definition: events.h:49
Definition: algorithm.h:29
Definition: events.h:218
Definition: hardware-input.h:54