summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2014-09-12 23:44:25 +0200
committerbunnei <bunneidev@gmail.com>2014-09-12 23:44:25 +0200
commitcbdf4d4c8e11f8d1503b440eee1ed2d5f144a73f (patch)
treec9c95671835d73b5ca7e52029de5bb27832e11a3 /src/common
parentMerge pull request #99 from archshift/ext-check (diff)
parentAdded support for multiple input device types for KeyMap and connected Qt. (diff)
downloadyuzu-cbdf4d4c8e11f8d1503b440eee1ed2d5f144a73f.tar
yuzu-cbdf4d4c8e11f8d1503b440eee1ed2d5f144a73f.tar.gz
yuzu-cbdf4d4c8e11f8d1503b440eee1ed2d5f144a73f.tar.bz2
yuzu-cbdf4d4c8e11f8d1503b440eee1ed2d5f144a73f.tar.lz
yuzu-cbdf4d4c8e11f8d1503b440eee1ed2d5f144a73f.tar.xz
yuzu-cbdf4d4c8e11f8d1503b440eee1ed2d5f144a73f.tar.zst
yuzu-cbdf4d4c8e11f8d1503b440eee1ed2d5f144a73f.zip
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt3
-rw-r--r--src/common/emu_window.cpp17
-rw-r--r--src/common/emu_window.h8
-rw-r--r--src/common/key_map.cpp25
-rw-r--r--src/common/key_map.h45
5 files changed, 98 insertions, 0 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 3a82f5b80..9d5a90762 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -4,10 +4,12 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scm_rev.cpp.in" "${CMAKE_CURRENT_SOU
set(SRCS
break_points.cpp
console_listener.cpp
+ emu_window.cpp
extended_trace.cpp
file_search.cpp
file_util.cpp
hash.cpp
+ key_map.cpp
log_manager.cpp
math_util.cpp
mem_arena.cpp
@@ -39,6 +41,7 @@ set(HEADERS
file_search.h
file_util.h
hash.h
+ key_map.h
linear_disk_cache.h
log.h
log_manager.h
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 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include "emu_window.h"
+
+void EmuWindow::KeyPressed(KeyMap::HostDeviceKey key) {
+ HID_User::PadState mapped_key = KeyMap::GetPadKey(key);
+
+ HID_User::PadButtonPress(mapped_key);
+}
+
+void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) {
+ HID_User::PadState mapped_key = KeyMap::GetPadKey(key);
+
+ HID_User::PadButtonRelease(mapped_key);
+}
diff --git a/src/common/emu_window.h b/src/common/emu_window.h
index 5e2c33d7a..23f178fdf 100644
--- a/src/common/emu_window.h
+++ b/src/common/emu_window.h
@@ -7,6 +7,8 @@
#include "common/common.h"
#include "common/scm_rev.h"
+#include "common/key_map.h"
+
// Abstraction class used to provide an interface between emulation code and the frontend (e.g. SDL,
// QGLWidget, GLFW, etc...)
class EmuWindow
@@ -32,6 +34,12 @@ public:
/// Releases (dunno if this is the "right" word) the GLFW context from the caller thread
virtual void DoneCurrent() = 0;
+ /// Signals a key press action to the HID module
+ static void KeyPressed(KeyMap::HostDeviceKey key);
+
+ /// Signals a key release action to the HID module
+ static void KeyReleased(KeyMap::HostDeviceKey key);
+
Config GetConfig() const {
return m_config;
}
diff --git a/src/common/key_map.cpp b/src/common/key_map.cpp
new file mode 100644
index 000000000..309caab98
--- /dev/null
+++ b/src/common/key_map.cpp
@@ -0,0 +1,25 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include "key_map.h"
+#include <map>
+
+namespace KeyMap {
+
+static std::map<HostDeviceKey, HID_User::PadState> key_map;
+static int next_device_id = 0;
+
+int NewDeviceId() {
+ return next_device_id++;
+}
+
+void SetKeyMapping(HostDeviceKey key, HID_User::PadState padState) {
+ key_map[key].hex = padState.hex;
+}
+
+HID_User::PadState GetPadKey(HostDeviceKey key) {
+ return key_map[key];
+}
+
+}
diff --git a/src/common/key_map.h b/src/common/key_map.h
new file mode 100644
index 000000000..b5acfbab0
--- /dev/null
+++ b/src/common/key_map.h
@@ -0,0 +1,45 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "core/hle/service/hid.h"
+
+namespace KeyMap {
+
+/**
+ * Represents a key for a specific host device.
+ */
+struct HostDeviceKey {
+ int key_code;
+ int device_id; ///< Uniquely identifies a host device
+
+ bool operator < (const HostDeviceKey &other) const {
+ if (device_id == other.device_id) {
+ return key_code < other.key_code;
+ }
+ return device_id < other.device_id;
+ }
+
+ bool operator == (const HostDeviceKey &other) const {
+ return device_id == other.device_id && key_code == other.key_code;
+ }
+};
+
+/**
+ * Generates a new device id, which uniquely identifies a host device within KeyMap.
+ */
+int NewDeviceId();
+
+/**
+ * Maps a device-specific key to a PadState.
+ */
+void SetKeyMapping(HostDeviceKey key, HID_User::PadState padState);
+
+/**
+ * Gets the PadState that's mapped to the provided device-specific key.
+ */
+HID_User::PadState GetPadKey(HostDeviceKey key);
+
+}