Skip to content
Open
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
60 changes: 60 additions & 0 deletions src/gui/gui.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/***************************************************************************

Check notice on line 1 in src/gui/gui.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 12.31 to 11.53, threshold = 4 This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
* Copyright (C) 2019 PCSX-Redux authors *
* *
* This program is free software; you can redistribute it and/or modify *
Expand Down Expand Up @@ -1426,6 +1426,9 @@
if (ImGui::MenuItem(_("Hard Reset"), "Shift+F8")) {
g_system->hardReset();
}
if (ImGui::MenuItem(_("Take Screenshot"))) {
saveScreenShot();
}
ImGui::EndMenu();
}
ImGui::Separator();
Expand Down Expand Up @@ -3102,3 +3105,60 @@
}
}
}

clip::image PCSX::GUI::convertScreenshotToImage(PCSX::GPU::ScreenShot&& screenshot) {
clip::image_spec spec;
spec.width = screenshot.width;
spec.height = screenshot.height;
if (screenshot.bpp == PCSX::GPU::ScreenShot::BPP_16) {
spec.bits_per_pixel = 16;
spec.bytes_per_row = screenshot.width * 2;
spec.red_mask = 0x1f; // 0x7c00;
spec.green_mask = 0x3e0;
spec.blue_mask = 0x7c00; // 0x1f;
spec.alpha_mask = 0;
spec.red_shift = 0; // 10;
spec.green_shift = 5;
spec.blue_shift = 10; // 0;
spec.alpha_shift = 0;
} else {
spec.bits_per_pixel = 24;
spec.bytes_per_row = screenshot.width * 3;
spec.red_mask = 0xff0000;
spec.green_mask = 0xff00;
spec.blue_mask = 0xff;
spec.alpha_mask = 0;
spec.red_shift = 16;
spec.green_shift = 8;
spec.blue_shift = 0;
spec.alpha_shift = 0;
}
clip::image img(screenshot.data.data(), spec);
return img.to_rgba8888();
}

bool PCSX::GUI::writeImagePNG(std::string filename, clip::image&& img) { return img.export_to_png(filename); }

std::string PCSX::GUI::getDateString() {
auto now = std::chrono::system_clock::now();
auto in_time_t = std::chrono::system_clock::to_time_t(now);

auto local_time = std::localtime(&in_time_t);

std::stringstream ss;
ss << std::put_time(local_time, "%Y-%m-%d-%H-%M-%S");

Copilot AI Apr 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that is needed for std::put_time to function correctly. Please add the necessary include to avoid potential compile errors.

Copilot uses AI. Check for mistakes.

std::string datetime_string = ss.str();

return datetime_string;
}

bool PCSX::GUI::saveScreenShot() {
std::filesystem::path path =
g_system->getPersistentDir() / (getSaveStatePrefix(true) + getDateString() + ".png");
auto screenshot = g_emulator->m_gpu->takeScreenShot();
clip::image img = convertScreenshotToImage(std::move(screenshot));
bool success = writeImagePNG(path.string(), std::move(img));

return success;
}
6 changes: 6 additions & 0 deletions src/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <memory>
#include <set>
#include <string>
#include <sstream>
#include <ctime>
#include <string_view>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -458,13 +460,17 @@ class GUI final : public UI {
std::string buildSaveStateFilename(int i);
std::string buildSaveStateFilename(std::string name);
bool saveStateExists(std::filesystem::path filename);
bool saveScreenShot();

private:
void applyTheme(int theme);
void cherryTheme();
void monoTheme();
void draculaTheme();
void oliveTheme();
std::string getDateString();
clip::image convertScreenshotToImage(PCSX::GPU::ScreenShot&& screenshot);
bool writeImagePNG(std::string filename, clip::image&& img);

Notifier m_notifier = {l_("Notification")};
Widgets::Console m_luaConsole = {settings.get<ShowLuaConsole>().value};
Expand Down
Loading