From 6575ba54874e1965f28d72fc85198f5f28724c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 9 Apr 2024 14:23:26 +0200 Subject: [PATCH] Make screenshot notifications clickable (on platforms where it's possible) --- Common/System/OSD.cpp | 15 ++++++++------- Common/System/OSD.h | 2 +- GPU/Common/TextureReplacer.cpp | 2 +- UI/DevScreens.cpp | 4 ++-- UI/NativeApp.cpp | 12 +++++++++++- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Common/System/OSD.cpp b/Common/System/OSD.cpp index 997123af86..b20a8bc572 100644 --- a/Common/System/OSD.cpp +++ b/Common/System/OSD.cpp @@ -16,11 +16,10 @@ OnScreenDisplay::~OnScreenDisplay() { std::lock_guard guard(mutex_); double now = time_now_d(); - for (auto iter = entries_.begin(); iter != entries_.end(); ) { - if (iter->clickCallback) { + for (auto &iter : entries_) { + if (iter.clickCallback) { // Wasn't clicked, but let it free any data. - iter->clickCallback(false, iter->clickUserData); - iter->clickCallback = nullptr; + iter.clickCallback(false, iter.clickUserData); } } } @@ -65,7 +64,6 @@ void OnScreenDisplay::ClickEntry(size_t index, double now) { entries_[index].endTime = std::min(now + FadeoutTime(), entries_[index].endTime); if (entries_[index].clickCallback) { entries_[index].clickCallback(true, entries_[index].clickUserData); - entries_[index].clickCallback = nullptr; } } } @@ -321,10 +319,13 @@ void OnScreenDisplay::ClearAchievementStuff() { } } -void OnScreenDisplay::SetClickCallback(const char *id, void (*callback)(bool, void *)) { +void OnScreenDisplay::SetClickCallback(const char *id, void (*callback)(bool, void *), void *userdata) { + _dbg_assert_(callback != nullptr); for (auto &ent : entries_) { - if (ent.id == id) { + // protect against dupes. + if (ent.id == id && !ent.clickCallback) { ent.clickCallback = callback; + ent.clickUserData = userdata; } } } diff --git a/Common/System/OSD.h b/Common/System/OSD.h index 8715f41f4b..fdd513f02c 100644 --- a/Common/System/OSD.h +++ b/Common/System/OSD.h @@ -75,7 +75,7 @@ public: void ClearAchievementStuff(); // Can't add an infinite number of "Show" functions, so starting to offer post-modification. - void SetClickCallback(const char *id, void (*callback)(bool, void *)); + void SetClickCallback(const char *id, void (*callback)(bool, void *), void *userdata); struct Entry { OSDType type; diff --git a/GPU/Common/TextureReplacer.cpp b/GPU/Common/TextureReplacer.cpp index 53f7e716a8..5d03565f94 100644 --- a/GPU/Common/TextureReplacer.cpp +++ b/GPU/Common/TextureReplacer.cpp @@ -714,7 +714,7 @@ public: bool success = WriteTextureToPNG(&png, saveFilename, 0, rgbaData.data(), pitch, nullptr); png_image_free(&png); if (png.warning_or_error >= 2) { - ERROR_LOG(G3D, "Saving screenshot to PNG produced errors."); + ERROR_LOG(G3D, "Saving texture to PNG produced errors."); } else if (success) { NOTICE_LOG(G3D, "Saving texture for replacement: %08x / %dx%d in '%s'", replacedInfoHash, w, h, saveFilename.ToVisualString().c_str()); } else { diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index c37343b041..3c5aea442b 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -873,11 +873,11 @@ void SystemInfoScreen::CreateInternalsTab(UI::ViewGroup *internals) { // This one is clickable internals->Add(new Choice(si->T("Success")))->OnClick.Add([&](UI::EventParams &) { g_OSD.Show(OSDType::MESSAGE_SUCCESS, "Success", 0.0f, "clickable"); - g_OSD.SetClickCallback("clickable", [](bool clicked, void*) { + g_OSD.SetClickCallback("clickable", [](bool clicked, void *) { if (clicked) { System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://www.google.com/"); } - }); + }, nullptr); return UI::EVENT_DONE; }); internals->Add(new Choice(sy->T("RetroAchievements")))->OnClick.Add([&](UI::EventParams &) { diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 692201f107..3f022572c1 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -993,7 +993,17 @@ static void TakeScreenshot() { bool success = TakeGameScreenshot(filename, g_Config.bScreenshotsAsPNG ? ScreenshotFormat::PNG : ScreenshotFormat::JPG, SCREENSHOT_OUTPUT); if (success) { - g_OSD.Show(OSDType::MESSAGE_FILE_LINK, filename.ToString()); + g_OSD.Show(OSDType::MESSAGE_FILE_LINK, filename.ToString(), 0.0f, "screenshot_link"); + if (System_GetPropertyBool(SYSPROP_CAN_SHOW_FILE)) { + g_OSD.SetClickCallback("screenshot_link", [](bool clicked, void *data) -> void { + Path *path = reinterpret_cast(data); + if (clicked) { + System_ShowFileInFolder(*path); + } else { + delete path; + } + }, new Path(filename)); + } } else { auto err = GetI18NCategory(I18NCat::ERRORS); g_OSD.Show(OSDType::MESSAGE_ERROR, err->T("Could not save screenshot file"));