MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Window.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Vruta {
6class WindowEventSource;
7}
8
9namespace MayaFlux::Buffers {
10class VKBuffer;
11}
12
13namespace MayaFlux::Core {
14
15/**
16 * @class Window
17 * @brief Platform-agnostic window wrapper
18 *
19 * Wraps a window (provided via a backend) and provides a unified interface
20 * for window management, event handling, and state tracking.
21 */
22class MAYAFLUX_API Window {
23public:
24 virtual ~Window() = default;
25
26 /**
27 * @brief Show the window
28 */
29 virtual void show() = 0;
30
31 /**
32 * @brief Hide the window
33 */
34 virtual void hide() = 0;
35
36 /**
37 * @brief Destroy the window and release resources
38 */
39 virtual void destroy() = 0;
40
41 /**
42 * @brief Poll for window events (non-blocking)
43 */
44 [[nodiscard]] virtual bool should_close() const = 0;
45
46 /**
47 * @brief Close the window as if the user had closed it
48 *
49 * Marks it for the usual teardown and signals WINDOW_CLOSED once. Safe to
50 * call from an event handler: the signal is delivered after the dispatch
51 * in progress has finished. Call from the thread that polls the window's
52 * events.
53 */
54 virtual void request_close() = 0;
55
56 /**
57 * @brief Get the current window state
58 */
59 [[nodiscard]] virtual const WindowState& get_state() const = 0;
60
61 /*
62 * @brief Get the window creation parameters
63 */
64 [[nodiscard]] virtual const WindowCreateInfo& get_create_info() const = 0;
65
66 /**
67 * @brief Set input configuration (keyboard, mouse, cursor)
68 * @param config Input configuration settings
69 */
70 virtual void set_input_config(const InputConfig& config) = 0;
71
72 /**
73 * @brief Get current input configuration
74 * @return Current input configuration settings
75 */
76 [[nodiscard]] virtual const InputConfig& get_input_config() const = 0;
77
78 /**
79 * @brief Set the callback function for window events
80 * @param callback Function to be called on window events
81 */
83
84 /**
85 * @brief Get native window handle (platform-specific)
86 * @return Pointer to the native window handle
87 */
88 [[nodiscard]] virtual void* get_native_handle() const = 0;
89
90 /**
91 * @brief Get native display handle (platform-specific)
92 * @return Pointer to the native display handle
93 */
94 [[nodiscard]] virtual void* get_native_display() const = 0;
95
96 /**
97 * @brief Set window title, size, or position
98 * @param title New window title
99 */
100 virtual void set_title(const std::string& title) = 0;
101
102 /**
103 * @brief Resize the window
104 * @param width New window width
105 * @param height New window height
106 */
107 virtual void set_size(uint32_t width, uint32_t height) = 0;
108
109 /**
110 * @brief Move the window to a new position
111 * @param x New X coordinate
112 * @param y New Y coordinate
113 */
114 virtual void set_position(uint32_t x, uint32_t y) = 0;
115
116 /**
117 * @brief Set the clear color for the window
118 * @param color RGBA color array
119 */
120 virtual void set_color(const std::array<float, 4>& color) = 0;
121
122 /**
123 * @brief Gets the event source for awaiting events
124 */
125 [[nodiscard]] virtual Vruta::WindowEventSource& get_event_source() = 0;
126 [[nodiscard]] virtual const Vruta::WindowEventSource& get_event_source() const = 0;
127
128 /**
129 * @brief Check if window is registered with graphics subsystem
130 */
131 [[nodiscard]] virtual bool is_graphics_registered() const = 0;
132
133 /**
134 * @brief Mark window as registered/unregistered with graphics
135 * Called by GraphicsSubsystem during register/unregister
136 */
137 virtual void set_graphics_registered(bool registered) = 0;
138
139 /**
140 * @brief Register a VKBuffer as rendering to this window
141 * @param buffer Buffer that will render to this window
142 *
143 * Used for tracking and queries. Does not affect rendering directly.
144 */
145 virtual void register_rendering_buffer(std::shared_ptr<Buffers::VKBuffer> buffer) = 0;
146
147 /**
148 * @brief Unregister a VKBuffer from this window
149 * @param buffer Buffer to unregister
150 */
151 virtual void unregister_rendering_buffer(std::shared_ptr<Buffers::VKBuffer> buffer) = 0;
152
153 /**
154 * @brief Drain platform-native event queue into WindowEventSource.
155 *
156 * Called once per frame by WindowManager::process(), or directly for a
157 * standalone window. Callbacks and awaiters run on the calling thread.
158 */
159 virtual void poll() { }
160
161 /**
162 * @brief Track a secondary command buffer for this frame
163 * @param cmd_id Command buffer ID that contains draw commands for this window
164 *
165 * Called by RenderProcessor after recording. PresentProcessor queries these
166 * to know which secondary buffers to execute.
167 */
168 virtual void track_frame_command(uint64_t cmd_id) = 0;
169
170 /**
171 * @brief Get all command buffers recorded for this frame
172 * @return Vector of command buffer IDs
173 *
174 * Called by PresentProcessor to collect secondary buffers for execution.
175 */
176 [[nodiscard]] virtual const std::vector<uint64_t>& get_frame_commands() const = 0;
177
178 /**
179 * @brief Clear tracked commands for this frame
180 *
181 * Called after presenting to reset for next frame.
182 */
183 virtual void clear_frame_commands() = 0;
184
185 /**
186 * @brief Whether per-frame surface capture is enabled for this window.
187 *
188 * Defaults to false. When false, the graphics backend skips the capture
189 * copy and readback entirely, so trivial windows incur no capture cost.
190 * Enable only on windows whose frames are consumed via
191 * DisplayService::get_last_frame or Kakshya readback.
192 */
193 [[nodiscard]] virtual bool is_capture_enabled() const = 0;
194
195 /**
196 * @brief Enable or disable per-frame surface capture for this window.
197 */
198 virtual void set_capture_enabled(bool enabled) = 0;
199
200 /**
201 * @brief Get all VKBuffers currently rendering to this window
202 * @return Vector of buffers (weak_ptr to avoid ownership issues)
203 */
204 [[nodiscard]] virtual std::vector<std::shared_ptr<Buffers::VKBuffer>> get_rendering_buffers() const = 0;
205};
206
207/**
208 * @brief Check if a Unicode codepoint is valid for text input
209 * @param codepoint Unicode codepoint to check
210 * @return true if valid, false otherwise
211 *
212 * Valid codepoints are:
213 * - >= 0x20 (space) and <= 0x10FFFF (max Unicode)
214 * - Not 0x7F (DEL)
215 * - Not in the surrogate range 0xD800-0xDFFF
216 */
217[[nodiscard]] inline constexpr bool is_text_input_codepoint(
218 uint32_t codepoint) noexcept
219{
220 return codepoint >= 0x20
221 && codepoint != 0x7F
222 && (codepoint < 0xD800 || codepoint > 0xDFFF)
223 && codepoint <= 0x10FFFF;
224}
225
226} // namespace MayaFlux::Core
glm::vec3 color
Definition Decoder.cpp:97
std::shared_ptr< NetworkGeometryBuffer > buffer
PickCallback callback
Definition Picker.cpp:22
uint32_t width
uint32_t height
virtual void unregister_rendering_buffer(std::shared_ptr< Buffers::VKBuffer > buffer)=0
Unregister a VKBuffer from this window.
virtual void destroy()=0
Destroy the window and release resources.
virtual void set_capture_enabled(bool enabled)=0
Enable or disable per-frame surface capture for this window.
virtual void register_rendering_buffer(std::shared_ptr< Buffers::VKBuffer > buffer)=0
Register a VKBuffer as rendering to this window.
virtual void set_input_config(const InputConfig &config)=0
Set input configuration (keyboard, mouse, cursor)
virtual void * get_native_display() const =0
Get native display handle (platform-specific)
virtual bool is_capture_enabled() const =0
Whether per-frame surface capture is enabled for this window.
virtual void track_frame_command(uint64_t cmd_id)=0
Track a secondary command buffer for this frame.
virtual ~Window()=default
virtual void set_graphics_registered(bool registered)=0
Mark window as registered/unregistered with graphics Called by GraphicsSubsystem during register/unre...
virtual void set_event_callback(WindowEventCallback callback)=0
Set the callback function for window events.
virtual const WindowCreateInfo & get_create_info() const =0
virtual void request_close()=0
Close the window as if the user had closed it.
virtual void hide()=0
Hide the window.
virtual void set_color(const std::array< float, 4 > &color)=0
Set the clear color for the window.
virtual void set_title(const std::string &title)=0
Set window title, size, or position.
virtual void * get_native_handle() const =0
Get native window handle (platform-specific)
virtual void poll()
Drain platform-native event queue into WindowEventSource.
Definition Window.hpp:159
virtual void clear_frame_commands()=0
Clear tracked commands for this frame.
virtual void set_size(uint32_t width, uint32_t height)=0
Resize the window.
virtual std::vector< std::shared_ptr< Buffers::VKBuffer > > get_rendering_buffers() const =0
Get all VKBuffers currently rendering to this window.
virtual bool is_graphics_registered() const =0
Check if window is registered with graphics subsystem.
virtual const WindowState & get_state() const =0
Get the current window state.
virtual const InputConfig & get_input_config() const =0
Get current input configuration.
virtual void show()=0
Show the window.
virtual const Vruta::WindowEventSource & get_event_source() const =0
virtual Vruta::WindowEventSource & get_event_source()=0
Gets the event source for awaiting events.
virtual const std::vector< uint64_t > & get_frame_commands() const =0
Get all command buffers recorded for this frame.
virtual void set_position(uint32_t x, uint32_t y)=0
Move the window to a new position.
virtual bool should_close() const =0
Poll for window events (non-blocking)
Platform-agnostic window wrapper.
Definition Window.hpp:22
Awaitable stream of window input events.
constexpr bool is_text_input_codepoint(uint32_t codepoint) noexcept
Check if a Unicode codepoint is valid for text input.
Definition Window.hpp:217
std::function< void(const WindowEvent &)> WindowEventCallback
Input configuration for a window.
Configuration for creating a single window instance.
Runtime state of a window (mutable by system, read by user)