RMG-Input: use native gamepad button names for a/b/x/y

This commit is contained in:
Rosalie Wanders
2025-10-18 01:23:43 +02:00
parent 2927d86d49
commit aba3676b1e
4 changed files with 84 additions and 0 deletions
+1
View File
@@ -28,6 +28,7 @@ set(RMG_INPUT_SOURCES
UserInterface/MainDialog.ui
UserInterface/MainDialog.cpp
UserInterface/UIResources.qrc
Utilities/Sdl3ButtonLabelToString.cpp
Utilities/QtKeyToSdl3Key.cpp
Thread/SDLThread.cpp
Thread/HotkeysThread.cpp
@@ -9,6 +9,7 @@
*/
#include "ControllerWidget.hpp"
#include "UserInterface/OptionsDialog.hpp"
#include "Utilities/Sdl3ButtonLabelToString.hpp"
#include "common.hpp"
@@ -1050,6 +1051,23 @@ void ControllerWidget::on_MainDialog_SdlEvent(SDL_Event* event)
sdlButton = event->gbutton.button;
sdlButtonPressed = (event->type == SDL_EVENT_GAMEPAD_BUTTON_DOWN);
sdlButtonName = SDL_GetGamepadStringForButton(static_cast<SDL_GamepadButton>(sdlButton));
// convert A/B/X/Y buttons to their native counterpart,
// this makes the button text look better in the UI
if (sdlButton == SDL_GAMEPAD_BUTTON_SOUTH ||
sdlButton == SDL_GAMEPAD_BUTTON_EAST ||
sdlButton == SDL_GAMEPAD_BUTTON_WEST ||
sdlButton == SDL_GAMEPAD_BUTTON_NORTH)
{
SDL_GamepadButtonLabel sdlLabel = SDL_GetGamepadButtonLabel(this->currentController,
static_cast<SDL_GamepadButton>(sdlButton));
QString sdlLabelName = Utilities::Sdl3ButtonLabelToString(sdlLabel);
if (!sdlLabelName.isEmpty())
{ // replace only when we have a name
sdlButtonName = sdlLabelName;
}
}
}
else if ((event->type == SDL_EVENT_JOYSTICK_BUTTON_DOWN) ||
(event->type == SDL_EVENT_JOYSTICK_BUTTON_UP))
@@ -0,0 +1,53 @@
/*
* Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG
* Copyright (C) 2020-2025 Rosalie Wanders <rosalie@mailbox.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Sdl3ButtonLabelToString.hpp"
#include <SDL3/SDL.h>
using namespace Utilities;
QString Utilities::Sdl3ButtonLabelToString(SDL_GamepadButtonLabel label)
{
QString buttonName;
switch (label)
{
case SDL_GAMEPAD_BUTTON_LABEL_A:
buttonName = "a";
break;
case SDL_GAMEPAD_BUTTON_LABEL_B:
buttonName = "b";
break;
case SDL_GAMEPAD_BUTTON_LABEL_X:
buttonName = "x";
break;
case SDL_GAMEPAD_BUTTON_LABEL_Y:
buttonName = "y";
break;
case SDL_GAMEPAD_BUTTON_LABEL_CROSS:
buttonName = "cross";
break;
case SDL_GAMEPAD_BUTTON_LABEL_CIRCLE:
buttonName = "circle";
break;
case SDL_GAMEPAD_BUTTON_LABEL_SQUARE:
buttonName = "square";
break;
case SDL_GAMEPAD_BUTTON_LABEL_TRIANGLE:
buttonName = "triangle";
break;
default:
break;
}
return buttonName;
}
@@ -0,0 +1,12 @@
#ifndef SDL3BUTTONLABELTOSTRING_HPP
#define SDL3BUTTONLABELTOSTRING_HPP
#include <SDL3/SDL.h>
#include <QString>
namespace Utilities
{
QString Sdl3ButtonLabelToString(SDL_GamepadButtonLabel label);
} // namespace Utilities
#endif // SDL3BUTTONLABELTOSTRING_HPP