1 /* ScummVM - Graphic Adventure Engine
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.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #ifndef COMMON_KEYMAP_H
27 #define COMMON_KEYMAP_H
29 #include "common/scummsys.h"
31 #ifdef ENABLE_KEYMAPPER
33 #include "common/config-manager.h"
34 #include "common/func.h"
35 #include "common/hashmap.h"
36 #include "common/keyboard.h"
37 #include "common/list.h"
38 #include "backends/keymapper/action.h"
46 * Hash function for KeyState
48 template<> struct Hash
<KeyState
>
49 : public UnaryFunction
<KeyState
, uint
> {
51 uint
operator()(const KeyState
&val
) const {
52 return (uint
)val
.keycode
| ((uint
)val
.flags
<< 24);
58 Keymap(const String
& name
, Keymap
*parent
= 0) : _name(name
), _parent(parent
) {}
59 Keymap(const Keymap
& km
);
64 * Retrieves the Action with the given id
65 * @param id id of Action to retrieve
66 * @return Pointer to the Action or 0 if not found
68 Action
*getAction(const char *id
);
71 * Get the list of all the Actions contained in this Keymap
73 List
<Action
*>& getActions() { return _actions
; }
76 * Find the Action that a key is mapped to
77 * @param key the key that is mapped to the required Action
78 * @return a pointer to the Action or 0 if no
80 Action
*getMappedAction(const KeyState
& ks
) const;
82 void setConfigDomain(ConfigManager::Domain
*dom
);
85 * Load this keymap's mappings from the config manager.
86 * @param hwKeys the set to retrieve hardware key pointers from
88 void loadMappings(const HardwareKeySet
*hwKeys
);
91 * Save this keymap's mappings to the config manager
92 * @note Changes are *not* flushed to disk, to do so call ConfMan.flushToDisk()
93 * @note Changes are *not* flushed to disk, to do so call ConfMan.flushToDisk()
98 void automaticMapping(HardwareKeySet
*hwKeys
);
101 * Returns true if all UserAction's in Keymap are mapped, or,
102 * all HardwareKey's from the given set have been used up.
104 bool isComplete(const HardwareKeySet
*hwKeys
);
106 const String
& getName() { return _name
; }
107 Keymap
*getParent() { return _parent
; }
110 friend struct Action
;
113 * Adds a new Action to this Map,
114 * adding it at the back of the internal array
115 * @param action the Action to add
117 void addAction(Action
*action
);
120 * Registers a HardwareKey to the given Action
121 * @param action Action in this Keymap
122 * @param key pointer to HardwareKey to map
123 * @see Action::mapKey
125 void registerMapping(Action
*action
, const HardwareKey
*key
);
128 * Unregisters a HardwareKey from the given Action (if one is mapped)
129 * @param action Action in this Keymap
130 * @see Action::mapKey
132 void unregisterMapping(Action
*action
);
134 Action
*findAction(const char *id
);
135 const Action
*findAction(const char *id
) const;
137 void internalMapKey(Action
*action
, HardwareKey
*hwKey
);
139 Action
*getParentMappedAction(KeyState key
);
143 List
<Action
*> _actions
;
144 HashMap
<KeyState
, Action
*> _keymap
;
145 ConfigManager::Domain
*_configDomain
;
150 } // end of namespace Common
152 #endif // #ifdef ENABLE_KEYMAPPER
154 #endif // #ifndef COMMON_KEYMAP_H