mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-06 14:15:41 +12:00
[Qt] Implement circlepad
This commit is contained in:
parent
2229adbd21
commit
e3c9f0b219
2 changed files with 41 additions and 1 deletions
|
@ -30,7 +30,20 @@ class MainWindow : public QMainWindow {
|
|||
|
||||
private:
|
||||
// Types of messages we might send from the GUI thread to the emulator thread
|
||||
enum class MessageType { LoadROM, Reset, Pause, Resume, TogglePause, DumpRomFS, PressKey, ReleaseKey, LoadLuaScript, EditCheat };
|
||||
enum class MessageType {
|
||||
LoadROM,
|
||||
Reset,
|
||||
Pause,
|
||||
Resume,
|
||||
TogglePause,
|
||||
DumpRomFS,
|
||||
PressKey,
|
||||
ReleaseKey,
|
||||
SetCirclePadX,
|
||||
SetCirclePadY,
|
||||
LoadLuaScript,
|
||||
EditCheat,
|
||||
};
|
||||
|
||||
// Tagged union representing our message queue messages
|
||||
struct EmulatorMessage {
|
||||
|
@ -45,6 +58,10 @@ class MainWindow : public QMainWindow {
|
|||
u32 key;
|
||||
} key;
|
||||
|
||||
struct {
|
||||
s16 value;
|
||||
} circlepad;
|
||||
|
||||
struct {
|
||||
std::string* str;
|
||||
} string;
|
||||
|
|
|
@ -276,6 +276,8 @@ void MainWindow::dispatchMessage(const EmulatorMessage& message) {
|
|||
case MessageType::Reset: emu->reset(Emulator::ReloadOption::Reload); break;
|
||||
case MessageType::PressKey: emu->getServiceManager().getHID().pressKey(message.key.key); break;
|
||||
case MessageType::ReleaseKey: emu->getServiceManager().getHID().releaseKey(message.key.key); break;
|
||||
case MessageType::SetCirclePadX: emu->getServiceManager().getHID().setCirclepadX(message.circlepad.value); break;
|
||||
case MessageType::SetCirclePadY: emu->getServiceManager().getHID().setCirclepadY(message.circlepad.value); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,7 +285,12 @@ void MainWindow::keyPressEvent(QKeyEvent* event) {
|
|||
auto pressKey = [this](u32 key) {
|
||||
EmulatorMessage message{.type = MessageType::PressKey};
|
||||
message.key.key = key;
|
||||
sendMessage(message);
|
||||
};
|
||||
|
||||
auto setCirclePad = [this](MessageType type, s16 value) {
|
||||
EmulatorMessage message{.type = type};
|
||||
message.circlepad.value = value;
|
||||
sendMessage(message);
|
||||
};
|
||||
|
||||
|
@ -296,6 +303,11 @@ void MainWindow::keyPressEvent(QKeyEvent* event) {
|
|||
case Qt::Key_Q: pressKey(HID::Keys::L); break;
|
||||
case Qt::Key_P: pressKey(HID::Keys::R); break;
|
||||
|
||||
case Qt::Key_W: setCirclePad(MessageType::SetCirclePadY, 0x9C); break;
|
||||
case Qt::Key_A: setCirclePad(MessageType::SetCirclePadX, -0x9C); break;
|
||||
case Qt::Key_S: setCirclePad(MessageType::SetCirclePadY, -0x9C); break;
|
||||
case Qt::Key_D: setCirclePad(MessageType::SetCirclePadX, 0x9C); break;
|
||||
|
||||
case Qt::Key_Right: pressKey(HID::Keys::Right); break;
|
||||
case Qt::Key_Left: pressKey(HID::Keys::Left); break;
|
||||
case Qt::Key_Up: pressKey(HID::Keys::Up); break;
|
||||
|
@ -312,7 +324,12 @@ void MainWindow::keyReleaseEvent(QKeyEvent* event) {
|
|||
auto releaseKey = [this](u32 key) {
|
||||
EmulatorMessage message{.type = MessageType::ReleaseKey};
|
||||
message.key.key = key;
|
||||
sendMessage(message);
|
||||
};
|
||||
|
||||
auto releaseCirclePad = [this](MessageType type) {
|
||||
EmulatorMessage message{.type = type};
|
||||
message.circlepad.value = 0;
|
||||
sendMessage(message);
|
||||
};
|
||||
|
||||
|
@ -325,6 +342,12 @@ void MainWindow::keyReleaseEvent(QKeyEvent* event) {
|
|||
case Qt::Key_Q: releaseKey(HID::Keys::L); break;
|
||||
case Qt::Key_P: releaseKey(HID::Keys::R); break;
|
||||
|
||||
case Qt::Key_W:
|
||||
case Qt::Key_S: releaseCirclePad(MessageType::SetCirclePadY); break;
|
||||
|
||||
case Qt::Key_A:
|
||||
case Qt::Key_D: releaseCirclePad(MessageType::SetCirclePadX); break;
|
||||
|
||||
case Qt::Key_Right: releaseKey(HID::Keys::Right); break;
|
||||
case Qt::Key_Left: releaseKey(HID::Keys::Left); break;
|
||||
case Qt::Key_Up: releaseKey(HID::Keys::Up); break;
|
||||
|
|
Loading…
Add table
Reference in a new issue