summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorGravatar Kevin Hartman2014-09-08 21:46:02 -0700
committerGravatar Kevin Hartman2014-09-12 01:15:14 -0700
commit02fd19b2f60f4db8a683734e4300d7498c861309 (patch)
treec9c95671835d73b5ca7e52029de5bb27832e11a3 /src/common
parentInitial HID PAD work, with GLFW only. (diff)
downloadyuzu-02fd19b2f60f4db8a683734e4300d7498c861309.tar.gz
yuzu-02fd19b2f60f4db8a683734e4300d7498c861309.tar.xz
yuzu-02fd19b2f60f4db8a683734e4300d7498c861309.zip
Added support for multiple input device types for KeyMap and connected Qt.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/emu_window.cpp17
-rw-r--r--src/common/emu_window.h19
-rw-r--r--src/common/key_map.cpp18
-rw-r--r--src/common/key_map.h46
5 files changed, 61 insertions, 40 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 4ae34bea9..9d5a90762 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -4,6 +4,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scm_rev.cpp.in" "${CMAKE_CURRENT_SOU
4set(SRCS 4set(SRCS
5 break_points.cpp 5 break_points.cpp
6 console_listener.cpp 6 console_listener.cpp
7 emu_window.cpp
7 extended_trace.cpp 8 extended_trace.cpp
8 file_search.cpp 9 file_search.cpp
9 file_util.cpp 10 file_util.cpp
diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp
new file mode 100644
index 000000000..7a2c50ac8
--- /dev/null
+++ b/src/common/emu_window.cpp
@@ -0,0 +1,17 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include "emu_window.h"
6
7void EmuWindow::KeyPressed(KeyMap::HostDeviceKey key) {
8 HID_User::PadState mapped_key = KeyMap::GetPadKey(key);
9
10 HID_User::PadButtonPress(mapped_key);
11}
12
13void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) {
14 HID_User::PadState mapped_key = KeyMap::GetPadKey(key);
15
16 HID_User::PadButtonRelease(mapped_key);
17}
diff --git a/src/common/emu_window.h b/src/common/emu_window.h
index 90fbd9335..23f178fdf 100644
--- a/src/common/emu_window.h
+++ b/src/common/emu_window.h
@@ -8,7 +8,6 @@
8#include "common/scm_rev.h" 8#include "common/scm_rev.h"
9 9
10#include "common/key_map.h" 10#include "common/key_map.h"
11#include "core/hle/service/hid.h"
12 11
13// Abstraction class used to provide an interface between emulation code and the frontend (e.g. SDL, 12// Abstraction class used to provide an interface between emulation code and the frontend (e.g. SDL,
14// QGLWidget, GLFW, etc...) 13// QGLWidget, GLFW, etc...)
@@ -35,21 +34,11 @@ public:
35 /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread 34 /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread
36 virtual void DoneCurrent() = 0; 35 virtual void DoneCurrent() = 0;
37 36
38 static void KeyPressed(KeyMap::CitraKey key) { 37 /// Signals a key press action to the HID module
39 HID_User::PADState mapped_key = KeyMap::Get3DSKey(key); 38 static void KeyPressed(KeyMap::HostDeviceKey key);
40 39
41 if (mapped_key.hex != HID_User::PAD_NONE.hex) { 40 /// Signals a key release action to the HID module
42 HID_User::PADButtonPress(mapped_key); 41 static void KeyReleased(KeyMap::HostDeviceKey key);
43 }
44 }
45
46 static void KeyReleased(KeyMap::CitraKey key) {
47 HID_User::PADState mapped_key = KeyMap::Get3DSKey(key);
48
49 if (mapped_key.hex != HID_User::PAD_NONE.hex) {
50 HID_User::PADButtonRelease(mapped_key);
51 }
52 }
53 42
54 Config GetConfig() const { 43 Config GetConfig() const {
55 return m_config; 44 return m_config;
diff --git a/src/common/key_map.cpp b/src/common/key_map.cpp
index 5941a105b..309caab98 100644
--- a/src/common/key_map.cpp
+++ b/src/common/key_map.cpp
@@ -1,21 +1,25 @@
1// Copyright 2013 Dolphin Emulator Project 1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2 2// Licensed under GPLv2
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "key_map.h" 5#include "key_map.h"
6#include <map> 6#include <map>
7 7
8
9namespace KeyMap { 8namespace KeyMap {
10 9
11std::map<CitraKey, HID_User::PADState> g_key_map; 10static std::map<HostDeviceKey, HID_User::PadState> key_map;
11static int next_device_id = 0;
12
13int NewDeviceId() {
14 return next_device_id++;
15}
12 16
13void SetKeyMapping(CitraKey key, HID_User::PADState padState) { 17void SetKeyMapping(HostDeviceKey key, HID_User::PadState padState) {
14 g_key_map[key].hex = padState.hex; 18 key_map[key].hex = padState.hex;
15} 19}
16 20
17HID_User::PADState Get3DSKey(CitraKey key) { 21HID_User::PadState GetPadKey(HostDeviceKey key) {
18 return g_key_map[key]; 22 return key_map[key];
19} 23}
20 24
21} 25}
diff --git a/src/common/key_map.h b/src/common/key_map.h
index 7e94df618..b5acfbab0 100644
--- a/src/common/key_map.h
+++ b/src/common/key_map.h
@@ -1,4 +1,4 @@
1// Copyright 2013 Dolphin Emulator Project 1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2 2// Licensed under GPLv2
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
@@ -8,28 +8,38 @@
8 8
9namespace KeyMap { 9namespace KeyMap {
10 10
11class CitraKey { 11/**
12public: 12 * Represents a key for a specific host device.
13 CitraKey() : keyCode(0) {} 13 */
14 CitraKey(int code) : keyCode(code) {} 14struct HostDeviceKey {
15 15 int key_code;
16 int keyCode; 16 int device_id; ///< Uniquely identifies a host device
17 17
18 bool operator < (const CitraKey &other) const { 18 bool operator < (const HostDeviceKey &other) const {
19 return keyCode < other.keyCode; 19 if (device_id == other.device_id) {
20 return key_code < other.key_code;
21 }
22 return device_id < other.device_id;
20 } 23 }
21 24
22 bool operator == (const CitraKey &other) const { 25 bool operator == (const HostDeviceKey &other) const {
23 return keyCode == other.keyCode; 26 return device_id == other.device_id && key_code == other.key_code;
24 } 27 }
25}; 28};
26 29
27struct DefaultKeyMapping { 30/**
28 KeyMap::CitraKey key; 31 * Generates a new device id, which uniquely identifies a host device within KeyMap.
29 HID_User::PADState state; 32 */
30}; 33int NewDeviceId();
34
35/**
36 * Maps a device-specific key to a PadState.
37 */
38void SetKeyMapping(HostDeviceKey key, HID_User::PadState padState);
31 39
32void SetKeyMapping(CitraKey key, HID_User::PADState padState); 40/**
33HID_User::PADState Get3DSKey(CitraKey key); 41 * Gets the PadState that's mapped to the provided device-specific key.
42 */
43HID_User::PadState GetPadKey(HostDeviceKey key);
34 44
35} 45}