mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-23 14:19:55 -06:00
actually complete the input config dialog
This commit is contained in:
119
src/frontend/qt_sdl/Input.cpp
Normal file
119
src/frontend/qt_sdl/Input.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
Copyright 2016-2020 Arisotura
|
||||
|
||||
This file is part of melonDS.
|
||||
|
||||
melonDS is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "Input.h"
|
||||
#include "PlatformConfig.h"
|
||||
|
||||
|
||||
namespace Input
|
||||
{
|
||||
|
||||
int JoystickID;
|
||||
SDL_Joystick* Joystick = nullptr;
|
||||
|
||||
u32 KeyInputMask, JoyInputMask;
|
||||
u32 KeyHotkeyMask, JoyHotkeyMask;
|
||||
u32 HotkeyMask, LastHotkeyMask;
|
||||
u32 HotkeyPress, HotkeyRelease;
|
||||
|
||||
|
||||
void OpenJoystick()
|
||||
{
|
||||
if (Joystick) SDL_JoystickClose(Joystick);
|
||||
|
||||
int num = SDL_NumJoysticks();
|
||||
if (num < 1)
|
||||
{
|
||||
Joystick = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
if (JoystickID >= num)
|
||||
JoystickID = 0;
|
||||
|
||||
Joystick = SDL_JoystickOpen(JoystickID);
|
||||
}
|
||||
|
||||
void CloseJoystick()
|
||||
{
|
||||
if (Joystick)
|
||||
{
|
||||
SDL_JoystickClose(Joystick);
|
||||
Joystick = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Process()
|
||||
{
|
||||
SDL_JoystickUpdate();
|
||||
|
||||
if (Joystick)
|
||||
{
|
||||
if (!SDL_JoystickGetAttached(Joystick))
|
||||
{
|
||||
SDL_JoystickClose(Joystick);
|
||||
Joystick = NULL;
|
||||
}
|
||||
}
|
||||
if (!Joystick && (SDL_NumJoysticks() > 0))
|
||||
{
|
||||
JoystickID = Config::JoystickID;
|
||||
OpenJoystick();
|
||||
}
|
||||
|
||||
/*JoyInputMask = 0xFFF;
|
||||
for (int i = 0; i < 12; i++)
|
||||
if (JoystickButtonDown(Config::JoyMapping[i]))
|
||||
JoyInputMask &= ~(1<<i);
|
||||
|
||||
JoyHotkeyMask = 0;
|
||||
for (int i = 0; i < HK_MAX; i++)
|
||||
if (JoystickButtonDown(Config::HKJoyMapping[i]))
|
||||
JoyHotkeyMask |= (1<<i);
|
||||
|
||||
HotkeyMask = KeyHotkeyMask | JoyHotkeyMask;
|
||||
HotkeyPress = HotkeyMask & ~LastHotkeyMask;
|
||||
HotkeyRelease = LastHotkeyMask & ~HotkeyMask;
|
||||
LastHotkeyMask = HotkeyMask;*/
|
||||
}
|
||||
|
||||
|
||||
// TODO: MacOS version of this!
|
||||
// distinguish between left and right modifier keys (Ctrl, Alt, Shift)
|
||||
// Qt provides no real cross-platform way to do this, so here we go
|
||||
// for Windows and Linux we can distinguish via scancodes (but both
|
||||
// provide different scancodes)
|
||||
#ifdef __WIN32__
|
||||
bool IsRightModKey(QKeyEvent* event)
|
||||
{
|
||||
quint32 scan = event->nativeScanCode();
|
||||
return (scan == 0x11D || scan == 0x138 || scan == 0x36);
|
||||
}
|
||||
#else
|
||||
bool IsRightModKey(QKeyEvent* event)
|
||||
{
|
||||
quint32 scan = event->nativeScanCode();
|
||||
return (scan == 0x69 || scan == 0x6C || scan == 0x3E);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
Reference in New Issue
Block a user