ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

keymapper.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef COMMON_KEYMAPPER_H
00024 #define COMMON_KEYMAPPER_H
00025 
00026 #include "common/scummsys.h"
00027 
00028 #include "backends/keymapper/keymap.h"
00029 
00030 #include "common/array.h"
00031 #include "common/config-manager.h"
00032 #include "common/events.h"
00033 
00034 namespace Common {
00035 
00036 const char *const kGuiKeymapName = "gui";
00037 const char *const kGlobalKeymapName = "global";
00038 
00039 struct Action;
00040 class DelayedEventSource;
00041 struct HardwareInput;
00042 class HardwareInputSet;
00043 class KeymapperDefaultBindings;
00044 
00045 class Keymapper : public Common::EventMapper {
00046 public:
00047 
00048     Keymapper(EventManager *eventMan);
00049     ~Keymapper();
00050 
00051     // EventMapper interface
00052     virtual List<Event> mapEvent(const Event &ev);
00053 
00059     void registerHardwareInputSet(HardwareInputSet *inputs, KeymapperDefaultBindings *backendDefaultBindings);
00060 
00068     void addGlobalKeymap(Keymap *keymap);
00069 
00078     void addGameKeymap(Keymap *keymap);
00079 
00084     void cleanupGameKeymaps();
00085 
00091     Keymap *getKeymap(const String &id) const;
00092 
00096     const KeymapArray &getKeymaps() const { return _keymaps; }
00097 
00101     void reloadAllMappings();
00102 
00108     void setEnabledKeymapType(Keymap::KeymapType type);
00109 
00113     void setEnabled(bool enabled) { _enabled = enabled; }
00114 
00118     void clear();
00119 
00123     HardwareInput findHardwareInput(const Event &event);
00124 
00125     void initKeymap(Keymap *keymap, ConfigManager::Domain *domain);
00126     void reloadKeymapMappings(Keymap *keymap);
00127 
00128 private:
00129     EventManager *_eventMan;
00130     HardwareInputSet *_hardwareInputs;
00131     KeymapperDefaultBindings *_backendDefaultBindings;
00132     DelayedEventSource *_delayedEventSource;
00133 
00134     enum IncomingEventType {
00135         kIncomingEventIgnored,
00136         kIncomingEventStart,
00137         kIncomingEventEnd,
00138         kIncomingEventInstant
00139     };
00140 
00141     enum {
00142         kJoyAxisPressedTreshold   = Common::JOYAXIS_MAX / 2,
00143         kJoyAxisUnpressedTreshold = Common::JOYAXIS_MAX / 4
00144     };
00145 
00146     bool _enabled;
00147     Keymap::KeymapType _enabledKeymapType;
00148 
00149     KeymapArray _keymaps;
00150 
00151     bool _joystickAxisPreviouslyPressed[6];
00152 
00153     Keymap::KeymapMatch getMappedActions(const Event &event, Keymap::ActionArray &actions, Keymap::KeymapType keymapType) const;
00154     Event executeAction(const Action *act, const Event &incomingEvent);
00155     EventType convertStartToEnd(EventType eventType);
00156     IncomingEventType convertToIncomingEventType(const Event &ev) const;
00157 
00158     void hardcodedEventMapping(Event ev);
00159     void resetInputState();
00160 };
00161 
00162 class DelayedEventSource : public EventSource {
00163 public:
00164     // EventSource API
00165     bool pollEvent(Event &event) override;
00166     bool allowMapping() const override;
00167 
00171     void scheduleEvent(const Event &ev, uint32 delayMillis);
00172 
00173 private:
00174     struct DelayedEventsEntry {
00175         const uint32 timerOffset;
00176         const Event event;
00177         DelayedEventsEntry(const uint32 offset, const Event ev) : timerOffset(offset), event(ev) { }
00178     };
00179 
00180     Queue<DelayedEventsEntry> _delayedEvents;
00181     uint32 _delayedEffectiveTime;
00182 };
00183 
00184 } // End of namespace Common
00185 
00186 #endif // #ifndef COMMON_KEYMAPPER_H


Generated on Sat Aug 1 2020 05:01:03 for ResidualVM by doxygen 1.7.1
curved edge   curved edge