aboutsummaryrefslogtreecommitdiff
path: root/backends/common/keymapper.h
blob: 3252d336e1fc7bbbad32edb66ad81d4a74c2b028 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef COMMON_KEYMAPPER
#define COMMON_KEYMAPPER

#include "backends/common/keymap.h"
#include "common/list.h"

namespace Common {

class KeymapManager;

class Keymapper {
public:

	Keymapper(EventManager *eventMan);

	/**
	 * Registers a HardwareKeySet with the Keymapper
	 * @note should only be called once (during backend initialisation)
	 */
	void registerHardwareKeySet(HardwareKeySet *keys);

	/**
	 * Get the HardwareKeySet that is registered with the Keymapper
	 */
	const HardwareKeySet *getHardwareKeySet() const;

	/**
	 * Add a keymap to the global domain.
	 * If a saved key setup exists for it in the ini file it will be used.
	 * Else, the key setup will be automatically mapped.
	 */
	void addGlobalKeyMap(const String& name, Keymap *keymap);

	/**
	* Add a keymap to the game domain.
	* @see addGlobalKeyMap
	* @note initGame() should be called before any game keymaps are added.
	*/
	void addGameKeyMap(const String& name, Keymap *keymap);

	/**
	 * Initialise the keymapper for a new game
	 */
	void initGame();

	/**
	 * Cleanup the keymapper after a game has ended
	 */
	void cleanupGame();

	/**
	 * Switch the active keymap.
	 * @param name name of the new keymap
	 * @return true if successful
	 */
	bool switchKeymap(const String& name);

	/**
	* @brief Map a key press event.
	* If the active keymap contains a UserAction mapped to the given key, then 
	* the UserAction's events are pushed into the EventManager's event queue.
	* @param key key that was pressed
	* @param isKeyDown true for key down, false for key up
	* @return true if key was mapped
	*/
	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);

private:

	typedef List<HardwareKey*>::iterator Iterator;

	EventManager *_eventMan;
	KeymapManager *_keymapMan;

	String _gameId;

	Keymap *_currentMap;

	const HardwareKeySet *_hardwareKeys;

};

} // end of namespace Common

#endif