Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom touch buttons: Allow empty button images, not just empty shapes #19460

Merged
merged 2 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions UI/GamepadEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,10 @@ UI::ViewGroup *CreatePadLayout(float xres, float yres, bool *pause, bool showPau
auto addCustomButton = [=](const ConfigCustomButton& cfg, const char *key, const ConfigTouchPos &touch) -> CustomButton * {
using namespace CustomKeyData;
if (touch.show) {
_dbg_assert_(cfg.shape < ARRAY_SIZE(customKeyShapes));
_dbg_assert_(cfg.image < ARRAY_SIZE(customKeyImages));

// Note: cfg.shape and cfg.image are bounds-checked elsewhere.
auto aux = root->Add(new CustomButton(cfg.key, key, cfg.toggle, cfg.repeat, controllMapper,
g_Config.iTouchButtonStyle == 0 ? customKeyShapes[cfg.shape].i : customKeyShapes[cfg.shape].l, customKeyShapes[cfg.shape].i,
customKeyImages[cfg.image].i, touch.scale, customKeyShapes[cfg.shape].d, buttonLayoutParams(touch)));
Expand Down Expand Up @@ -940,7 +944,15 @@ UI::ViewGroup *CreatePadLayout(float xres, float yres, bool *pause, bool showPau
root->Add(new PSPStick(stickBg, "Right analog stick", stickImage, ImageID("I_STICK"), 1, g_Config.touchRightAnalogStick.scale, buttonLayoutParams(g_Config.touchRightAnalogStick)));
}

// Sanitize custom button images, while adding them.
for (int i = 0; i < Config::CUSTOM_BUTTON_COUNT; i++) {
if (g_Config.CustomButton[i].shape >= ARRAY_SIZE(CustomKeyData::customKeyShapes)) {
g_Config.CustomButton[i].shape = 0;
}
if (g_Config.CustomButton[i].image >= ARRAY_SIZE(CustomKeyData::customKeyImages)) {
g_Config.CustomButton[i].image = 0;
}

char temp[64];
snprintf(temp, sizeof(temp), "Custom %d button", i + 1);
addCustomButton(g_Config.CustomButton[i], temp, g_Config.touchCustom[i]);
Expand Down
1 change: 1 addition & 0 deletions UI/GamepadEmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ namespace CustomKeyData {
{ ImageID("I_ARROW_UP"), 0.0f},
{ ImageID("I_ARROW_DOWN"), 0.0f},
{ ImageID("I_THREE_DOTS"), 0.0f},
{ ImageID("I_EMPTY"), 0.0f},
};

// Shape list
Expand Down
10 changes: 10 additions & 0 deletions UI/TouchControlLayoutScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ void ControlLayoutView::CreateViews() {
auto addDragCustomKey = [&](ConfigTouchPos &pos, const char *key, const ConfigCustomButton& cfg) {
DragDropButton *b = nullptr;
if (pos.show) {


b = new DragDropButton(pos, key, g_Config.iTouchButtonStyle == 0 ? customKeyShapes[cfg.shape].i : customKeyShapes[cfg.shape].l, customKeyImages[cfg.image].i, bounds);
b->FlipImageH(customKeyShapes[cfg.shape].f);
b->SetAngle(customKeyImages[cfg.image].r, customKeyShapes[cfg.shape].r);
Expand All @@ -523,6 +525,14 @@ void ControlLayoutView::CreateViews() {
};

for (int i = 0; i < Config::CUSTOM_BUTTON_COUNT; i++) {
// Similar to GamepadEmu, we sanitize the images for valid values.
if (g_Config.CustomButton[i].shape >= ARRAY_SIZE(CustomKeyData::customKeyShapes)) {
g_Config.CustomButton[i].shape = 0;
}
if (g_Config.CustomButton[i].image >= ARRAY_SIZE(CustomKeyData::customKeyImages)) {
g_Config.CustomButton[i].image = 0;
}

char temp[64];
snprintf(temp, sizeof(temp), "Custom %d button", i);
addDragCustomKey(g_Config.touchCustom[i], temp, g_Config.CustomButton[i]);
Expand Down
Loading