yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
test_editor.cc
Go to the documentation of this file.
1#include "test_editor.h"
2
3#include <SDL.h>
4
6#include "app/core/window.h"
8#include "app/gui/style.h"
9#include "imgui/backends/imgui_impl_sdl2.h"
10#include "imgui/backends/imgui_impl_sdlrenderer2.h"
11#include "imgui.h"
12
13#ifdef IMGUI_ENABLE_TEST_ENGINE
14#include "imgui_test_engine/imgui_te_context.h"
15#include "imgui_test_engine/imgui_te_engine.h"
16#include "imgui_test_engine/imgui_te_imconfig.h"
17#include "imgui_test_engine/imgui_te_ui.h"
18#endif
19
20namespace yaze {
21namespace test {
22
23absl::Status TestEditor::Update() {
24 ImGui::NewFrame();
25 if (ImGui::Begin("My Window")) {
26 ImGui::Text("Hello, world!");
27 ImGui::Button("My Button");
28 }
29
30 static bool show_demo_window = true;
31
32#ifdef IMGUI_ENABLE_TEST_ENGINE
33 ImGuiTestEngine_ShowTestEngineWindows(engine_, &show_demo_window);
34#else
35 ImGui::Text("ImGui Test Engine not available in this build");
36 (void)show_demo_window; // Suppress unused variable warning
37#endif
38
39 ImGui::End();
40
41 return absl::OkStatus();
42}
43
44#ifdef IMGUI_ENABLE_TEST_ENGINE
45void TestEditor::RegisterTests(ImGuiTestEngine* engine) {
46 engine_ = engine;
47 ImGuiTest* test = IM_REGISTER_TEST(engine, "demo_test", "test1");
48 test->TestFunc = [](ImGuiTestContext* ctx) {
49 ctx->SetRef("My Window");
50 ctx->ItemClick("My Button");
51 ctx->ItemCheck("Node/Checkbox");
52 };
53}
54#endif
55
56// TODO: Fix the window/controller management
58 yaze::core::Controller controller;
59 yaze::core::Window window;
60 // Create renderer for test
61 auto test_renderer = std::make_unique<yaze::gfx::SDL2Renderer>();
62 yaze::core::CreateWindow(window, test_renderer.get(), SDL_WINDOW_RESIZABLE);
63 IMGUI_CHECKVERSION();
64 ImGui::CreateContext();
65
66 // Initialize Test Engine (if available)
67#ifdef IMGUI_ENABLE_TEST_ENGINE
68 ImGuiTestEngine* engine = ImGuiTestEngine_CreateContext();
69 ImGuiTestEngineIO& test_io = ImGuiTestEngine_GetIO(engine);
70 test_io.ConfigVerboseLevel = ImGuiTestVerboseLevel_Info;
71 test_io.ConfigVerboseLevelOnError = ImGuiTestVerboseLevel_Debug;
72#else
73 void* engine = nullptr; // Placeholder when test engine is disabled
74#endif
75
76 ImGuiIO& io = ImGui::GetIO();
77 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
78
79 // Initialize ImGui for SDL
80 SDL_Renderer* sdl_renderer = static_cast<SDL_Renderer*>(test_renderer->GetBackendRenderer());
81 ImGui_ImplSDL2_InitForSDLRenderer(controller.window(), sdl_renderer);
82 ImGui_ImplSDLRenderer2_Init(sdl_renderer);
83
84 yaze::test::TestEditor test_editor;
85#ifdef IMGUI_ENABLE_TEST_ENGINE
86 test_editor.RegisterTests(engine);
87 ImGuiTestEngine_Start(engine, ImGui::GetCurrentContext());
88#endif
89 controller.set_active(true);
90
91 // Set the default style
93
94 // Build a new ImGui frame
95 ImGui_ImplSDLRenderer2_NewFrame();
96 ImGui_ImplSDL2_NewFrame();
97
98 while (controller.IsActive()) {
99 controller.OnInput();
100 auto status = test_editor.Update();
101 if (!status.ok()) {
102 return EXIT_FAILURE;
103 }
104 controller.DoRender();
105 }
106
107#ifdef IMGUI_ENABLE_TEST_ENGINE
108 ImGuiTestEngine_Stop(engine);
109#endif
110 controller.OnExit();
111 return EXIT_SUCCESS;
112}
113
114} // namespace test
115} // namespace yaze
Main controller for the application.
Definition controller.h:24
auto window() -> SDL_Window *
Definition controller.h:36
bool IsActive() const
Definition controller.h:26
void set_active(bool active)
Definition controller.h:37
absl::Status Update() override
absl::Status CreateWindow(Window &window, gfx::IRenderer *renderer, int flags)
Definition window.cc:57
void ColorsYaze()
Definition style.cc:32
int RunIntegrationTest()
Main namespace for the application.