MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Windowing.hpp
Go to the documentation of this file.
1#pragma once
2
3namespace MayaFlux {
4
5namespace Core {
6 struct GraphicsSurfaceInfo;
7 class WindowManager;
8 class Window;
9 struct WindowCreateInfo;
10}
11
12/**
13 * @brief Gets a handle to default window manager
14 * @return Reference to the WindowManager
15 */
16MAYAFLUX_API Core::WindowManager& get_window_manager();
17
18/**
19 * @brief Create a new window with specified parameters
20 * @param create_info Struct containing window creation parameters (title, dimensions, monitor_id, surface format overrides, etc.)
21 * @return Shared pointer to the created Window instance
22 *
23 * This function abstracts away platform-specific window creation details.
24 * The returned Window object can be used for rendering and event handling.
25 */
26MAYAFLUX_API std::shared_ptr<Core::Window> create_window(const Core::WindowCreateInfo& create_info);
27
28/**
29 * @brief Convert window pixel coordinates to normalized device coordinates (NDC)
30 * @param window_x X coordinate in window space [0, width]
31 * @param window_y Y coordinate in window space [0, height] (top-left origin)
32 * @param window_width Window width in pixels
33 * @param window_height Window height in pixels
34 * @return NDC coordinates as vec3 (x, y, 0.0) in range [-1, +1] (center origin, +Y up)
35 *
36 * Window coordinates use top-left origin with Y increasing downward.
37 * NDC coordinates use center origin with Y increasing upward.
38 * Z is always set to 0.0 for 2D screen-space positions.
39 *
40 * Example:
41 * normalize_coords(0, 0, 800, 600) → (-1.0, -1.0, 0.0) // top-left
42 * normalize_coords(400, 300, 800, 600) → (0.0, 0.0, 0.0) // center
43 * normalize_coords(800, 600, 800, 600) → (+1.0, +1.0, 0.0) // bottom-right
44 */
45MAYAFLUX_API glm::vec3 normalize_coords(double window_x, double window_y,
46 uint32_t window_width, uint32_t window_height);
47
48/**
49 * @brief Convert window pixel coordinates to NDC using window state
50 * @param window_x X coordinate in window space
51 * @param window_y Y coordinate in window space
52 * @param window Window to extract dimensions from
53 * @return NDC coordinates as vec3 (x, y, 0.0)
54 */
55MAYAFLUX_API glm::vec3 normalize_coords(double window_x, double window_y,
56 const std::shared_ptr<Core::Window>& window);
57
58/**
59 * @brief Convert NDC coordinates to window pixel coordinates
60 * @param ndc_x X coordinate in NDC space [-1, +1]
61 * @param ndc_y Y coordinate in NDC space [-1, +1] (center origin, +Y up)
62 * @param ndc_z Z coordinate (ignored, accepted for convenience when passing vec3)
63 * @param window_width Window width in pixels
64 * @param window_height Window height in pixels
65 * @return Window coordinates in pixels (top-left origin, +Y down)
66 *
67 * Inverse of normalize_coords(). Z coordinate is ignored.
68 */
69MAYAFLUX_API glm::vec2 window_coords(double ndc_x, double ndc_y, double ndc_z,
70 uint32_t window_width, uint32_t window_height);
71
72/**
73 * @brief Convert NDC coordinates to window pixel coordinates using window state
74 * @param ndc_x X coordinate in NDC space
75 * @param ndc_y Y coordinate in NDC space
76 * @param ndc_z Z coordinate (ignored)
77 * @param window Window to extract dimensions from
78 * @return Window coordinates in pixels
79 */
80MAYAFLUX_API glm::vec2 window_coords(double ndc_x, double ndc_y, double ndc_z,
81 const std::shared_ptr<Core::Window>& window);
82
83/**
84 * @brief Convert NDC vec3 position to window pixel coordinates
85 * @param ndc_pos NDC position (z component ignored)
86 * @param window_width Window width in pixels
87 * @param window_height Window height in pixels
88 * @return Window coordinates in pixels
89 */
90MAYAFLUX_API glm::vec2 window_coords(const glm::vec3& ndc_pos,
91 uint32_t window_width, uint32_t window_height);
92
93/**
94 * @brief Convert NDC vec3 position to window pixel coordinates using window state
95 * @param ndc_pos NDC position (z component ignored)
96 * @param window Window to extract dimensions from
97 * @return Window coordinates in pixels
98 */
99MAYAFLUX_API glm::vec2 window_coords(const glm::vec3& ndc_pos,
100 const std::shared_ptr<Core::Window>& window);
101
102/**
103 * @brief Get window aspect ratio (width/height)
104 * @param window_width Window width in pixels
105 * @param window_height Window height in pixels
106 * @return Aspect ratio as float
107 */
108MAYAFLUX_API float aspect_ratio(uint32_t window_width, uint32_t window_height);
109
110/**
111 * @brief Get window aspect ratio from window state
112 * @param window Window to extract dimensions from
113 * @return Aspect ratio as float
114 */
115MAYAFLUX_API float aspect_ratio(const std::shared_ptr<Core::Window>& window);
116
117/**
118 * @brief Normalize coordinates preserving aspect ratio (useful for circular/square shapes)
119 * @param window_x X coordinate in window space
120 * @param window_y Y coordinate in window space
121 * @param window_width Window width in pixels
122 * @param window_height Window height in pixels
123 * @return Aspect-corrected NDC coordinates where circles remain circular
124 *
125 * Unlike normalize_coords(), this ensures geometric shapes maintain their proportions.
126 * The shorter dimension maps to [-1, +1], the longer dimension extends beyond.
127 */
128MAYAFLUX_API glm::vec3 normalize_coords_aspect(double window_x, double window_y,
129 uint32_t window_width, uint32_t window_height);
130
131/**
132 * @brief Normalize coordinates preserving aspect ratio using window state
133 * @param window_x X coordinate in window space
134 * @param window_y Y coordinate in window space
135 * @param window Window to extract dimensions from
136 * @return Aspect-corrected NDC coordinates
137 */
138MAYAFLUX_API glm::vec3 normalize_coords_aspect(double window_x, double window_y,
139 const std::shared_ptr<Core::Window>& window);
140
141/**
142 * @brief Check if a point in window coordinates is inside the window bounds
143 * @param window_x X coordinate in window space
144 * @param window_y Y coordinate in window space
145 * @param window_width Window width in pixels
146 * @param window_height Window height in pixels
147 * @return true if point is within [0, width) × [0, height)
148 */
149MAYAFLUX_API bool is_in_bounds(double window_x, double window_y,
150 uint32_t window_width, uint32_t window_height);
151
152/**
153 * @brief Check if a point in window coordinates is inside the window bounds
154 * @param window_x X coordinate in window space
155 * @param window_y Y coordinate in window space
156 * @param window Window to extract dimensions from
157 * @return true if point is within window bounds
158 */
159MAYAFLUX_API bool is_in_bounds(double window_x, double window_y,
160 const std::shared_ptr<Core::Window>& window);
161
162}
@ 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:18
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:38
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.
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:23
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:78
float aspect_ratio(uint32_t window_width, uint32_t window_height)
Get window aspect ratio (width/height)
Definition Windowing.cpp:67
Core::WindowManager & get_window_manager()
Gets a handle to default window manager.
Definition Windowing.cpp:13
Main namespace for the Maya Flux audio engine.
Definition LiveAid.hpp:6