2008-07-30 13:47:54 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-07-19 00:57:37 +00:00
|
|
|
#ifndef COMMON_KEYMAP
|
|
|
|
#define COMMON_KEYMAP
|
|
|
|
|
2008-08-06 19:21:45 +00:00
|
|
|
#include "common/config-manager.h"
|
2008-07-19 00:57:37 +00:00
|
|
|
#include "common/func.h"
|
|
|
|
#include "common/hashmap.h"
|
2008-08-01 16:44:49 +00:00
|
|
|
#include "common/keyboard.h"
|
|
|
|
#include "common/list.h"
|
|
|
|
#include "backends/common/action.h"
|
2008-07-19 00:57:37 +00:00
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
|
2008-07-24 10:00:56 +00:00
|
|
|
struct HardwareKey;
|
2008-08-06 19:21:45 +00:00
|
|
|
class HardwareKeySet;
|
2008-07-24 10:00:56 +00:00
|
|
|
|
2008-07-19 00:57:37 +00:00
|
|
|
/**
|
|
|
|
* Hash function for KeyState
|
|
|
|
*/
|
|
|
|
template<> struct Hash<KeyState>
|
|
|
|
: public UnaryFunction<KeyState, uint> {
|
|
|
|
|
|
|
|
uint operator()(const KeyState &val) const {
|
|
|
|
return (uint)(val.keycode * (val.flags << 1));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Keymap {
|
|
|
|
public:
|
2008-08-01 16:44:49 +00:00
|
|
|
Keymap() {}
|
2008-07-19 00:57:37 +00:00
|
|
|
Keymap(const Keymap& km);
|
|
|
|
|
2008-07-19 19:12:49 +00:00
|
|
|
public:
|
2008-07-19 00:57:37 +00:00
|
|
|
/**
|
2008-08-01 16:44:49 +00:00
|
|
|
* Adds a new Action to this Map,
|
2008-07-19 00:57:37 +00:00
|
|
|
* adding it at the back of the internal array
|
2008-08-01 16:44:49 +00:00
|
|
|
* @param action the Action to add
|
2008-07-19 00:57:37 +00:00
|
|
|
*/
|
2008-08-01 16:44:49 +00:00
|
|
|
void addAction(Action *action);
|
2008-07-19 19:12:49 +00:00
|
|
|
|
|
|
|
/**
|
2008-08-01 16:44:49 +00:00
|
|
|
* Retrieves the Action with the given id
|
|
|
|
* @param id id of Action to retrieve
|
|
|
|
* @return Pointer to the Action or 0 if not found
|
2008-07-19 19:12:49 +00:00
|
|
|
*/
|
2008-08-01 16:44:49 +00:00
|
|
|
Action *getAction(int32 id);
|
2008-07-19 00:57:37 +00:00
|
|
|
|
|
|
|
/**
|
2008-08-01 16:44:49 +00:00
|
|
|
* Get a read-only array of all the Actions contained in this Keymap
|
2008-07-19 00:57:37 +00:00
|
|
|
*/
|
2008-08-01 16:44:49 +00:00
|
|
|
const List<Action*>& getActions() const { return _actions; }
|
2008-07-19 00:57:37 +00:00
|
|
|
|
|
|
|
/**
|
2008-08-01 16:44:49 +00:00
|
|
|
* Find the Action that a key is mapped to
|
2008-08-06 19:21:45 +00:00
|
|
|
* @param key the key that is mapped to the required Action
|
|
|
|
* @return a pointer to the Action or 0 if no
|
2008-07-19 00:57:37 +00:00
|
|
|
*/
|
2008-08-01 16:44:49 +00:00
|
|
|
Action *getMappedAction(const KeyState& ks) const;
|
2008-07-19 00:57:37 +00:00
|
|
|
|
2008-08-06 19:21:45 +00:00
|
|
|
/**
|
|
|
|
* Load this keymap's mappings from the given config domain and hardware key set
|
|
|
|
* @param domain config domain to load keymap from
|
|
|
|
* @param name name of the keymap to load
|
|
|
|
* @param hwKeys the set to retrieve hardware key pointers from
|
|
|
|
*/
|
|
|
|
void loadMappings(ConfigManager::Domain *domain, const String& name, const HardwareKeySet *hwKeys);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save this keymap's mappings to the given config domain
|
|
|
|
* @param domain config domain to save keymap to
|
|
|
|
* @param name name to save the keymap under
|
|
|
|
*/
|
|
|
|
void saveMappings(ConfigManager::Domain *domain, const String& name);
|
|
|
|
|
2008-07-19 00:57:37 +00:00
|
|
|
private:
|
2008-08-01 16:44:49 +00:00
|
|
|
friend struct Action;
|
2008-07-24 10:00:56 +00:00
|
|
|
/**
|
2008-08-01 16:44:49 +00:00
|
|
|
* Registers a HardwareKey to the given Action
|
|
|
|
* @param action Action in this Keymap
|
2008-07-24 10:00:56 +00:00
|
|
|
* @param key pointer to HardwareKey to map
|
2008-08-01 16:44:49 +00:00
|
|
|
* @see Action::mapKey
|
2008-07-24 10:00:56 +00:00
|
|
|
*/
|
2008-08-01 16:44:49 +00:00
|
|
|
void registerMapping(Action *action, const HardwareKey *key);
|
2008-07-24 10:00:56 +00:00
|
|
|
|
|
|
|
/**
|
2008-08-01 16:44:49 +00:00
|
|
|
* Unregisters a HardwareKey from the given Action (if one is mapped)
|
|
|
|
* @param action Action in this Keymap
|
|
|
|
* @see Action::mapKey
|
2008-07-24 10:00:56 +00:00
|
|
|
*/
|
2008-08-01 16:44:49 +00:00
|
|
|
void unregisterMapping(Action *action);
|
2008-07-24 10:00:56 +00:00
|
|
|
|
2008-08-01 16:44:49 +00:00
|
|
|
Action *findAction(int32 id);
|
|
|
|
const Action *findAction(int32 id) const;
|
2008-07-19 00:57:37 +00:00
|
|
|
|
2008-08-01 16:44:49 +00:00
|
|
|
void internalMapKey(Action *action, HardwareKey *hwKey);
|
2008-07-19 00:57:37 +00:00
|
|
|
|
2008-08-01 16:44:49 +00:00
|
|
|
List<Action*> _actions;
|
|
|
|
HashMap<KeyState, Action*> _keymap;
|
2008-07-19 00:57:37 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // end of namespace Common
|
|
|
|
|
2008-07-30 13:47:54 +00:00
|
|
|
#endif
|