Skip to content

Commit 67de63b

Browse files
authored
UI+build: Isolate wxWidgets code from non-GUI code (#1633)
1 parent 5f3c281 commit 67de63b

File tree

199 files changed

+2416
-2093
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+2416
-2093
lines changed

.github/workflows/generate_pot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
find src -name *.cpp -o -name *.hpp -o -name *.h |
3232
xargs xgettext --from-code=utf-8 -w 100
3333
--keyword="_" --keyword="wxTRANSLATE" --keyword="wxPLURAL:1,2"
34+
--keyword="_tr" --keyword="TR_NOOP"
3435
--check=space-ellipsis --omit-header
3536
-o cemu.pot
3637

src/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,3 @@ if(UNIX AND NOT APPLE)
150150
# most likely not helpful in debugging problems with cemu code
151151
target_link_options(CemuBin PRIVATE "$<$<CONFIG:Release>:-Xlinker;--strip-debug>")
152152
endif()
153-
154-
if (ENABLE_WXWIDGETS)
155-
target_link_libraries(CemuBin PRIVATE wx::base wx::core)
156-
endif()

src/Cafe/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,6 @@ else ()
597597
target_link_libraries(CemuCafe PRIVATE libusb::libusb)
598598
endif ()
599599

600-
if (ENABLE_WXWIDGETS)
601-
target_link_libraries(CemuCafe PRIVATE wx::base wx::core)
602-
endif()
603-
604600
if(WIN32)
605601
target_link_libraries(CemuCafe PRIVATE iphlpapi)
606602
endif()

src/Cafe/CafeSystem.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "Cafe/OS/common/OSCommon.h"
2-
#include "gui/wxgui.h"
2+
#include "WindowSystem.h"
33
#include "Cafe/OS/libs/gx2/GX2.h"
44
#include "Cafe/GameProfile/GameProfile.h"
55
#include "Cafe/HW/Espresso/Interpreter/PPCInterpreterInternal.h"
@@ -65,9 +65,6 @@
6565
// HW interfaces
6666
#include "Cafe/HW/SI/si.h"
6767

68-
// dependency to be removed
69-
#include "gui/guiWrapper.h"
70-
7168
#include <time.h>
7269

7370
#if BOOST_OS_LINUX
@@ -172,7 +169,7 @@ void LoadMainExecutable()
172169
applicationRPX = RPLLoader_LoadFromMemory(rpxData, rpxSize, (char*)_pathToExecutable.c_str());
173170
if (!applicationRPX)
174171
{
175-
wxMessageBox(_("Failed to run this title because the executable is damaged"));
172+
WindowSystem::ShowErrorDialog(_tr("Failed to run this title because the executable is damaged"));
176173
cemuLog_createLogFile(false);
177174
cemuLog_waitForFlush();
178175
exit(0);
@@ -357,7 +354,7 @@ uint32 LoadSharedData()
357354

358355
void cemu_initForGame()
359356
{
360-
gui_updateWindowTitles(false, true, 0.0);
357+
WindowSystem::UpdateWindowTitles(false, true, 0.0);
361358
// input manager apply game profile
362359
InputManager::instance().apply_game_profile();
363360
// log info for launched title
@@ -855,7 +852,7 @@ namespace CafeSystem
855852
PPCTimer_waitForInit();
856853
// start system
857854
sSystemRunning = true;
858-
gui_notifyGameLoaded();
855+
WindowSystem::NotifyGameLoaded();
859856
std::thread t(_LaunchTitleThread);
860857
t.detach();
861858
}

src/Cafe/Filesystem/FST/KeyCache.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include <wx/msgdlg.h>
21
#include <mutex>
3-
#include <gui/helpers/wxHelpers.h>
42

3+
#include "Cemu/Logging/CemuLogging.h"
4+
#include "WindowSystem.h"
55
#include "config/ActiveSettings.h"
66
#include "util/crypto/aes128.h"
77
#include "Common/FileStream.h"
@@ -75,7 +75,7 @@ void KeyCache_Prepare()
7575
}
7676
else
7777
{
78-
wxMessageBox(_("Unable to create file keys.txt\nThis can happen if Cemu does not have write permission to its own directory, the disk is full or if anti-virus software is blocking Cemu."), _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
78+
WindowSystem::ShowErrorDialog(_tr("Unable to create file keys.txt\nThis can happen if Cemu does not have write permission to its own directory, the disk is full or if anti-virus software is blocking Cemu."), _tr("Error"), WindowSystem::ErrorCategory::KEYS_TXT_CREATION);
7979
}
8080
mtxKeyCache.unlock();
8181
return;
@@ -108,8 +108,8 @@ void KeyCache_Prepare()
108108
continue;
109109
if( strishex(line) == false )
110110
{
111-
auto errorMsg = formatWxString(_("Error in keys.txt at line {}"), lineNumber);
112-
wxMessageBox(errorMsg, _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
111+
auto errorMsg = _tr("Error in keys.txt at line {}", lineNumber);
112+
WindowSystem::ShowErrorDialog(errorMsg, WindowSystem::ErrorCategory::KEYS_TXT_CREATION);
113113
continue;
114114
}
115115
if(line.size() == 32 )

src/Cafe/GraphicPack/GraphicPack2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ bool GraphicPack2::LoadGraphicPack(const fs::path& rulesPath, IniParser& rules)
8585
auto gp = std::make_shared<GraphicPack2>(rulesPath, rules);
8686

8787
// check if enabled and preset set
88-
const auto& config_entries = g_config.data().graphic_pack_entries;
88+
const auto& config_entries = GetConfigHandle().data().graphic_pack_entries;
8989

9090
// legacy absolute path checking for not breaking compatibility
9191
auto file = gp->GetRulesPath();

src/Cafe/GraphicPack/GraphicPack2Patches.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#include "Cafe/GraphicPack/GraphicPack2.h"
2+
#include "Cemu/Logging/CemuLogging.h"
23
#include "Common/FileStream.h"
4+
#include "WindowSystem.h"
35
#include "util/helpers/StringParser.h"
46
#include "Cemu/PPCAssembler/ppcAssembler.h"
57
#include "Cafe/OS/RPL/rpl_structs.h"
68
#include "boost/algorithm/string.hpp"
79

8-
#include "gui/wxgui.h" // for wxMessageBox
9-
#include "gui/helpers/wxHelpers.h"
10-
1110
// error handler
1211
void PatchErrorHandler::printError(class PatchGroup* patchGroup, sint32 lineNumber, std::string_view errorMsg)
1312
{
@@ -40,13 +39,13 @@ void PatchErrorHandler::printError(class PatchGroup* patchGroup, sint32 lineNumb
4039

4140
void PatchErrorHandler::showStageErrorMessageBox()
4241
{
43-
wxString errorMsg;
42+
std::string errorMsg;
4443
if (m_gp)
4544
{
4645
if (m_stage == STAGE::PARSER)
47-
errorMsg.assign(formatWxString(_("Failed to load patches for graphic pack \'{}\'"), m_gp->GetName()));
46+
errorMsg.assign(_tr("Failed to load patches for graphic pack \'{}\'", m_gp->GetName()));
4847
else
49-
errorMsg.assign(formatWxString(_("Failed to apply patches for graphic pack \'{}\'"), m_gp->GetName()));
48+
errorMsg.assign(_tr("Failed to apply patches for graphic pack \'{}\'", m_gp->GetName()));
5049
}
5150
else
5251
{
@@ -55,7 +54,7 @@ void PatchErrorHandler::showStageErrorMessageBox()
5554
if (cemuLog_isLoggingEnabled(LogType::Patches))
5655
{
5756
errorMsg.append("\n \n")
58-
.append(_("Details:"))
57+
.append(_tr("Details:"))
5958
.append("\n");
6059
for (auto& itr : errorMessages)
6160
{
@@ -64,7 +63,7 @@ void PatchErrorHandler::showStageErrorMessageBox()
6463
}
6564
}
6665

67-
wxMessageBox(errorMsg, _("Graphic pack error"));
66+
WindowSystem::ShowErrorDialog(errorMsg, _tr("Graphic pack error"), WindowSystem::ErrorCategory::GRAPHIC_PACKS);
6867
}
6968

7069
// loads Cemu-style patches (patch_<anything>.asm)

src/Cafe/HW/Espresso/Debugger/Debugger.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
#include "gui/guiWrapper.h"
1+
#include "Common/precompiled.h"
22
#include "Debugger.h"
33
#include "Cafe/OS/RPL/rpl_structs.h"
44
#include "Cemu/PPCAssembler/ppcAssembler.h"
55
#include "Cafe/HW/Espresso/Recompiler/PPCRecompiler.h"
66
#include "Cemu/ExpressionParser/ExpressionParser.h"
77

8-
#include "gui/debugger/DebuggerWindow2.h"
9-
108
#include "Cafe/OS/libs/coreinit/coreinit.h"
9+
#include "OS/RPL/rpl.h"
1110
#include "util/helpers/helpers.h"
1211

1312
#if BOOST_OS_WINDOWS
1413
#include <Windows.h>
1514
#endif
1615

16+
DebuggerDispatcher g_debuggerDispatcher;
17+
1718
debuggerState_t debuggerState{ };
1819

1920
DebuggerBreakpoint* debugger_getFirstBP(uint32 address)
@@ -337,7 +338,7 @@ void debugger_toggleBreakpoint(uint32 address, bool state, DebuggerBreakpoint* b
337338
{
338339
bp->enabled = state;
339340
debugger_updateExecutionBreakpoint(address);
340-
debuggerWindow_updateViewThreadsafe2();
341+
g_debuggerDispatcher.UpdateViewThreadsafe();
341342
}
342343
else if (bpItr->isMemBP())
343344
{
@@ -359,7 +360,7 @@ void debugger_toggleBreakpoint(uint32 address, bool state, DebuggerBreakpoint* b
359360
debugger_updateMemoryBreakpoint(bpItr);
360361
else
361362
debugger_updateMemoryBreakpoint(nullptr);
362-
debuggerWindow_updateViewThreadsafe2();
363+
g_debuggerDispatcher.UpdateViewThreadsafe();
363364
}
364365
return;
365366
}
@@ -496,7 +497,7 @@ void debugger_stepInto(PPCInterpreter_t* hCPU, bool updateDebuggerWindow = true)
496497
debugger_updateExecutionBreakpoint(initialIP);
497498
debuggerState.debugSession.instructionPointer = hCPU->instructionPointer;
498499
if(updateDebuggerWindow)
499-
debuggerWindow_moveIP();
500+
g_debuggerDispatcher.MoveIP();
500501
ppcRecompilerEnabled = isRecEnabled;
501502
}
502503

@@ -515,15 +516,15 @@ bool debugger_stepOver(PPCInterpreter_t* hCPU)
515516
// nothing to skip, use step-into
516517
debugger_stepInto(hCPU);
517518
debugger_updateExecutionBreakpoint(initialIP);
518-
debuggerWindow_moveIP();
519+
g_debuggerDispatcher.MoveIP();
519520
ppcRecompilerEnabled = isRecEnabled;
520521
return false;
521522
}
522523
// create one-shot breakpoint at next instruction
523524
debugger_createCodeBreakpoint(initialIP + 4, DEBUGGER_BP_T_ONE_SHOT);
524525
// step over current instruction (to avoid breakpoint)
525526
debugger_stepInto(hCPU);
526-
debuggerWindow_moveIP();
527+
g_debuggerDispatcher.MoveIP();
527528
// restore breakpoints
528529
debugger_updateExecutionBreakpoint(initialIP);
529530
// run
@@ -621,8 +622,8 @@ void debugger_enterTW(PPCInterpreter_t* hCPU)
621622
DebuggerBreakpoint* singleshotBP = debugger_getFirstBP(debuggerState.debugSession.instructionPointer, DEBUGGER_BP_T_ONE_SHOT);
622623
if (singleshotBP)
623624
debugger_deleteBreakpoint(singleshotBP);
624-
debuggerWindow_notifyDebugBreakpointHit2();
625-
debuggerWindow_updateViewThreadsafe2();
625+
g_debuggerDispatcher.NotifyDebugBreakpointHit();
626+
g_debuggerDispatcher.UpdateViewThreadsafe();
626627
// reset step control
627628
debuggerState.debugSession.stepInto = false;
628629
debuggerState.debugSession.stepOver = false;
@@ -639,14 +640,14 @@ void debugger_enterTW(PPCInterpreter_t* hCPU)
639640
break; // if true is returned, continue with execution
640641
}
641642
debugger_createPPCStateSnapshot(hCPU);
642-
debuggerWindow_updateViewThreadsafe2();
643+
g_debuggerDispatcher.UpdateViewThreadsafe();
643644
debuggerState.debugSession.stepOver = false;
644645
}
645646
if (debuggerState.debugSession.stepInto)
646647
{
647648
debugger_stepInto(hCPU);
648649
debugger_createPPCStateSnapshot(hCPU);
649-
debuggerWindow_updateViewThreadsafe2();
650+
g_debuggerDispatcher.UpdateViewThreadsafe();
650651
debuggerState.debugSession.stepInto = false;
651652
continue;
652653
}
@@ -663,8 +664,8 @@ void debugger_enterTW(PPCInterpreter_t* hCPU)
663664

664665
debuggerState.debugSession.isTrapped = false;
665666
debuggerState.debugSession.hCPU = nullptr;
666-
debuggerWindow_updateViewThreadsafe2();
667-
debuggerWindow_notifyRun();
667+
g_debuggerDispatcher.UpdateViewThreadsafe();
668+
g_debuggerDispatcher.NotifyRun();
668669
}
669670

670671
void debugger_shouldBreak(PPCInterpreter_t* hCPU)

src/Cafe/HW/Espresso/Debugger/Debugger.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,69 @@
1515
#define DEBUGGER_BP_T_GDBSTUB_TW 0x7C010008
1616
#define DEBUGGER_BP_T_DEBUGGER_TW 0x7C020008
1717

18+
class DebuggerCallbacks
19+
{
20+
public:
21+
virtual void UpdateViewThreadsafe() {}
22+
virtual void NotifyDebugBreakpointHit() {}
23+
virtual void NotifyRun() {}
24+
virtual void MoveIP() {}
25+
virtual void NotifyModuleLoaded(void* module) {}
26+
virtual void NotifyModuleUnloaded(void* module) {}
27+
virtual ~DebuggerCallbacks() = default;
28+
};
29+
30+
class DebuggerDispatcher
31+
{
32+
private:
33+
static inline class DefaultDebuggerCallbacks : public DebuggerCallbacks
34+
{
35+
} s_defaultDebuggerCallbacks;
36+
DebuggerCallbacks* m_callbacks = &s_defaultDebuggerCallbacks;
37+
38+
public:
39+
void SetDebuggerCallbacks(DebuggerCallbacks* debuggerCallbacks)
40+
{
41+
cemu_assert_debug(m_callbacks == &s_defaultDebuggerCallbacks);
42+
m_callbacks = debuggerCallbacks;
43+
}
44+
45+
void ClearDebuggerCallbacks()
46+
{
47+
cemu_assert_debug(m_callbacks != &s_defaultDebuggerCallbacks);
48+
m_callbacks = &s_defaultDebuggerCallbacks;
49+
}
50+
51+
void UpdateViewThreadsafe()
52+
{
53+
m_callbacks->UpdateViewThreadsafe();
54+
}
55+
56+
void NotifyDebugBreakpointHit()
57+
{
58+
m_callbacks->NotifyDebugBreakpointHit();
59+
}
60+
61+
void NotifyRun()
62+
{
63+
m_callbacks->NotifyRun();
64+
}
65+
66+
void MoveIP()
67+
{
68+
m_callbacks->MoveIP();
69+
}
70+
71+
void NotifyModuleLoaded(void* module)
72+
{
73+
m_callbacks->NotifyModuleLoaded(module);
74+
}
75+
76+
void NotifyModuleUnloaded(void* module)
77+
{
78+
m_callbacks->NotifyModuleUnloaded(module);
79+
}
80+
} extern g_debuggerDispatcher;
1881

1982
struct DebuggerBreakpoint
2083
{

src/Cafe/HW/Latte/Core/LatteOverlay.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "Cafe/HW/Latte/Core/LatteOverlay.h"
22
#include "Cafe/HW/Latte/Core/LattePerformanceMonitor.h"
3-
#include "gui/guiWrapper.h"
3+
#include "WindowSystem.h"
44

55
#include "config/CemuConfig.h"
66

@@ -519,17 +519,17 @@ void LatteOverlay_render(bool pad_view)
519519
return;
520520

521521
sint32 w = 0, h = 0;
522-
if (pad_view && gui_isPadWindowOpen())
523-
gui_getPadWindowPhysSize(w, h);
522+
if (pad_view && WindowSystem::IsPadWindowOpen())
523+
WindowSystem::GetPadWindowPhysSize(w, h);
524524
else
525-
gui_getWindowPhysSize(w, h);
525+
WindowSystem::GetWindowPhysSize(w, h);
526526

527527
if (w == 0 || h == 0)
528528
return;
529529

530530
const Vector2f window_size{ (float)w,(float)h };
531531

532-
float fontDPIScale = !pad_view ? gui_getWindowDPIScale() : gui_getPadDPIScale();
532+
float fontDPIScale = !pad_view ? WindowSystem::GetWindowDPIScale() : WindowSystem::GetPadDPIScale();
533533

534534
float overlayFontSize = 14.0f * (float)config.overlay.text_scale / 100.0f * fontDPIScale;
535535

0 commit comments

Comments
 (0)