Skip to content

Commit

Permalink
Make screenshot notifications clickable (on platforms where it's poss…
Browse files Browse the repository at this point in the history
…ible)
  • Loading branch information
hrydgard committed Apr 9, 2024
1 parent cfa9b59 commit 4bf9895
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
8 changes: 5 additions & 3 deletions Common/System/OSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,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;
}
}
}
Expand Down Expand Up @@ -321,10 +320,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;
}
}
}
2 changes: 1 addition & 1 deletion Common/System/OSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class OnScreenDisplay {
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;
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/TextureReplacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ class SaveTextureTask : public Task {
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 {
Expand Down
4 changes: 2 additions & 2 deletions UI/DevScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &) {
Expand Down
12 changes: 11 additions & 1 deletion UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path *>(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"));
Expand Down

0 comments on commit 4bf9895

Please sign in to comment.