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
99 bool is_active = true;
100 bool is_minimized = false;
101 bool is_maximized = false;
102 bool is_fullscreen = false;
103 bool is_focused = true;
104 bool is_resizing = false;
105 int width = 0;
106 int height = 0;
107};
108
117 public:
118 virtual ~IWindowBackend() = default;
119
120 // =========================================================================
121 // Lifecycle Management
122 // =========================================================================
123
129 virtual absl::Status Initialize(const WindowConfig& config) = 0;
130
135 virtual absl::Status Shutdown() = 0;
136
140 virtual bool IsInitialized() const = 0;
141
142 // =========================================================================
143 // Event Processing
144 // =========================================================================
145
151 virtual bool PollEvent(WindowEvent& out_event) = 0;
152
157 virtual void ProcessNativeEvent(void* native_event) = 0;
158
166 virtual bool WaitForEvent(int timeout_ms) {
167 (void)timeout_ms;
168 return false;
169 }
170
171 // =========================================================================
172 // Window State
173 // =========================================================================
174
178 virtual WindowStatus GetStatus() const = 0;
179
183 virtual bool IsActive() const = 0;
184
188 virtual void SetActive(bool active) = 0;
189
193 virtual void GetSize(int* width, int* height) const = 0;
194
198 virtual void SetSize(int width, int height) = 0;
199
203 virtual std::string GetTitle() const = 0;
204
208 virtual void SetTitle(const std::string& title) = 0;
209
213 virtual void ShowWindow() = 0;
214
218 virtual void HideWindow() = 0;
219
220 // =========================================================================
221 // Renderer Integration
222 // =========================================================================
223
229 virtual bool InitializeRenderer(gfx::IRenderer* renderer) = 0;
230
235 virtual SDL_Window* GetNativeWindow() = 0;
236
237 // =========================================================================
238 // ImGui Integration
239 // =========================================================================
240
246 virtual absl::Status InitializeImGui(gfx::IRenderer* renderer) = 0;
247
251 virtual void ShutdownImGui() = 0;
252
256 virtual void NewImGuiFrame() = 0;
257
262 virtual void RenderImGui(gfx::IRenderer* renderer) = 0;
263
264 // =========================================================================
265 // Audio Support (Legacy compatibility)
266 // =========================================================================
267
271 virtual uint32_t GetAudioDevice() const = 0;
272
276 virtual std::shared_ptr<int16_t> GetAudioBuffer() const = 0;
277
278 // =========================================================================
279 // Backend Information
280 // =========================================================================
281
285 virtual std::string GetBackendName() const = 0;
286
290 virtual int GetSDLVersion() const = 0;
291};
292
297 SDL2,
298 SDL3,
299 GLFW, // Reserved for future native multi-viewport backend
300 IOS,
301 Null, // Headless/Server mode
302 Auto // Automatically select based on availability
303};
304
309 public:
315 static std::unique_ptr<IWindowBackend> Create(WindowBackendType type);
316
321
325 static bool IsAvailable(WindowBackendType type);
326};
327
328} // namespace platform
329} // namespace yaze
330
331#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:116
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:166
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:308
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.
WindowEventType
Window event types (platform-agnostic)
Definition iwindow.h:40
WindowBackendType
Backend type enumeration for factory.
Definition iwindow.h:296
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:98