Use signals on button/trigger to release to make GUI more responsive

This commit is contained in:
rainmakerv3 2025-06-24 22:54:03 +08:00
parent cd4931b16f
commit 86be802223
2 changed files with 26 additions and 9 deletions

View File

@ -752,6 +752,8 @@ void ControlSettings::CheckMapping(QPushButton*& button) {
button->setText(mapping); button->setText(mapping);
EnableButtonMapping = false; EnableButtonMapping = false;
EnableAxisMapping = false; EnableAxisMapping = false;
L2Pressed = false;
R2Pressed = false;
EnableMappingButtons(); EnableMappingButtons();
timer->stop(); timer->stop();
} }
@ -844,19 +846,32 @@ void ControlSettings::processSDLEvents(int Type, int Input, int Value) {
if (Type == SDL_EVENT_GAMEPAD_AXIS_MOTION) { if (Type == SDL_EVENT_GAMEPAD_AXIS_MOTION) {
// SDL trigger axis values range from 0 to 32000, set mapping on half movement // SDL trigger axis values range from 0 to 32000, set mapping on half movement
// Set zone for trigger release signal arbitrarily at 5000 // Set zone for trigger release signal arbitrarily at 5000
if (Value > 16000) {
switch (Input) { switch (Input) {
case SDL_GAMEPAD_AXIS_LEFT_TRIGGER: case SDL_GAMEPAD_AXIS_LEFT_TRIGGER:
if (Value > 16000) {
pressedButtons.insert("l2"); pressedButtons.insert("l2");
L2Pressed = true;
} else if (Value < 5000) {
if (L2Pressed)
emit PushGamepadEvent();
}
break; break;
case SDL_GAMEPAD_AXIS_RIGHT_TRIGGER: case SDL_GAMEPAD_AXIS_RIGHT_TRIGGER:
if (Value > 16000) {
pressedButtons.insert("r2"); pressedButtons.insert("r2");
R2Pressed = true;
} else if (Value < 5000) {
if (R2Pressed)
emit PushGamepadEvent();
}
break; break;
default: default:
break; break;
} }
} }
}
if (Type == SDL_EVENT_GAMEPAD_BUTTON_UP)
emit PushGamepadEvent();
} else if (EnableAxisMapping) { } else if (EnableAxisMapping) {
if (Type == SDL_EVENT_GAMEPAD_AXIS_MOTION) { if (Type == SDL_EVENT_GAMEPAD_AXIS_MOTION) {

View File

@ -51,6 +51,8 @@ private:
QSet<QString> pressedButtons; QSet<QString> pressedButtons;
bool GameRunning; bool GameRunning;
bool L2Pressed = false;
bool R2Pressed = false;
bool EnableButtonMapping = false; bool EnableButtonMapping = false;
bool EnableAxisMapping = false; bool EnableAxisMapping = false;
bool MappingCompleted = false; bool MappingCompleted = false;