yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
sdl2_window_backend.h
Go to the documentation of this file.
1// sdl2_window_backend.h - SDL2 Window Backend Implementation
2
3#ifndef YAZE_APP_PLATFORM_SDL2_WINDOW_BACKEND_H_
4#define YAZE_APP_PLATFORM_SDL2_WINDOW_BACKEND_H_
5
7
8#include <memory>
9#include <string>
10
11#include "absl/status/status.h"
13#include "util/sdl_deleter.h"
14
15namespace yaze {
16namespace platform {
17
25 public:
26 SDL2WindowBackend() = default;
27 ~SDL2WindowBackend() override;
28
29 // =========================================================================
30 // IWindowBackend Implementation
31 // =========================================================================
32
33 absl::Status Initialize(const WindowConfig& config) override;
34 absl::Status Shutdown() override;
35 bool IsInitialized() const override { return initialized_; }
36
37 bool PollEvent(WindowEvent& out_event) override;
38 void ProcessNativeEvent(void* native_event) override;
39
40 WindowStatus GetStatus() const override;
41 bool IsActive() const override { return active_; }
42 void SetActive(bool active) override { active_ = active; }
43
44 void GetSize(int* width, int* height) const override;
45 void SetSize(int width, int height) override;
46 std::string GetTitle() const override;
47 void SetTitle(const std::string& title) override;
48
49 void ShowWindow() override;
50 void HideWindow() override;
51
52 bool InitializeRenderer(gfx::IRenderer* renderer) override;
53 SDL_Window* GetNativeWindow() override { return window_.get(); }
54
55 absl::Status InitializeImGui(gfx::IRenderer* renderer) override;
56 void ShutdownImGui() override;
57 void NewImGuiFrame() override;
58 void RenderImGui(gfx::IRenderer* renderer) override;
59
60 uint32_t GetAudioDevice() const override { return audio_device_; }
61 std::shared_ptr<int16_t> GetAudioBuffer() const override {
62 return audio_buffer_;
63 }
64
65 std::string GetBackendName() const override { return "SDL2"; }
66 int GetSDLVersion() const override { return 2; }
67
68 private:
69 // Convert SDL2 event to platform-agnostic WindowEvent
70 WindowEvent ConvertSDL2Event(const SDL_Event& sdl_event);
71
72 // Update modifier key state from SDL
74
75 std::unique_ptr<SDL_Window, util::SDL_Deleter> window_;
76 bool initialized_ = false;
77 bool active_ = true;
78 bool is_resizing_ = false;
79 bool imgui_initialized_ = false;
80
81 // Modifier key state
82 bool key_shift_ = false;
83 bool key_ctrl_ = false;
84 bool key_alt_ = false;
85 bool key_super_ = false;
86
87 // Legacy audio support
88 SDL_AudioDeviceID audio_device_ = 0;
89 std::shared_ptr<int16_t> audio_buffer_;
90};
91
92} // namespace platform
93} // namespace yaze
94
95#endif // YAZE_APP_PLATFORM_SDL2_WINDOW_BACKEND_H_
Defines an abstract interface for all rendering operations.
Definition irenderer.h:60
Abstract window backend interface.
Definition iwindow.h:116
SDL2 implementation of the window backend interface.
void ShowWindow() override
Show the window.
absl::Status InitializeImGui(gfx::IRenderer *renderer) override
Initialize ImGui backends for this window/renderer combo.
bool IsActive() const override
Check if window is still active (not closed)
void SetTitle(const std::string &title) override
Set window title.
std::shared_ptr< int16_t > GetAudioBuffer() const override
Get audio buffer (for legacy audio management)
int GetSDLVersion() const override
Get SDL version being used.
absl::Status Shutdown() override
Shutdown the window backend and release resources.
bool PollEvent(WindowEvent &out_event) override
Poll and process pending events.
SDL_Window * GetNativeWindow() override
Get the underlying SDL_Window pointer for ImGui integration.
WindowStatus GetStatus() const override
Get current window status.
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)
bool InitializeRenderer(gfx::IRenderer *renderer) override
Initialize renderer for this window.
void SetSize(int width, int height) override
Set window dimensions.
std::shared_ptr< int16_t > audio_buffer_
absl::Status Initialize(const WindowConfig &config) override
Initialize the window backend with configuration.
void SetActive(bool active) override
Set window active state.
void ShutdownImGui() override
Shutdown ImGui backends.
void RenderImGui(gfx::IRenderer *renderer) override
Render ImGui draw data (and viewports if enabled)
WindowEvent ConvertSDL2Event(const SDL_Event &sdl_event)
std::unique_ptr< SDL_Window, util::SDL_Deleter > window_
void NewImGuiFrame() override
Start a new ImGui frame.
void HideWindow() override
Hide the window.
uint32_t GetAudioDevice() const override
Get audio device ID (for legacy audio buffer management)
std::string GetTitle() const override
Get window title.
bool IsInitialized() const override
Check if the backend is initialized.
std::string GetBackendName() const override
Get backend name for debugging/logging.
SDL2/SDL3 compatibility layer.
Window configuration parameters.
Definition iwindow.h:24
Platform-agnostic window event data.
Definition iwindow.h:65
Window backend status information.
Definition iwindow.h:98