Skip to content

Commit 25878b8

Browse files
committed
Add debug UI for system API
1 parent 6f26bdf commit 25878b8

File tree

9 files changed

+52
-19
lines changed

9 files changed

+52
-19
lines changed

src/core/include/growl/core/api/api_internal.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,20 @@ class APIInternal {
1919

2020
virtual Error init() = 0;
2121
virtual void dispose() = 0;
22+
#ifdef GROWL_IMGUI
23+
virtual void populateDebugMenu() {}
24+
#endif
2225
};
2326

2427
class SystemAPIInternal : public SystemAPI, public APIInternal {
2528
public:
2629
virtual ~SystemAPIInternal() {}
2730
// Used in push-style touch input e.g. on iOS.
2831
virtual void onTouch(InputTouchEvent touch) {}
29-
virtual void setDarkMode(bool dark_mode) {}
32+
virtual void setDarkMode(bool dark_mode) {
33+
this->dark_mode = dark_mode;
34+
}
35+
virtual void populateDebugMenu() override;
3036
};
3137

3238
class GraphicsAPIInternal : public GraphicsAPI, public APIInternal {

src/core/include/growl/core/api/system_api.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class File;
1616
class Window;
1717

1818
class SystemAPI {
19+
friend class SystemAPIInternal;
20+
1921
public:
2022
virtual ~SystemAPI() {}
2123
virtual bool isRunning() = 0;
@@ -46,7 +48,7 @@ class SystemAPI {
4648
virtual void setLogLevel(LogLevel log_level) = 0;
4749

4850
virtual bool isDarkMode() {
49-
return false;
51+
return dark_mode;
5052
}
5153

5254
virtual Result<std::unique_ptr<File>>
@@ -56,6 +58,9 @@ class SystemAPI {
5658
virtual void
5759
logInternal(LogLevel log_level, std::string tag, std::string formatted) = 0;
5860
InputProcessor* inputProcessor = nullptr;
61+
62+
private:
63+
bool dark_mode;
5964
};
6065

6166
} // namespace Growl

src/core/include/growl/core/imgui.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace Growl {
66

7-
void imGuiBegin();
7+
class API;
8+
9+
void imGuiBegin(API& api);
810
void imGuiBeginGameWindow();
911
void imGuiEndGameWindow();
1012
bool imGuiGameWindowFocused();
@@ -20,6 +22,7 @@ int game_window_y;
2022
int game_window_w = 0;
2123
int game_window_h = 0;
2224
bool game_window_resized;
25+
bool system_api_view = false;
2326
} // namespace
2427
} // namespace Growl
2528

src/core/src/api/api.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#include "growl/core/api/api.h"
22
#include "growl/core/api/api_internal.h"
3+
#ifdef GROWL_IMGUI
4+
#include "imgui.h"
5+
#endif
36

47
using Growl::API;
8+
using Growl::SystemAPIInternal;
59

610
void API::addSystemAPI(std::unique_ptr<SystemAPIInternal> internal) {
711
systemInternal = std::move(internal);
@@ -18,3 +22,12 @@ void API::addAudioAPI(std::unique_ptr<AudioAPIInternal> internal) {
1822
void API::addScriptingAPI(std::unique_ptr<ScriptingAPIInternal> internal) {
1923
scriptingInternal = std::move(internal);
2024
}
25+
26+
#ifdef GROWL_IMGUI
27+
void SystemAPIInternal::populateDebugMenu() {
28+
bool dark_mode = isDarkMode();
29+
if (ImGui::Checkbox("Dark mode", &dark_mode)) {
30+
setDarkMode(dark_mode);
31+
}
32+
}
33+
#endif

src/core/src/imgui.cpp

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
#ifdef GROWL_IMGUI
2-
32
#include "growl/core/imgui.h"
3+
#include "growl/core/api/api.h"
44
#include "imgui.h"
55

6-
void Growl::imGuiBegin() {
6+
constexpr const char* SYSTEM_API_WINDOW = "System API";
7+
8+
namespace Growl {
9+
void doApiWindows(API& api) {
10+
if (system_api_view) {
11+
ImGui::Begin(SYSTEM_API_WINDOW, &system_api_view);
12+
static_cast<SystemAPIInternal&>(api.system()).populateDebugMenu();
13+
ImGui::End();
14+
}
15+
}
16+
} // namespace Growl
17+
18+
void Growl::imGuiBegin(API& api) {
719
ImGui::NewFrame();
820
ImGui::BeginMainMenuBar();
921
ImGui::Text("Growl");
22+
if (ImGui::BeginMenu("Views")) {
23+
ImGui::SeparatorText("Growl APIs");
24+
ImGui::MenuItem("System API", nullptr, &system_api_view);
25+
ImGui::EndMenu();
26+
}
1027
auto size = ImGui::CalcTextSize("0.00 ms/frame (000.0 FPS)");
1128
ImGuiStyle& style = ImGui::GetStyle();
1229
size.x += style.FramePadding.x * 2 + style.ItemSpacing.x;
@@ -19,6 +36,7 @@ void Growl::imGuiBegin() {
1936
ImGui::EndMainMenuBar();
2037
ImGuiID dockspace_id = ImGui::GetID("DockSpace");
2138
ImGui::DockSpaceOverViewport(dockspace_id);
39+
doApiWindows(api);
2240
}
2341

2442
void Growl::imGuiBeginGameWindow() {

src/plugins/ios/src/ios_system.h

-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ class IOSSystemAPI : public SystemAPIInternal {
1818
return running;
1919
}
2020

21-
void setDarkMode(bool dark_mode) override;
22-
bool isDarkMode() override;
23-
2421
virtual Result<std::unique_ptr<Window>>
2522
createWindow(const Config& config) override;
2623
void setLogLevel(LogLevel log_level) override;
@@ -40,7 +37,6 @@ class IOSSystemAPI : public SystemAPIInternal {
4037

4138
API& api;
4239
bool running;
43-
bool dark_mode;
4440
GCController* controller = nullptr;
4541
id game_controller_connect_observer;
4642
id game_controller_disconnect_observer;

src/plugins/ios/src/ios_system.mm

-8
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,6 @@
9393
OS_LOG_DEFAULT, OS_LOG_TYPE_DEBUG, "[%s] %s", tag.c_str(), msg.c_str());
9494
}
9595

96-
void IOSSystemAPI::setDarkMode(bool dark_mode) {
97-
this->dark_mode = dark_mode;
98-
}
99-
100-
bool IOSSystemAPI::isDarkMode() {
101-
return dark_mode;
102-
}
103-
10496
Result<std::unique_ptr<File>>
10597
IOSSystemAPI::openFile(std::string path, size_t start, size_t end) {
10698
auto full_path =

src/plugins/metal/src/metal_graphics.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
// Start the Dear ImGui frame
6666
ImGui_ImplMetal_NewFrame(imgui_pass);
6767
window->newImguiFrame();
68-
imGuiBegin();
68+
imGuiBegin(api);
6969
#endif
7070
}
7171

src/plugins/opengl/src/opengl_graphics.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void OpenGLGraphicsAPI::begin() {
4747
#ifdef GROWL_IMGUI
4848
ImGui_ImplOpenGL3_NewFrame();
4949
window->newImguiFrame();
50-
imGuiBegin();
50+
imGuiBegin(api);
5151
#endif
5252
}
5353

0 commit comments

Comments
 (0)