yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
sdl3_window_backend.h
Go to the documentation of this file.
1// sdl3_window_backend.h - SDL3 Window Backend Implementation
2
3#ifndef YAZE_APP_PLATFORM_SDL3_WINDOW_BACKEND_H_
4#define YAZE_APP_PLATFORM_SDL3_WINDOW_BACKEND_H_
5
6// Only compile SDL3 backend when YAZE_USE_SDL3 is defined
7#ifdef YAZE_USE_SDL3
8
9#include <SDL3/SDL.h>
10
11#include <memory>
12#include <string>
13
14#include "absl/status/status.h"
16
17namespace yaze {
18namespace platform {
19
20// Forward declaration for unique_ptr custom deleter
21struct SDL3WindowDeleter {
22 void operator()(SDL_Window* p) const {
23 if (p)
24 SDL_DestroyWindow(p);
25 }
26};
27
37class SDL3WindowBackend : public IWindowBackend {
38 public:
39 SDL3WindowBackend() = default;
40 ~SDL3WindowBackend() override;
41
42 // =========================================================================
43 // IWindowBackend Implementation
44 // =========================================================================
45
46 absl::Status Initialize(const WindowConfig& config) override;
47 absl::Status Shutdown() override;
48 bool IsInitialized() const override { return initialized_; }
49
50 bool PollEvent(WindowEvent& out_event) override;
51 void ProcessNativeEvent(void* native_event) override;
52 bool WaitForEvent(int timeout_ms) override;
53
54 WindowStatus GetStatus() const override;
55 bool IsActive() const override { return active_; }
56 void SetActive(bool active) override { active_ = active; }
57
58 void GetSize(int* width, int* height) const override;
59 void SetSize(int width, int height) override;
60 std::string GetTitle() const override;
61 void SetTitle(const std::string& title) override;
62
63 void ShowWindow() override;
64 void HideWindow() override;
65
66 bool InitializeRenderer(gfx::IRenderer* renderer) override;
67 SDL_Window* GetNativeWindow() override { return window_.get(); }
68
69 absl::Status InitializeImGui(gfx::IRenderer* renderer) override;
70 void ShutdownImGui() override;
71 void NewImGuiFrame() override;
72 void RenderImGui(gfx::IRenderer* renderer) override;
73
74 uint32_t GetAudioDevice() const override { return 0; } // SDL3 uses streams
75 std::shared_ptr<int16_t> GetAudioBuffer() const override {
76 return audio_buffer_;
77 }
78
79 std::string GetBackendName() const override { return "SDL3"; }
80 int GetSDLVersion() const override { return 3; }
81
82 private:
83 // Convert SDL3 event to platform-agnostic WindowEvent
84 WindowEvent ConvertSDL3Event(const SDL_Event& sdl_event);
85
86 // Update modifier key state from SDL3
87 void UpdateModifierState();
88
89 std::unique_ptr<SDL_Window, SDL3WindowDeleter> window_;
90 bool initialized_ = false;
91 bool active_ = true;
92 bool is_resizing_ = false;
93 bool imgui_initialized_ = false;
94
95 // Modifier key state
96 bool key_shift_ = false;
97 bool key_ctrl_ = false;
98 bool key_alt_ = false;
99 bool key_super_ = false;
100
101 // Legacy audio buffer for compatibility
102 std::shared_ptr<int16_t> audio_buffer_;
103};
104
105} // namespace platform
106} // namespace yaze
107
108#endif // YAZE_USE_SDL3
109#endif // YAZE_APP_PLATFORM_SDL3_WINDOW_BACKEND_H_