mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-03 12:27:21 +12:00
First step towards configurable keyboard mappings (#464)
* Configurable keyboard mappings * Cleanup * Cleanup * Biggest mistake of my career * format * Fix naming convention --------- Co-authored-by: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com>
This commit is contained in:
parent
5488e9ca7c
commit
3270cfe602
9 changed files with 162 additions and 126 deletions
22
include/input_mappings.hpp
Normal file
22
include/input_mappings.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "helpers.hpp"
|
||||
#include "services/hid.hpp"
|
||||
|
||||
struct InputMappings {
|
||||
using Scancode = u32;
|
||||
using Container = std::unordered_map<Scancode, u32>;
|
||||
|
||||
u32 getMapping(Scancode scancode) const {
|
||||
auto it = container.find(scancode);
|
||||
return it != container.end() ? it->second : HID::Keys::Null;
|
||||
}
|
||||
|
||||
void setMapping(Scancode scancode, u32 key) { container[scancode] = key; }
|
||||
static InputMappings defaultKeyboardMappings();
|
||||
|
||||
private:
|
||||
Container container;
|
||||
};
|
|
@ -11,6 +11,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "emulator.hpp"
|
||||
#include "input_mappings.hpp"
|
||||
#include "panda_qt/about_window.hpp"
|
||||
#include "panda_qt/config_window.hpp"
|
||||
#include "panda_qt/cheats_window.hpp"
|
||||
|
@ -87,6 +88,7 @@ class MainWindow : public QMainWindow {
|
|||
std::mutex messageQueueMutex;
|
||||
std::vector<EmulatorMessage> messageQueue;
|
||||
|
||||
InputMappings keyboardMappings;
|
||||
ScreenWidget screen;
|
||||
AboutWindow* aboutWindow;
|
||||
ConfigWindow* configWindow;
|
||||
|
@ -120,4 +122,4 @@ class MainWindow : public QMainWindow {
|
|||
|
||||
void loadLuaScript(const std::string& code);
|
||||
void editCheat(u32 handle, const std::vector<uint8_t>& cheat, const std::function<void(u32)>& callback);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <filesystem>
|
||||
|
||||
#include "emulator.hpp"
|
||||
#include "input_mappings.hpp"
|
||||
|
||||
class FrontendSDL {
|
||||
Emulator emu;
|
||||
|
@ -16,9 +17,12 @@ class FrontendSDL {
|
|||
FrontendSDL();
|
||||
bool loadROM(const std::filesystem::path& path);
|
||||
void run();
|
||||
u32 getMapping(InputMappings::Scancode scancode) { return keyboardMappings.getMapping(scancode); }
|
||||
|
||||
SDL_Window* window = nullptr;
|
||||
SDL_GameController* gameController = nullptr;
|
||||
InputMappings keyboardMappings;
|
||||
|
||||
int gameControllerID;
|
||||
bool programRunning = true;
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
namespace HID::Keys {
|
||||
enum : u32 {
|
||||
Null = 0,
|
||||
A = 1 << 0,
|
||||
B = 1 << 1,
|
||||
Select = 1 << 2,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue