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_HARDWARE_KEY_H
27 #define COMMON_HARDWARE_KEY_H
29 #include "common/scummsys.h"
31 #ifdef ENABLE_KEYMAPPER
33 #include "backends/keymapper/types.h"
38 #define HWKEY_ID_SIZE (30)
41 * Describes an available hardware key
44 /** unique id used for saving/loading to config */
45 char hwKeyId
[HWKEY_ID_SIZE
];
47 /** Human readable description */
51 * The KeyState that is generated by the back-end
52 * when this hardware key is pressed.
57 ActionType preferredAction
;
59 HardwareKey(const char *i
, KeyState ky
= KeyState(), String desc
= "",
60 KeyType typ
= kGenericKeyType
, ActionType prefAct
= kGenericActionType
)
61 : key(ky
), description(desc
), type(typ
), preferredAction(prefAct
) {
63 strncpy(hwKeyId
, i
, HWKEY_ID_SIZE
);
69 * Simple class to encapsulate a device's set of HardwareKeys.
70 * Each device should instantiate this and call addHardwareKey a number of times
71 * in its constructor to define the device's available keys.
73 class HardwareKeySet
{
76 virtual ~HardwareKeySet() {
77 List
<const HardwareKey
*>::const_iterator it
;
79 for (it
= _keys
.begin(); it
!= _keys
.end(); it
++)
83 void addHardwareKey(HardwareKey
*key
) {
88 const HardwareKey
*findHardwareKey(const char *id
) const {
89 List
<const HardwareKey
*>::const_iterator it
;
91 for (it
= _keys
.begin(); it
!= _keys
.end(); it
++) {
92 if (strncmp((*it
)->hwKeyId
, id
, HWKEY_ID_SIZE
) == 0)
98 const HardwareKey
*findHardwareKey(const KeyState
& keystate
) const {
99 List
<const HardwareKey
*>::const_iterator it
;
101 for (it
= _keys
.begin(); it
!= _keys
.end(); it
++) {
102 if ((*it
)->key
== keystate
)
108 const List
<const HardwareKey
*> &getHardwareKeys() const {
119 void checkForKey(HardwareKey
*key
) {
120 List
<const HardwareKey
*>::iterator it
;
122 for (it
= _keys
.begin(); it
!= _keys
.end(); it
++) {
123 if (strncmp((*it
)->hwKeyId
, key
->hwKeyId
, HWKEY_ID_SIZE
) == 0)
124 error("Error adding HardwareKey '%s' - id of %s already in use!", key
->description
.c_str(), key
->hwKeyId
);
125 else if ((*it
)->key
== key
->key
)
126 error("Error adding HardwareKey '%s' - key already in use!", key
->description
.c_str());
130 List
<const HardwareKey
*> _keys
;
134 } // end of namespace Common
136 #endif // #ifdef ENABLE_KEYMAPPER
138 #endif // #ifndef COMMON_HARDWARE_KEY_H