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 bool InitializeRenderer(gfx::IRenderer* renderer) override;
50 SDL_Window* GetNativeWindow() override { return window_.get(); }
51
52 absl::Status InitializeImGui(gfx::IRenderer* renderer) override;
53 void ShutdownImGui() override;
54 void NewImGuiFrame() override;
55 void RenderImGui(gfx::IRenderer* renderer) override;
56
57 uint32_t GetAudioDevice() const override { return audio_device_; }
58 std::shared_ptr<int16_t> GetAudioBuffer() const override {
59 return audio_buffer_;
60 }
61
62 std::string GetBackendName() const override { return "SDL2"; }
63 int GetSDLVersion() const override { return 2; }
64
65 private:
66 // Convert SDL2 event to platform-agnostic WindowEvent
67 WindowEvent ConvertSDL2Event(const SDL_Event& sdl_event);
68
69 // Update modifier key state from SDL
71
72 std::unique_ptr<SDL_Window, util::SDL_Deleter> window_;
73 bool initialized_ = false;
74 bool active_ = true;
75 bool is_resizing_ = false;
76 bool imgui_initialized_ = false;
77
78 // Modifier key state
79 bool key_shift_ = false;
80 bool key_ctrl_ = false;
81 bool key_alt_ = false;
82 bool key_super_ = false;
83
84 // Legacy audio support
85 SDL_AudioDeviceID audio_device_ = 0;
86 std::shared_ptr<int16_t> audio_buffer_;
87};
88
89} // namespace platform
90} // namespace yaze
91
92#endif // YAZE_APP_PLATFORM_SDL2_WINDOW_BACKEND_H_
Defines an abstract interface for all rendering operations.
Definition irenderer.h:40
Abstract window backend interface.
Definition iwindow.h:114
SDL2 implementation of the window backend interface.
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.
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:63
Window backend status information.
Definition iwindow.h:96