yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
null_window_backend.cc
Go to the documentation of this file.
1// null_window_backend.cc - Null Window Backend Implementation (Headless)
2
6#include "util/log.h"
7#include "imgui/imgui.h"
8
9namespace yaze {
10namespace platform {
11
12absl::Status NullWindowBackend::Initialize(const WindowConfig& config) {
13 LOG_INFO("NullWindowBackend", "Initializing headless window backend...");
14 initialized_ = true;
15 active_ = true;
16 width_ = config.width > 0 ? config.width : 1280;
17 height_ = config.height > 0 ? config.height : 720;
18 return absl::OkStatus();
19}
20
22 LOG_INFO("NullWindowBackend", "Shutting down headless window backend");
23
26 }
27
28 // CRITICAL: Shutdown graphics arena while renderer is still conceptually valid
29 LOG_INFO("NullWindowBackend", "Shutting down graphics arena...");
31
32 initialized_ = false;
33 return absl::OkStatus();
34}
35
37 // No events in headless mode
38 return false;
39}
40
41void NullWindowBackend::ProcessNativeEvent(void* native_event) {
42 // No-op
43}
44
46 WindowStatus status;
47 status.is_active = active_;
48 status.width = width_;
49 status.height = height_;
50 // All other flags false
51 return status;
52}
53
54void NullWindowBackend::GetSize(int* width, int* height) const {
55 if (width) *width = width_;
56 if (height) *height = height_;
57}
58
59void NullWindowBackend::SetSize(int width, int height) {
60 width_ = width;
61 height_ = height;
62}
63
65 // Return true to pretend renderer is initialized
66 return true;
67}
68
70 // Even in headless, we might want a minimal ImGui context for test automation logic
71 // that depends on ImGui::GetIO() or similar, though we won't render.
72 if (ImGui::GetCurrentContext() == nullptr) {
73 IMGUI_CHECKVERSION();
74 ImGui::CreateContext();
75 ImGuiIO& io = ImGui::GetIO();
76 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Required for layout initialization
77 io.IniFilename = nullptr;
78 io.DisplaySize = ImVec2((float)width_, (float)height_);
79 io.DeltaTime = 1.0f / 60.0f;
80
81 // Load standard fonts so panels don't crash accessing them
82 auto status = LoadPackageFonts();
83 if (!status.ok()) {
84 LOG_WARN("NullWindowBackend", "Failed to load package fonts: %s", status.ToString().c_str());
85 }
86
87 // Build font atlas so NewFrame doesn't crash
88 unsigned char* pixels;
89 int width, height;
90 io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
91 io.Fonts->SetTexID((ImTextureID)(intptr_t)1); // Dummy ID
92
93 imgui_initialized_ = true;
94 }
95 return absl::OkStatus();
96}
97
99 if (imgui_initialized_ && ImGui::GetCurrentContext() != nullptr) {
100 ImGui::DestroyContext();
101 imgui_initialized_ = false;
102 }
103}
104
106 if (imgui_initialized_) {
107 ImGuiIO& io = ImGui::GetIO();
108 io.DisplaySize = ImVec2((float)width_, (float)height_);
109 io.DeltaTime = 1.0f / 60.0f;
110 }
111}
112
114 if (imgui_initialized_ && ImGui::GetCurrentContext() != nullptr) {
115 ImGui::Render();
116 }
117}
118
119} // namespace platform
120} // namespace yaze
void Shutdown()
Definition arena.cc:371
static Arena & Get()
Definition arena.cc:21
Defines an abstract interface for all rendering operations.
Definition irenderer.h:60
bool PollEvent(WindowEvent &out_event) override
Poll and process pending events.
absl::Status Shutdown() override
Shutdown the window backend and release resources.
absl::Status Initialize(const WindowConfig &config) override
Initialize the window backend with configuration.
bool InitializeRenderer(gfx::IRenderer *renderer) override
Initialize renderer for this window.
WindowStatus GetStatus() const override
Get current window status.
void SetSize(int width, int height) override
Set window dimensions.
void NewImGuiFrame() override
Start a new ImGui frame.
void RenderImGui(gfx::IRenderer *renderer) override
Render ImGui draw data (and viewports if enabled)
void ShutdownImGui() override
Shutdown ImGui backends.
void GetSize(int *width, int *height) const override
Get window dimensions.
void ProcessNativeEvent(void *native_event) override
Process a native SDL event (for ImGui integration)
absl::Status InitializeImGui(gfx::IRenderer *renderer) override
Initialize ImGui backends for this window/renderer combo.
#define LOG_WARN(category, format,...)
Definition log.h:107
#define LOG_INFO(category, format,...)
Definition log.h:105
absl::Status LoadPackageFonts()
Window configuration parameters.
Definition iwindow.h:24
Platform-agnostic window event data.
Definition iwindow.h:65
Window backend status information.
Definition iwindow.h:98