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 #ifdef ENABLE_KEYMAPPER
00029 
00030 #include "common/events.h"
00031 #include "common/list.h"
00032 #include "common/hashmap.h"
00033 #include "common/stack.h"
00034 #include "backends/keymapper/hardware-input.h"
00035 #include "backends/keymapper/keymap.h"
00036 
00037 namespace Common {
00038 
00039 const char *const kGuiKeymapName = "gui";
00040 const char *const kGlobalKeymapName = "global";
00041 
00042 class Keymapper : public Common::DefaultEventMapper {
00043 public:
00044 
00045     struct MapRecord {
00046         Keymap* keymap;
00047         bool transparent;
00048         bool global;
00049     };
00050 
00051     /* Nested class that represents a set of keymaps */
00052     class Domain : public HashMap<String, Keymap*,
00053                 IgnoreCase_Hash, IgnoreCase_EqualTo>  {
00054     public:
00055         Domain() : _configDomain(0) {}
00056         ~Domain() {
00057             deleteAllKeyMaps();
00058         }
00059 
00060         void setConfigDomain(ConfigManager::Domain *confDom) {
00061             _configDomain = confDom;
00062         }
00063         ConfigManager::Domain *getConfigDomain() {
00064             return _configDomain;
00065         }
00066 
00067         void addKeymap(Keymap *map);
00068 
00069         void deleteAllKeyMaps();
00070 
00071         Keymap *getKeymap(const String& name);
00072 
00073     private:
00074         ConfigManager::Domain *_configDomain;
00075     };
00076 
00077     Keymapper(EventManager *eventMan);
00078     ~Keymapper();
00079 
00080     // EventMapper interface
00081     virtual List<Event> mapEvent(const Event &ev, EventSource *source);
00082 
00087     void registerHardwareInputSet(HardwareInputSet *inputs);
00088 
00092     const List<const HardwareInput *> &getHardwareInputs() const {
00093         assert(_hardwareInputs);
00094         return _hardwareInputs->getHardwareInputs();
00095     }
00096 
00102     void addGlobalKeymap(Keymap *keymap);
00103 
00109     void addGameKeymap(Keymap *keymap);
00110 
00115     void cleanupGameKeymaps();
00116 
00123     Keymap *getKeymap(const String& name, bool *global = 0);
00124 
00133     bool pushKeymap(const String& name, bool transparent = false);
00134 
00141     void popKeymap(const char *name = 0);
00142 
00151     List<Event> mapKey(const KeyState& key, bool keyDown);
00152     List<Event> mapNonKey(const HardwareInputCode code);
00153 
00158     List<Event> mapKeyDown(const KeyState& key);
00159 
00164     List<Event> mapKeyUp(const KeyState& key);
00165 
00169     void setEnabled(bool enabled) { _enabled = enabled; }
00170 
00177     void startRemappingMode(Action *actionToRemap);
00178 
00182     void stopRemappingMode() { _remapping = false; }
00183 
00187     bool isRemapping() const { return _remapping; }
00188 
00192     const HardwareInput *findHardwareInput(const KeyState& key);
00193 
00197     const HardwareInput *findHardwareInput(const HardwareInputCode code);
00198 
00199     Domain& getGlobalDomain() { return _globalDomain; }
00200     Domain& getGameDomain() { return _gameDomain; }
00201     const Stack<MapRecord>& getActiveStack() const { return _activeMaps; }
00202 
00203 private:
00204 
00205     enum IncomingEventType {
00206         kIncomingKeyDown,
00207         kIncomingKeyUp,
00208         kIncomingNonKey
00209     };
00210 
00211     void initKeymap(Domain &domain, Keymap *keymap);
00212 
00213     Domain _globalDomain;
00214     Domain _gameDomain;
00215 
00216     HardwareInputSet *_hardwareInputs;
00217 
00218     void pushKeymap(Keymap *newMap, bool transparent, bool global);
00219 
00220     Action *getAction(const KeyState& key);
00221     List<Event> executeAction(const Action *act, IncomingEventType incomingType = kIncomingNonKey);
00222     EventType convertDownToUp(EventType eventType);
00223     List<Event> remap(const Event &ev);
00224 
00225     EventManager *_eventMan;
00226 
00227     bool _enabled;
00228     bool _remapping;
00229 
00230     Action *_actionToRemap;
00231     Stack<MapRecord> _activeMaps;
00232     HashMap<KeyState, Action *> _keysDown;
00233 
00234 };
00235 
00236 } // End of namespace Common
00237 
00238 #endif // #ifdef ENABLE_KEYMAPPER
00239 
00240 #endif // #ifndef COMMON_KEYMAPPER_H


Generated on Sat Jul 13 2019 05:00:54 for ResidualVM by doxygen 1.7.1
curved edge   curved edge