summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorGravatar Kevin Hartman2014-09-03 18:12:58 -0700
committerGravatar Kevin Hartman2014-09-11 22:43:42 -0700
commit4a94ec934ab1a2216f94e3fcc46f5dde1d6e2f02 (patch)
tree2588f0c6051c9a5e3f23057d2953c35a854dbc43 /src/common
parentCreated structure for PAD. (diff)
downloadyuzu-4a94ec934ab1a2216f94e3fcc46f5dde1d6e2f02.tar.gz
yuzu-4a94ec934ab1a2216f94e3fcc46f5dde1d6e2f02.tar.xz
yuzu-4a94ec934ab1a2216f94e3fcc46f5dde1d6e2f02.zip
Initial HID PAD work, with GLFW only.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt2
-rw-r--r--src/common/emu_window.h19
-rw-r--r--src/common/key_map.cpp21
-rw-r--r--src/common/key_map.h35
4 files changed, 77 insertions, 0 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 3a82f5b80..4ae34bea9 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -8,6 +8,7 @@ set(SRCS
8 file_search.cpp 8 file_search.cpp
9 file_util.cpp 9 file_util.cpp
10 hash.cpp 10 hash.cpp
11 key_map.cpp
11 log_manager.cpp 12 log_manager.cpp
12 math_util.cpp 13 math_util.cpp
13 mem_arena.cpp 14 mem_arena.cpp
@@ -39,6 +40,7 @@ set(HEADERS
39 file_search.h 40 file_search.h
40 file_util.h 41 file_util.h
41 hash.h 42 hash.h
43 key_map.h
42 linear_disk_cache.h 44 linear_disk_cache.h
43 log.h 45 log.h
44 log_manager.h 46 log_manager.h
diff --git a/src/common/emu_window.h b/src/common/emu_window.h
index 5e2c33d7a..90fbd9335 100644
--- a/src/common/emu_window.h
+++ b/src/common/emu_window.h
@@ -7,6 +7,9 @@
7#include "common/common.h" 7#include "common/common.h"
8#include "common/scm_rev.h" 8#include "common/scm_rev.h"
9 9
10#include "common/key_map.h"
11#include "core/hle/service/hid.h"
12
10// Abstraction class used to provide an interface between emulation code and the frontend (e.g. SDL, 13// Abstraction class used to provide an interface between emulation code and the frontend (e.g. SDL,
11// QGLWidget, GLFW, etc...) 14// QGLWidget, GLFW, etc...)
12class EmuWindow 15class EmuWindow
@@ -32,6 +35,22 @@ public:
32 /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread 35 /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread
33 virtual void DoneCurrent() = 0; 36 virtual void DoneCurrent() = 0;
34 37
38 static void KeyPressed(KeyMap::CitraKey key) {
39 HID_User::PADState mapped_key = KeyMap::Get3DSKey(key);
40
41 if (mapped_key.hex != HID_User::PAD_NONE.hex) {
42 HID_User::PADButtonPress(mapped_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
35 Config GetConfig() const { 54 Config GetConfig() const {
36 return m_config; 55 return m_config;
37 } 56 }
diff --git a/src/common/key_map.cpp b/src/common/key_map.cpp
new file mode 100644
index 000000000..5941a105b
--- /dev/null
+++ b/src/common/key_map.cpp
@@ -0,0 +1,21 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include "key_map.h"
6#include <map>
7
8
9namespace KeyMap {
10
11std::map<CitraKey, HID_User::PADState> g_key_map;
12
13void SetKeyMapping(CitraKey key, HID_User::PADState padState) {
14 g_key_map[key].hex = padState.hex;
15}
16
17HID_User::PADState Get3DSKey(CitraKey key) {
18 return g_key_map[key];
19}
20
21}
diff --git a/src/common/key_map.h b/src/common/key_map.h
new file mode 100644
index 000000000..7e94df618
--- /dev/null
+++ b/src/common/key_map.h
@@ -0,0 +1,35 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "core/hle/service/hid.h"
8
9namespace KeyMap {
10
11class CitraKey {
12public:
13 CitraKey() : keyCode(0) {}
14 CitraKey(int code) : keyCode(code) {}
15
16 int keyCode;
17
18 bool operator < (const CitraKey &other) const {
19 return keyCode < other.keyCode;
20 }
21
22 bool operator == (const CitraKey &other) const {
23 return keyCode == other.keyCode;
24 }
25};
26
27struct DefaultKeyMapping {
28 KeyMap::CitraKey key;
29 HID_User::PADState state;
30};
31
32void SetKeyMapping(CitraKey key, HID_User::PADState padState);
33HID_User::PADState Get3DSKey(CitraKey key);
34
35}