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_KEYMAPPER
|
|
|
|
#define COMMON_KEYMAPPER
|
|
|
|
|
2008-07-24 10:00:56 +00:00
|
|
|
#include "common/events.h"
|
2008-07-21 00:11:25 +00:00
|
|
|
#include "common/list.h"
|
2008-08-06 14:21:05 +00:00
|
|
|
#include "common/stack.h"
|
2008-08-07 16:38:39 +00:00
|
|
|
#include "backends/keymapper/hardware-key.h"
|
|
|
|
#include "backends/keymapper/keymap.h"
|
|
|
|
#include "backends/keymapper/keymap-manager.h"
|
2008-07-24 10:00:56 +00:00
|
|
|
|
2008-07-19 00:57:37 +00:00
|
|
|
namespace Common {
|
|
|
|
|
|
|
|
class Keymapper {
|
|
|
|
public:
|
2008-08-13 19:24:52 +00:00
|
|
|
|
|
|
|
struct MapRecord {
|
|
|
|
Keymap* keymap;
|
|
|
|
bool inherit;
|
2008-08-14 01:42:02 +00:00
|
|
|
bool global;
|
2008-08-13 19:24:52 +00:00
|
|
|
};
|
2008-07-19 00:57:37 +00:00
|
|
|
|
2008-07-21 00:11:25 +00:00
|
|
|
Keymapper(EventManager *eventMan);
|
2008-08-06 14:21:05 +00:00
|
|
|
~Keymapper();
|
2008-07-19 00:57:37 +00:00
|
|
|
|
2008-07-23 08:45:12 +00:00
|
|
|
/**
|
|
|
|
* Registers a HardwareKeySet with the Keymapper
|
|
|
|
* @note should only be called once (during backend initialisation)
|
|
|
|
*/
|
2008-07-21 00:11:25 +00:00
|
|
|
void registerHardwareKeySet(HardwareKeySet *keys);
|
2008-07-21 15:55:25 +00:00
|
|
|
|
2008-08-06 14:21:05 +00:00
|
|
|
|
2008-07-23 08:45:12 +00:00
|
|
|
/**
|
2008-08-08 14:23:59 +00:00
|
|
|
* Add a keymap to the global domain.
|
2008-07-23 08:45:12 +00:00
|
|
|
* If a saved key setup exists for it in the ini file it will be used.
|
|
|
|
* Else, the key setup will be automatically mapped.
|
|
|
|
*/
|
2008-08-08 14:23:59 +00:00
|
|
|
void addGlobalKeymap(Keymap *keymap);
|
2008-07-21 15:55:25 +00:00
|
|
|
|
2008-07-23 08:45:12 +00:00
|
|
|
/**
|
2008-08-14 01:42:02 +00:00
|
|
|
* Add a keymap to the game domain.
|
|
|
|
* @see addGlobalKeyMap
|
|
|
|
* @note initGame() should be called before any game keymaps are added.
|
|
|
|
*/
|
2008-08-08 14:23:59 +00:00
|
|
|
void addGameKeymap(Keymap *keymap);
|
2008-08-06 14:21:05 +00:00
|
|
|
|
2008-08-14 01:42:02 +00:00
|
|
|
/**
|
|
|
|
* Should be called at end of game to tell Keymapper to deactivate and free
|
|
|
|
* any game keymaps that are loaded.
|
|
|
|
*/
|
|
|
|
void cleanupGameKeymaps();
|
2008-08-06 14:21:05 +00:00
|
|
|
/**
|
2008-08-08 14:23:59 +00:00
|
|
|
* Push a new keymap to the top of the active stack, activating
|
|
|
|
* it for use.
|
2008-08-06 14:21:05 +00:00
|
|
|
* @param name name of the keymap to push
|
2008-08-08 14:23:59 +00:00
|
|
|
* @param inherit if true keymapper will iterate down the
|
|
|
|
* stack it cannot find a key in the new map
|
|
|
|
* @return true if succesful
|
2008-07-23 08:45:12 +00:00
|
|
|
*/
|
2008-08-06 14:21:05 +00:00
|
|
|
bool pushKeymap(const String& name, bool inherit = false);
|
|
|
|
|
|
|
|
/**
|
2008-08-08 14:23:59 +00:00
|
|
|
* Pop the top keymap off the active stack.
|
2008-08-06 14:21:05 +00:00
|
|
|
*/
|
|
|
|
void popKeymap();
|
2008-07-19 00:57:37 +00:00
|
|
|
|
2008-07-23 08:45:12 +00:00
|
|
|
/**
|
|
|
|
* @brief Map a key press event.
|
2008-08-01 16:44:49 +00:00
|
|
|
* If the active keymap contains a Action mapped to the given key, then
|
|
|
|
* the Action's events are pushed into the EventManager's event queue.
|
2008-08-06 14:21:05 +00:00
|
|
|
* @param key key that was pressed
|
|
|
|
* @param isKeyDown true for key down, false for key up
|
|
|
|
* @return true if key was mapped
|
2008-07-23 08:45:12 +00:00
|
|
|
*/
|
|
|
|
bool mapKey(const KeyState& key, bool isKeyDown);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Map a key down event.
|
|
|
|
* @see mapKey
|
|
|
|
*/
|
|
|
|
bool mapKeyDown(const KeyState& key);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Map a key up event.
|
|
|
|
* @see mapKey
|
|
|
|
*/
|
|
|
|
bool mapKeyUp(const KeyState& key);
|
|
|
|
|
2008-08-08 14:23:59 +00:00
|
|
|
const HardwareKey *getHardwareKey(const KeyState& key);
|
|
|
|
|
|
|
|
void setEnabled(bool enabled) { _enabled = enabled; }
|
|
|
|
|
2008-08-13 19:24:52 +00:00
|
|
|
KeymapManager *getManager() { return _keymapMan; }
|
|
|
|
Stack<MapRecord>& getActiveStack() { return _activeMaps; }
|
|
|
|
|
2008-07-19 00:57:37 +00:00
|
|
|
private:
|
|
|
|
|
2008-08-14 01:42:02 +00:00
|
|
|
void pushKeymap(Keymap *newMap, bool inherit, bool global);
|
2008-08-06 14:21:05 +00:00
|
|
|
|
2008-07-21 00:11:25 +00:00
|
|
|
typedef List<HardwareKey*>::iterator Iterator;
|
|
|
|
|
|
|
|
EventManager *_eventMan;
|
|
|
|
KeymapManager *_keymapMan;
|
|
|
|
|
2008-08-08 14:23:59 +00:00
|
|
|
bool _enabled;
|
2008-07-21 15:55:25 +00:00
|
|
|
|
2008-08-06 14:21:05 +00:00
|
|
|
Stack<MapRecord> _activeMaps;
|
2008-07-19 00:57:37 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2008-07-19 19:12:49 +00:00
|
|
|
} // end of namespace Common
|
|
|
|
|
2008-07-30 13:47:54 +00:00
|
|
|
#endif
|