MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Windowing.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux {
6
7namespace Core {
8 struct GraphicsSurfaceInfo;
9 class WindowManager;
10 class Window;
11 struct WindowCreateInfo;
12}
13
14/**
15 * @brief Gets a handle to default window manager
16 * @return Reference to the WindowManager
17 */
18MAYAFLUX_API Core::WindowManager& get_window_manager();
19
20/**
21 * @brief Create a new window with specified parameters
22 * @param create_info Struct containing window creation parameters (title, dimensions, monitor_id, surface format overrides, etc.)
23 * @return Shared pointer to the created Window instance
24 *
25 * This function abstracts away platform-specific window creation details.
26 * The returned Window object can be used for rendering and event handling.
27 */
28MAYAFLUX_API std::shared_ptr<Core::Window> create_window(const Core::WindowCreateInfo& create_info);
29
30/**
31 * @brief Convert window pixel coordinates to normalized device coordinates (NDC)
32 * @param window_x X coordinate in window space [0, width]
33 * @param window_y Y coordinate in window space [0, height] (top-left origin)
34 * @param window_width Window width in pixels
35 * @param window_height Window height in pixels
36 * @return NDC coordinates as vec3 (x, y, 0.0) in range [-1, +1] (center origin, +Y up)
37 *
38 * Window coordinates use top-left origin with Y increasing downward.
39 * NDC coordinates use center origin with Y increasing upward.
40 * Z is always set to 0.0 for 2D screen-space positions.
41 *
42 * Example:
43 * normalize_coords(0, 0, 800, 600) → (-1.0, -1.0, 0.0) // top-left
44 * normalize_coords(400, 300, 800, 600) → (0.0, 0.0, 0.0) // center
45 * normalize_coords(800, 600, 800, 600) → (+1.0, +1.0, 0.0) // bottom-right
46 */
47MAYAFLUX_API glm::vec3 normalize_coords(double window_x, double window_y,
48 uint32_t window_width, uint32_t window_height);
49
50/**
51 * @brief Convert window pixel coordinates to NDC using window state
52 * @param window_x X coordinate in window space
53 * @param window_y Y coordinate in window space
54 * @param window Window to extract dimensions from
55 * @return NDC coordinates as vec3 (x, y, 0.0)
56 */
57MAYAFLUX_API glm::vec3 normalize_coords(double window_x, double window_y,
58 const std::shared_ptr<Core::Window>& window);
59
60/**
61 * @brief Convert NDC coordinates to window pixel coordinates
62 * @param ndc_x X coordinate in NDC space [-1, +1]
63 * @param ndc_y Y coordinate in NDC space [-1, +1] (center origin, +Y up)
64 * @param ndc_z Z coordinate (ignored, accepted for convenience when passing vec3)
65 * @param window_width Window width in pixels
66 * @param window_height Window height in pixels
67 * @return Window coordinates in pixels (top-left origin, +Y down)
68 *
69 * Inverse of normalize_coords(). Z coordinate is ignored.
70 */
71MAYAFLUX_API glm::vec2 window_coords(double ndc_x, double ndc_y, double ndc_z,
72 uint32_t window_width, uint32_t window_height);
73
74/**
75 * @brief Convert NDC coordinates to window pixel coordinates using window state
76 * @param ndc_x X coordinate in NDC space
77 * @param ndc_y Y coordinate in NDC space
78 * @param ndc_z Z coordinate (ignored)
79 * @param window Window to extract dimensions from
80 * @return Window coordinates in pixels
81 */
82MAYAFLUX_API glm::vec2 window_coords(double ndc_x, double ndc_y, double ndc_z,
83 const std::shared_ptr<Core::Window>& window);
84
85/**
86 * @brief Convert NDC vec3 position to window pixel coordinates
87 * @param ndc_pos NDC position (z component ignored)
88 * @param window_width Window width in pixels
89 * @param window_height Window height in pixels
90 * @return Window coordinates in pixels
91 */
92MAYAFLUX_API glm::vec2 window_coords(const glm::vec3& ndc_pos,
93 uint32_t window_width, uint32_t window_height);
94
95/**
96 * @brief Convert NDC vec3 position to window pixel coordinates using window state
97 * @param ndc_pos NDC position (z component ignored)
98 * @param window Window to extract dimensions from
99 * @return Window coordinates in pixels
100 */
101MAYAFLUX_API glm::vec2 window_coords(const glm::vec3& ndc_pos,
102 const std::shared_ptr<Core::Window>& window);
103
104/**
105 * @brief Convert an NDC-space size (extent) to integer pixel dimensions.
106 *
107 * NDC spans 2.0 across each axis, so an NDC size of (1.8, 0.1) on a 1280x720
108 * window resolves to (1152, 36) pixels. Both components are clamped to at
109 * least 1 pixel.
110 *
111 * Use this for sizing text images, capture targets, and offscreen images to
112 * match an on-screen NDC region.
113 *
114 * @param ndc_size NDC extent (each component in [0, 2]).
115 * @param window_width Window width in pixels.
116 * @param window_height Window height in pixels.
117 * @return Integer pixel dimensions, each at least 1.
118 */
119MAYAFLUX_API glm::uvec2 normalized_size_to_pixels(
120 const glm::vec2& ndc_size,
121 uint32_t window_width, uint32_t window_height);
122
123/**
124 * @brief Convert an NDC-space size to integer pixel dimensions using window state.
125 * @param ndc_size NDC extent.
126 * @param window Window to extract dimensions from.
127 * @return Integer pixel dimensions, each at least 1.
128 */
129MAYAFLUX_API glm::uvec2 normalized_size_to_pixels(
130 const glm::vec2& ndc_size,
131 const std::shared_ptr<Core::Window>& window);
132
133/**
134 * @brief Convert an NDC AABB's extent to integer pixel dimensions.
135 *
136 * Equivalent to ndc_size_to_pixels(region.max - region.min, ...).
137 *
138 * @param region NDC axis-aligned bounding box.
139 * @param window_width Window width in pixels.
140 * @param window_height Window height in pixels.
141 * @return Integer pixel dimensions of the region's extent.
142 */
143MAYAFLUX_API glm::uvec2 normalized_size_to_pixels(
144 const Kinesis::AABB2D& region,
145 uint32_t window_width, uint32_t window_height);
146
147/**
148 * @brief Convert an NDC AABB's extent to integer pixel dimensions using window state.
149 * @param region NDC axis-aligned bounding box.
150 * @param window Window to extract dimensions from.
151 * @return Integer pixel dimensions of the region's extent.
152 */
153MAYAFLUX_API glm::uvec2 normalized_size_to_pixels(
154 const Kinesis::AABB2D& region,
155 const std::shared_ptr<Core::Window>& window);
156
157/**
158 * @brief Get window aspect ratio (width/height)
159 * @param window_width Window width in pixels
160 * @param window_height Window height in pixels
161 * @return Aspect ratio as float
162 */
163MAYAFLUX_API float aspect_ratio(uint32_t window_width, uint32_t window_height);
164
165/**
166 * @brief Get window aspect ratio from window state
167 * @param window Window to extract dimensions from
168 * @return Aspect ratio as float
169 */
170MAYAFLUX_API float aspect_ratio(const std::shared_ptr<Core::Window>& window);
171
172/**
173 * @brief Normalize coordinates preserving aspect ratio (useful for circular/square shapes)
174 * @param window_x X coordinate in window space
175 * @param window_y Y coordinate in window space
176 * @param window_width Window width in pixels
177 * @param window_height Window height in pixels
178 * @return Aspect-corrected NDC coordinates where circles remain circular
179 *
180 * Unlike normalize_coords(), this ensures geometric shapes maintain their proportions.
181 * The shorter dimension maps to [-1, +1], the longer dimension extends beyond.
182 */
183MAYAFLUX_API glm::vec3 normalize_coords_aspect(double window_x, double window_y,
184 uint32_t window_width, uint32_t window_height);
185
186/**
187 * @brief Normalize coordinates preserving aspect ratio using window state
188 * @param window_x X coordinate in window space
189 * @param window_y Y coordinate in window space
190 * @param window Window to extract dimensions from
191 * @return Aspect-corrected NDC coordinates
192 */
193MAYAFLUX_API glm::vec3 normalize_coords_aspect(double window_x, double window_y,
194 const std::shared_ptr<Core::Window>& window);
195
196/**
197 * @brief Check if a point in window coordinates is inside the window bounds
198 * @param window_x X coordinate in window space
199 * @param window_y Y coordinate in window space
200 * @param window_width Window width in pixels
201 * @param window_height Window height in pixels
202 * @return true if point is within [0, width) × [0, height)
203 */
204MAYAFLUX_API bool is_in_bounds(double window_x, double window_y,
205 uint32_t window_width, uint32_t window_height);
206
207/**
208 * @brief Check if a point in window coordinates is inside the window bounds
209 * @param window_x X coordinate in window space
210 * @param window_y Y coordinate in window space
211 * @param window Window to extract dimensions from
212 * @return true if point is within window bounds
213 */
214MAYAFLUX_API bool is_in_bounds(double window_x, double window_y,
215 const std::shared_ptr<Core::Window>& window);
216
217}
@ Core
Core engine, backend, subsystems.
std::shared_ptr< Core::Window > create_window(const Core::WindowCreateInfo &create_info)
Create a new window with specified parameters.
Definition Windowing.cpp:14
glm::vec2 window_coords(double ndc_x, double ndc_y, double ndc_z, uint32_t window_width, uint32_t window_height)
Convert NDC coordinates to window pixel coordinates.
Definition Windowing.cpp:32
bool is_in_bounds(double window_x, double window_y, uint32_t window_width, uint32_t window_height)
Check if a point in window coordinates is inside the window bounds.
Definition Windowing.cpp:84
glm::vec3 normalize_coords(double window_x, double window_y, uint32_t window_width, uint32_t window_height)
Convert window pixel coordinates to normalized device coordinates (NDC)
Definition Windowing.cpp:19
glm::uvec2 normalized_size_to_pixels(const glm::vec2 &ndc_size, uint32_t window_width, uint32_t window_height)
Convert an NDC-space size (extent) to integer pixel dimensions.
Definition Windowing.cpp:97
glm::vec3 normalize_coords_aspect(double window_x, double window_y, uint32_t window_width, uint32_t window_height)
Normalize coordinates preserving aspect ratio (useful for circular/square shapes)
Definition Windowing.cpp:71
float aspect_ratio(uint32_t window_width, uint32_t window_height)
Get window aspect ratio (width/height)
Definition Windowing.cpp:60
Core::WindowManager & get_window_manager()
Gets a handle to default window manager.
Definition Windowing.cpp:9
Main namespace for the Maya Flux audio engine.
Definition Runtime.cpp:12