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) SDL_DestroyWindow(p);
24 }
25};
26
36class SDL3WindowBackend : public IWindowBackend {
37 public:
38 SDL3WindowBackend() = default;
39 ~SDL3WindowBackend() override;
40
41 // =========================================================================
42 // IWindowBackend Implementation
43 // =========================================================================
44
45 absl::Status Initialize(const WindowConfig& config) override;
46 absl::Status Shutdown() override;
47 bool IsInitialized() const override { return initialized_; }
48
49 bool PollEvent(WindowEvent& out_event) override;
50 void ProcessNativeEvent(void* native_event) override;
51
52 WindowStatus GetStatus() const override;
53 bool IsActive() const override { return active_; }
54 void SetActive(bool active) override { active_ = active; }
55
56 void GetSize(int* width, int* height) const override;
57 void SetSize(int width, int height) override;
58 std::string GetTitle() const override;
59 void SetTitle(const std::string& title) override;
60
61 bool InitializeRenderer(gfx::IRenderer* renderer) override;
62 SDL_Window* GetNativeWindow() override { return window_.get(); }
63
64 absl::Status InitializeImGui(gfx::IRenderer* renderer) override;
65 void ShutdownImGui() override;
66 void NewImGuiFrame() override;
67 void RenderImGui(gfx::IRenderer* renderer) override;
68
69 uint32_t GetAudioDevice() const override { return 0; } // SDL3 uses streams
70 std::shared_ptr<int16_t> GetAudioBuffer() const override {
71 return audio_buffer_;
72 }
73
74 std::string GetBackendName() const override { return "SDL3"; }
75 int GetSDLVersion() const override { return 3; }
76
77 private:
78 // Convert SDL3 event to platform-agnostic WindowEvent
79 WindowEvent ConvertSDL3Event(const SDL_Event& sdl_event);
80
81 // Update modifier key state from SDL3
82 void UpdateModifierState();
83
84 std::unique_ptr<SDL_Window, SDL3WindowDeleter> window_;
85 bool initialized_ = false;
86 bool active_ = true;
87 bool is_resizing_ = false;
88 bool imgui_initialized_ = false;
89
90 // Modifier key state
91 bool key_shift_ = false;
92 bool key_ctrl_ = false;
93 bool key_alt_ = false;
94 bool key_super_ = false;
95
96 // Legacy audio buffer for compatibility
97 std::shared_ptr<int16_t> audio_buffer_;
98};
99
100} // namespace platform
101} // namespace yaze
102
103#endif // YAZE_USE_SDL3
104#endif // YAZE_APP_PLATFORM_SDL3_WINDOW_BACKEND_H_