yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
iwindow.h
Go to the documentation of this file.
1// iwindow.h - Window Backend Abstraction Layer
2// Provides interface for swapping window implementations (SDL2, SDL3)
3
4#ifndef YAZE_APP_PLATFORM_IWINDOW_H_
5#define YAZE_APP_PLATFORM_IWINDOW_H_
6
7#include <cstdint>
8#include <memory>
9#include <string>
10
11#include "absl/status/status.h"
14
15// Forward declarations to avoid SDL header dependency in interface
16struct SDL_Window;
17
18namespace yaze {
19namespace platform {
20
25 std::string title = "Yet Another Zelda3 Editor";
26 int width = 0; // 0 means auto-detect from display
27 int height = 0; // 0 means auto-detect from display
28 float display_scale = 0.8f; // Percentage of display to use when auto-detect
29 bool resizable = true;
30 bool maximized = false;
31 bool fullscreen = false;
32 bool high_dpi =
33 false; // Disabled by default - causes issues on macOS Retina with SDL_Renderer
34 bool hidden = false; // Start window hidden (for service mode)
35};
36
61
67
68 // Window resize data
69 int window_width = 0;
71
72 // Keyboard data
73 int key_code = 0;
74 int scan_code = 0;
75 bool key_shift = false;
76 bool key_ctrl = false;
77 bool key_alt = false;
78 bool key_super = false;
79
80 // Mouse data
81 float mouse_x = 0.0f;
82 float mouse_y = 0.0f;
83 int mouse_button = 0;
84 float wheel_x = 0.0f;
85 float wheel_y = 0.0f;
86
87 // Drop file data
88 std::string dropped_file;
89
90 // Native event copy (SDL2/SDL3). Only valid when has_native_event is true.
91 bool has_native_event = false;
92 SDL_Event native_event{};
93};
94
104bool PushWakeEvent();
105
112bool IsWakeEvent(const SDL_Event& event);
113
118 bool is_active = true;
119 bool is_minimized = false;
120 bool is_maximized = false;
121 bool is_fullscreen = false;
122 bool is_focused = true;
123 bool is_resizing = false;
124 int width = 0;
125 int height = 0;
126};
127
136 public:
137 virtual ~IWindowBackend() = default;
138
139 // =========================================================================
140 // Lifecycle Management
141 // =========================================================================
142
148 virtual absl::Status Initialize(const WindowConfig& config) = 0;
149
154 virtual absl::Status Shutdown() = 0;
155
159 virtual bool IsInitialized() const = 0;
160
161 // =========================================================================
162 // Event Processing
163 // =========================================================================
164
170 virtual bool PollEvent(WindowEvent& out_event) = 0;
171
176 virtual void ProcessNativeEvent(void* native_event) = 0;
177
185 virtual bool WaitForEvent(int timeout_ms) {
186 (void)timeout_ms;
187 return false;
188 }
189
200 virtual void WakeEventLoop() {
201 if (GetSDLVersion() != 0) {
203 }
204 }
205
206 // =========================================================================
207 // Window State
208 // =========================================================================
209
213 virtual WindowStatus GetStatus() const = 0;
214
218 virtual bool IsActive() const = 0;
219
223 virtual void SetActive(bool active) = 0;
224
228 virtual void GetSize(int* width, int* height) const = 0;
229
233 virtual void SetSize(int width, int height) = 0;
234
238 virtual std::string GetTitle() const = 0;
239
243 virtual void SetTitle(const std::string& title) = 0;
244
248 virtual void ShowWindow() = 0;
249
253 virtual void HideWindow() = 0;
254
255 // =========================================================================
256 // Renderer Integration
257 // =========================================================================
258
264 virtual bool InitializeRenderer(gfx::IRenderer* renderer) = 0;
265
270 virtual SDL_Window* GetNativeWindow() = 0;
271
272 // =========================================================================
273 // ImGui Integration
274 // =========================================================================
275
281 virtual absl::Status InitializeImGui(gfx::IRenderer* renderer) = 0;
282
286 virtual void ShutdownImGui() = 0;
287
291 virtual void NewImGuiFrame() = 0;
292
297 virtual void RenderImGui(gfx::IRenderer* renderer) = 0;
298
299 // =========================================================================
300 // Audio Support (Legacy compatibility)
301 // =========================================================================
302
306 virtual uint32_t GetAudioDevice() const = 0;
307
311 virtual std::shared_ptr<int16_t> GetAudioBuffer() const = 0;
312
313 // =========================================================================
314 // Backend Information
315 // =========================================================================
316
320 virtual std::string GetBackendName() const = 0;
321
325 virtual int GetSDLVersion() const = 0;
326};
327
332 SDL2,
333 SDL3,
334 GLFW, // Reserved for future native multi-viewport backend
335 IOS,
336 Null, // Headless/Server mode
337 Auto // Automatically select based on availability
338};
339
344 public:
350 static std::unique_ptr<IWindowBackend> Create(WindowBackendType type);
351
356
360 static bool IsAvailable(WindowBackendType type);
361};
362
363} // namespace platform
364} // namespace yaze
365
366#endif // YAZE_APP_PLATFORM_IWINDOW_H_
Defines an abstract interface for all rendering operations.
Definition irenderer.h:60
Abstract window backend interface.
Definition iwindow.h:135
virtual void WakeEventLoop()
Make a WaitForEvent() in progress on the UI thread return now.
Definition iwindow.h:200
virtual int GetSDLVersion() const =0
Get SDL version being used.
virtual void ShowWindow()=0
Show the window.
virtual uint32_t GetAudioDevice() const =0
Get audio device ID (for legacy audio buffer management)
virtual absl::Status Shutdown()=0
Shutdown the window backend and release resources.
virtual void SetSize(int width, int height)=0
Set window dimensions.
virtual WindowStatus GetStatus() const =0
Get current window status.
virtual std::string GetTitle() const =0
Get window title.
virtual void GetSize(int *width, int *height) const =0
Get window dimensions.
virtual absl::Status Initialize(const WindowConfig &config)=0
Initialize the window backend with configuration.
virtual void ShutdownImGui()=0
Shutdown ImGui backends.
virtual bool PollEvent(WindowEvent &out_event)=0
Poll and process pending events.
virtual std::shared_ptr< int16_t > GetAudioBuffer() const =0
Get audio buffer (for legacy audio management)
virtual SDL_Window * GetNativeWindow()=0
Get the underlying SDL_Window pointer for ImGui integration.
virtual bool IsInitialized() const =0
Check if the backend is initialized.
virtual bool InitializeRenderer(gfx::IRenderer *renderer)=0
Initialize renderer for this window.
virtual absl::Status InitializeImGui(gfx::IRenderer *renderer)=0
Initialize ImGui backends for this window/renderer combo.
virtual bool WaitForEvent(int timeout_ms)
Block until an event is pending or the timeout passes.
Definition iwindow.h:185
virtual void SetActive(bool active)=0
Set window active state.
virtual void ProcessNativeEvent(void *native_event)=0
Process a native SDL event (for ImGui integration)
virtual void RenderImGui(gfx::IRenderer *renderer)=0
Render ImGui draw data (and viewports if enabled)
virtual std::string GetBackendName() const =0
Get backend name for debugging/logging.
virtual void SetTitle(const std::string &title)=0
Set window title.
virtual ~IWindowBackend()=default
virtual void HideWindow()=0
Hide the window.
virtual void NewImGuiFrame()=0
Start a new ImGui frame.
virtual bool IsActive() const =0
Check if window is still active (not closed)
Factory for creating window backends.
Definition iwindow.h:343
static WindowBackendType GetDefaultType()
Get the default backend type for this build.
static std::unique_ptr< IWindowBackend > Create(WindowBackendType type)
Create a window backend of the specified type.
static bool IsAvailable(WindowBackendType type)
Check if a backend type is available.
bool PushWakeEvent()
Push an SDL user event that only wakes the frame loop.
bool IsWakeEvent(const SDL_Event &event)
True for an event pushed by PushWakeEvent().
WindowEventType
Window event types (platform-agnostic)
Definition iwindow.h:40
WindowBackendType
Backend type enumeration for factory.
Definition iwindow.h:331
SDL2/SDL3 compatibility layer.
Window configuration parameters.
Definition iwindow.h:24
Platform-agnostic window event data.
Definition iwindow.h:65
WindowEventType type
Definition iwindow.h:66
Window backend status information.
Definition iwindow.h:117