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

keymap.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_KEYMAP_H
00024 #define COMMON_KEYMAP_H
00025 
00026 #include "common/scummsys.h"
00027 
00028 #include "backends/keymapper/hardware-input.h"
00029 
00030 #include "common/config-manager.h"
00031 #include "common/func.h"
00032 #include "common/hashmap.h"
00033 #include "common/hash-ptr.h"
00034 #include "common/list.h"
00035 #include "common/str-array.h"
00036 
00037 namespace Common {
00038 
00039 const char *const kStandardActionsKeymapName = "standard-actions";
00040 
00041 struct Action;
00042 struct Event;
00043 struct HardwareInput;
00044 class HardwareInputSet;
00045 class KeymapperDefaultBindings;
00046 
00047 struct HardwareInput_EqualTo {
00048     bool operator()(const HardwareInput& x, const HardwareInput& y) const {
00049         return (x.type == y.type)
00050                 && (x.key.keycode == y.key.keycode)
00051                 && (x.key.flags == y.key.flags)
00052                 && (x.inputCode == y.inputCode);
00053     }
00054 };
00055 
00056 struct HardwareInput_Hash {
00057     uint operator()(const HardwareInput& x) const {
00058         uint hash = 7;
00059         hash = 31 * hash + x.type;
00060         hash = 31 * hash + x.key.keycode;
00061         hash = 31 * hash + x.key.flags;
00062         hash = 31 * hash + x.inputCode;
00063         return hash;
00064     }
00065 };
00066 
00067 class Keymap {
00068 public:
00069     enum KeymapType {
00070         kKeymapTypeGlobal,
00071         kKeymapTypeGui,
00072         kKeymapTypeGame
00073     };
00074 
00075     typedef Array<Action *> ActionArray;
00076 
00077     Keymap(KeymapType type, const String &id, const String &description);
00078     ~Keymap();
00079     void setConfigDomain(ConfigManager::Domain *configDomain);
00080     void setHardwareInputs(HardwareInputSet *hardwareInputSet);
00081     void setBackendDefaultBindings(const KeymapperDefaultBindings *backendDefaultBindings);
00082 
00089     void registerMapping(Action *action, const HardwareInput &input);
00090 
00096     void unregisterMapping(Action *action);
00097 
00102     void resetMapping(Action *action);
00103 
00107     Array<HardwareInput> getActionMapping(Action *action) const;
00108 
00114     ActionArray getMappedActions(const Event &event) const;
00115 
00123     void addAction(Action *action);
00124 
00128     const ActionArray &getActions() const { return _actions; }
00129 
00136     StringArray getActionDefaultMappings(Action *action);
00137 
00142     void loadMappings();
00143 
00148     void saveMappings();
00149 
00150     const String &getId() const { return _id; }
00151     const String &getDescription() const { return _description; }
00152     KeymapType getType() const { return _type; }
00153 
00157     bool isEnabled() const { return _enabled; }
00158     void setEnabled(bool enabled) { _enabled = enabled; }
00159 
00161     static Array<Keymap *> arrayOf(Keymap *keymap) {
00162         return Array<Keymap *>(1, keymap);
00163     }
00164 
00165 private:
00166 
00167     const Action *findAction(const char *id) const;
00168 
00169     void registerMappings(Action *action, const StringArray &hwInputIds);
00170     bool areMappingsIdentical(const Array<HardwareInput> &inputs, const StringArray &mapping);
00171 
00172     typedef HashMap<HardwareInput, ActionArray, HardwareInput_Hash, HardwareInput_EqualTo> HardwareActionMap;
00173 
00174     KeymapType _type;
00175     String _id;
00176     String _description;
00177 
00178     bool _enabled;
00179 
00180     ActionArray _actions;
00181     HardwareActionMap _hwActionMap;
00182 
00183     ConfigManager::Domain *_configDomain;
00184     HardwareInputSet *_hardwareInputSet;
00185     const KeymapperDefaultBindings *_backendDefaultBindings;
00186 };
00187 
00188 typedef Array<Keymap *> KeymapArray;
00189 
00190 } // End of namespace Common
00191 
00192 #endif // #ifndef COMMON_KEYMAP_H


Generated on Sat May 30 2020 05:00:32 for ResidualVM by doxygen 1.7.1
curved edge   curved edge