aboutsummaryrefslogtreecommitdiff
path: root/backends/common/hardware-key.h
diff options
context:
space:
mode:
authorStephen Kennedy2008-07-21 00:11:25 +0000
committerStephen Kennedy2008-07-21 00:11:25 +0000
commit757ed1a0945334162d253f819deb6ddd1ee18037 (patch)
treeb3bac6e2eb26c99a0e71816547996777e1406ce3 /backends/common/hardware-key.h
parent4c730401fea19d9fd32c2408315d3c3e788ff1fa (diff)
downloadscummvm-rg350-757ed1a0945334162d253f819deb6ddd1ee18037.tar.gz
scummvm-rg350-757ed1a0945334162d253f819deb6ddd1ee18037.tar.bz2
scummvm-rg350-757ed1a0945334162d253f819deb6ddd1ee18037.zip
Moved UserAction and HardwareKey classes into their own respective header files.
Added HardwareKeySet class to manage a devices set of hardware keys. Started implementing Keymapper class. svn-id: r33157
Diffstat (limited to 'backends/common/hardware-key.h')
-rw-r--r--backends/common/hardware-key.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/backends/common/hardware-key.h b/backends/common/hardware-key.h
new file mode 100644
index 0000000000..de1984dc31
--- /dev/null
+++ b/backends/common/hardware-key.h
@@ -0,0 +1,95 @@
+#ifndef COMMON_HARDWAREKEY
+#define COMMON_HARDWAREKEY
+
+#include "backends/common/user-action.h"
+
+namespace Common {
+
+/**
+* Describes an available hardware key
+*/
+struct HardwareKey {
+ /** unique id used for saving/loading to config */
+ int32 id;
+ /** Human readable description */
+ String description;
+ /**
+ * The KeyState that is generated by the back-end
+ * when this hardware key is pressed.
+ */
+ KeyState key;
+
+ UserActionCategory preferredCategory;
+ UserActionType preferredType;
+ int16 group;
+
+ HardwareKey(KeyState ks = KeyState(), String des = "",
+ UserActionCategory cat = kGenericUserActionCategory,
+ UserActionType ty = kGenericUserActionType, int gr = 0) {
+ key = ks;
+ description = des;
+ preferredCategory = cat;
+ preferredType = ty;
+ group = gr;
+ }
+};
+
+
+/**
+ * Simple class to encapsulate a device's set of HardwareKeys.
+ * Each device should extend this and call addHardwareKey a number of times
+ * in its constructor to define the device's available keys.
+ */
+class HardwareKeySet {
+public:
+
+ HardwareKeySet() {}
+ ~HardwareKeySet() {
+ List<HardwareKey*>::iterator it;
+ for (it = _keys.begin(); it != _keys.end(); it++)
+ delete *it;
+ }
+
+ void addHardwareKey(HardwareKey *key) {
+ checkForKey(key);
+ _keys.push_back(key);
+ }
+
+ const HardwareKey *findHardwareKey(int32 id) const {
+ List<HardwareKey*>::iterator it;
+ for (it = _keys.begin(); it != _keys.end(); it++) {
+ if ((*it)->id == id)
+ return (*it);
+ }
+ return 0;
+ }
+
+ const HardwareKey *findHardwareKey(const KeyState& keystate) const {
+ List<HardwareKey*>::iterator it;
+ for (it = _keys.begin(); it != _keys.end(); it++) {
+ if ((*it)->key == keystate)
+ return (*it);
+ }
+ return 0;
+ }
+
+
+private:
+
+ void checkForKey(HardwareKey *key) {
+ List<HardwareKey*>::iterator it;
+ for (it = _keys.begin(); it != _keys.end(); it++) {
+ if ((*it)->id == key->id)
+ error("HardwareKey with id %d already given!\n", key->id);
+ else if ((*it)->key == key->key)
+ error("HardwareKey with same KeyState already given!\n");
+ }
+ }
+
+ List<HardwareKey*> _keys;
+};
+
+
+} // end of namespace Common
+
+#endif \ No newline at end of file