Move screenshot logic with wxWidgets to guiWrapper

This commit is contained in:
SSimco
2023-06-07 10:23:13 +03:00
parent 8b265a9843
commit 466f03febc
4 changed files with 37 additions and 44 deletions
-4
View File
@@ -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()
+3 -40
View File
@@ -10,10 +10,6 @@
#include "config/ActiveSettings.h"
#include <wx/image.h>
#include <wx/dataobj.h>
#include <wx/clipbrd.h>
#include <wx/log.h>
std::unique_ptr<Renderer> g_renderer;
@@ -143,38 +139,6 @@ static std::optional<fs::path> 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<uint8> data, bool save_screenshot, int width, int height, bool mainWindow)
{
#if BOOST_OS_WINDOWS
@@ -182,12 +146,10 @@ static void ScreenshotThread(std::vector<uint8> 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<uint8> 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);
+32
View File
@@ -21,6 +21,7 @@
#include "Cafe/CafeSystem.h"
#include "wxHelper.h"
#include <wx/clipbrd.h>
WindowInfo g_window_info {};
@@ -231,6 +232,37 @@ std::string gui_RawKeyCodeToString(uint32 keyCode)
#endif
}
bool gui_saveScreenshotToFile(const fs::path& imagePath, std::vector<uint8>& 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<uint8>& 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
+2
View File
@@ -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<uint8>& data, int width, int height);
bool gui_saveScreenshotToClipboard(std::vector<uint8>& data, int width, int height);
/*
* Returns true if a screenshot request is queued
* Once this function has returned true, it will reset back to