diff --git a/src/Cafe/CMakeLists.txt b/src/Cafe/CMakeLists.txt index 8da22176..4b9ec166 100644 --- a/src/Cafe/CMakeLists.txt +++ b/src/Cafe/CMakeLists.txt @@ -508,10 +508,6 @@ if (ENABLE_WAYLAND) target_link_libraries(CemuCafe PUBLIC Wayland::Client) endif() -if (ENABLE_WXWIDGETS) - target_link_libraries(CemuCafe PRIVATE wx::base wx::core) -endif() - if(WIN32) target_link_libraries(CemuCafe PRIVATE iphlpapi) endif() diff --git a/src/Cafe/HW/Latte/Renderer/Renderer.cpp b/src/Cafe/HW/Latte/Renderer/Renderer.cpp index 63ba5a7d..b8585c77 100644 --- a/src/Cafe/HW/Latte/Renderer/Renderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Renderer.cpp @@ -10,10 +10,6 @@ #include "config/ActiveSettings.h" -#include -#include -#include -#include std::unique_ptr g_renderer; @@ -143,38 +139,6 @@ static std::optional GenerateScreenshotFilename(bool isDRC) return std::nullopt; } -std::mutex s_clipboardMutex; - -static bool SaveScreenshotToClipboard(const wxImage &image) -{ - bool success = false; - - s_clipboardMutex.lock(); - if (wxTheClipboard->Open()) - { - wxTheClipboard->SetData(new wxImageDataObject(image)); - wxTheClipboard->Close(); - success = true; - } - s_clipboardMutex.unlock(); - - return success; -} - -static bool SaveScreenshotToFile(const wxImage &image, bool mainWindow) -{ - auto path = GenerateScreenshotFilename(!mainWindow); - if (!path) return false; - - std::error_code ec; - fs::create_directories(path->parent_path(), ec); - if (ec) return false; - - // suspend wxWidgets logging for the lifetime this object, to prevent a message box if wxImage::SaveFile fails - wxLogNull _logNo; - return image.SaveFile(path->wstring()); -} - static void ScreenshotThread(std::vector data, bool save_screenshot, int width, int height, bool mainWindow) { #if BOOST_OS_WINDOWS @@ -182,12 +146,10 @@ static void ScreenshotThread(std::vector data, bool save_screenshot, int // to make this work we need to call OleInitialize() on the same thread OleInitialize(nullptr); #endif - - wxImage image(width, height, data.data(), true); if (mainWindow) { - if(SaveScreenshotToClipboard(image)) + if(gui_saveScreenshotToClipboard(data, width, height)) { if (!save_screenshot) LatteOverlay_pushNotification("Screenshot saved to clipboard", 2500); @@ -200,7 +162,8 @@ static void ScreenshotThread(std::vector data, bool save_screenshot, int if (save_screenshot) { - if (SaveScreenshotToFile(image, mainWindow)) + auto imagePath = GenerateScreenshotFilename(mainWindow); + if (imagePath.has_value() && gui_saveScreenshotToFile(imagePath.value(), data, width, height)) { if (mainWindow) LatteOverlay_pushNotification("Screenshot saved", 2500); diff --git a/src/gui/guiWrapper.cpp b/src/gui/guiWrapper.cpp index 7cf082a5..1ca86284 100644 --- a/src/gui/guiWrapper.cpp +++ b/src/gui/guiWrapper.cpp @@ -21,6 +21,7 @@ #include "Cafe/CafeSystem.h" #include "wxHelper.h" +#include WindowInfo g_window_info {}; @@ -231,6 +232,37 @@ std::string gui_RawKeyCodeToString(uint32 keyCode) #endif } +bool gui_saveScreenshotToFile(const fs::path& imagePath, std::vector& data, int width, int height) +{ + + std::error_code ec; + fs::create_directories(imagePath.parent_path(), ec); + if (ec) return false; + + // suspend wxWidgets logging for the lifetime this object, to prevent a message box if wxImage::SaveFile fails + wxLogNull _logNo; + wxImage image(width, height, data.data(), true); + return image.SaveFile(imagePath.wstring()); +} + +bool gui_saveScreenshotToClipboard(std::vector& data, int width, int height) +{ + static std::mutex s_clipboardMutex; + bool success = false; + + s_clipboardMutex.lock(); + if (wxTheClipboard->Open()) + { + wxImage image(width, height, data.data(), true); + wxTheClipboard->SetData(new wxImageDataObject(image)); + wxTheClipboard->Close(); + success = true; + } + s_clipboardMutex.unlock(); + + return success; +} + void gui_initHandleContextFromWxWidgetsWindow(WindowHandleInfo& handleInfoOut, class wxWindow* wxw) { #if BOOST_OS_WINDOWS diff --git a/src/gui/guiWrapper.h b/src/gui/guiWrapper.h index ebb29d83..396a4823 100644 --- a/src/gui/guiWrapper.h +++ b/src/gui/guiWrapper.h @@ -142,6 +142,8 @@ void gui_initHandleContextFromWxWidgetsWindow(WindowHandleInfo& handleInfoOut, c std::string gui_RawKeyCodeToString(uint32 keyCode); +bool gui_saveScreenshotToFile(const fs::path& imagePath, std::vector& data, int width, int height); +bool gui_saveScreenshotToClipboard(std::vector& data, int width, int height); /* * Returns true if a screenshot request is queued * Once this function has returned true, it will reset back to