Skip to main content

Window.ixx File

Abstract window interface used by the helios framework. More...

Included Headers

#include <memory> #include <stdexcept> #include <string> #include <unordered_map> #include <helios.rendering.Viewport> #include <helios.rendering.RenderTarget> #include <helios.rendering.ViewportSnapshot> #include <helios.util.log.LogManager> #include <helios.util.log.Logger> #include <helios.math.types> #include <helios.window.WindowConfig> #include <helios.util.Guid>

Namespaces Index

namespacehelios
namespacewindow

Window management and configuration. More...

Classes Index

classWindow

Abstract base class representing a generic window. More...

Macro Definitions Index

#defineHELIOS_LOG_SCOPE   "helios::window::Window"

Description

Abstract window interface used by the helios framework.

Macro Definitions

HELIOS_LOG_SCOPE

#define HELIOS_LOG_SCOPE   "helios::window::Window"

Definition at line 23 of file Window.ixx.

23#define HELIOS_LOG_SCOPE "helios::window::Window"

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file Window.ixx
3 * @brief Abstract window interface used by the helios framework.
4 */
5module;
6
7#include <memory>
8#include <stdexcept>
9#include <string>
10#include <unordered_map>
11
12export module helios.window.Window;
13
14import helios.util.Guid;
15import helios.window.WindowConfig;
16import helios.math.types;
17import helios.util.log.Logger;
18import helios.util.log.LogManager;
19import helios.rendering.RenderTarget;
20import helios.rendering.ViewportSnapshot;
21import helios.rendering.Viewport;
22
23#define HELIOS_LOG_SCOPE "helios::window::Window"
24export namespace helios::window {
25
26 /**
27 * @brief Abstract base class representing a generic window.
28 *
29 * This class provides a common interface for window management
30 * without depending on the underlying native window implementation.
31 *
32 * A Window can be uniquely identified via its Guid.
33 */
34 class Window {
35
36 private:
37 /**
38 * @brief Unique identifier for this window instance.
39 */
40 util::Guid guid_;
41
42 protected:
43
44 /**
45 * @brief The logger used with this Window instance.
46 */
48
49 /**
50 * @brief The current width of the window.
51 */
52 int width_;
53
54 /**
55 * @brief The current height of the window.
56 */
57 int height_;
58
59 /**
60 * @brief The title of the window.
61 */
62 std::string title_;
63
64 /**
65 * @brief Aspect ratio numerator.
66 *
67 * Aspect ratio is enforced only when BOTH aspectRatioNumer and aspectRatioDenom are non-zero.
68 */
70
71 /**
72 * @brief Aspect ratio denominator.
73 *
74 * Aspect ratio is enforced only when BOTH aspectRatioNumer and aspectRatioDenom are non-zero.
75 */
77
78 /**
79 * @brief The default render target for this Window.
80 * The default RenderTarget represents the default framebuffer, e.g. the "0" FBO in OpenGL.
81 */
82 std::unique_ptr<helios::rendering::RenderTarget> renderTarget_;
83
84 public:
85 virtual ~Window() = default;
86
87 // not copyable
88 Window(const Window&) = delete;
89 Window& operator=(const Window&) = delete;
90
91 // moveable
92 Window(Window&&) noexcept = default;
93 Window& operator=(Window&&) noexcept = default;
94
95 /**
96 * @brief Constructs a new Window based on the provided configuration.
97 *
98 * Initializes basic properties such as width, height and the viewport
99 * of the window.
100 *
101 * @param renderTarget The RenderTarget for this window. Ownership is transferred.
102 * @param cfg A const ref to the window configuration used for this instance.
103 *
104 * @throws std::invalid_argument if renderTarget is a nullptr.
105 */
106 explicit Window(
107 std::unique_ptr<helios::rendering::RenderTarget> renderTarget,
108 const WindowConfig& cfg
109 ) :
110 renderTarget_(std::move(renderTarget)),
111 width_(cfg.width),
112 height_(cfg.height),
113 title_(cfg.title),
114 aspectRatioNumer_(cfg.aspectRatioNumer),
115 aspectRatioDenom_(cfg.aspectRatioDenom),
116 guid_(util::Guid::generate()) {
117
118 if (!renderTarget_) {
119 throw std::invalid_argument("Window received a nullptr renderTarget");
120 }
121 }
122
123
124 /**
125 * @brief Checks if the window has received a close request.
126 *
127 * Implementing APIs should consider this flag at regular intervals
128 * (e.g. each frame) to determine whether this window should be closed.
129 *
130 * @return true if the window should be closed, otherwise false.
131 *
132 * @see setShouldClose()
133 */
134 [[nodiscard]] virtual bool shouldClose() const = 0;
135
136
137 /**
138 * @brief Sets the close flag of this window.
139 *
140 * @param close True to indicate this window should be closed,
141 * false otherwise.
142 *
143 * @see shouldClose()
144 */
145 virtual void setShouldClose(bool close) = 0;
146
147
148 /**
149 * @brief Returns the unique guid for this window instance.
150 *
151 * @return A const reference to the Guid of this window.
152 */
153 [[nodiscard]] const util::Guid& guid() const noexcept {
154 return guid_;
155 }
156
157
158 /**
159 * @brief Shows the underlying native window.
160 *
161 * Derived classes must implement the platform-specific logic to
162 * show this window.
163 *
164 * @return true if showing the window succeeded, otherwise false.
165 */
166 virtual bool show() noexcept = 0;
167
168
169 /**
170 * @brief Instructs the rendering system to swap the front and back buffers.
171 *
172 * Makes the back buffer's content visible on the screen.
173 * Derived classes must implement the platform-specific buffer mechanism.
174 */
175 virtual void swapBuffers() const noexcept = 0;
176
177
178 /**
179 * @brief Poll this window for native window events.
180 *
181 * This method processes pending events from the native window system.
182 * Implementing APIs should call this method at regular intervals, e.g.
183 * once per frame.
184 */
185 virtual void pollEvents() const noexcept = 0;
186
187
188 /**
189 * @brief Returns the current width of this window.
190 *
191 * @return The current width of this window.
192 */
193 [[nodiscard]] int width() const noexcept {
194 return width_;
195 }
196
197
198 /**
199 * @brief Returns the current height of this window.
200 *
201 * @return The current height of this window.
202 */
203 [[nodiscard]] int height() const noexcept {
204 return height_;
205 }
206
207
208 /**
209 * @brief Returns the RenderTarget associated with this Window.
210 *
211 * @return A reference to the RenderTarget of this window.
212 */
213 [[nodiscard]] helios::rendering::RenderTarget& renderTarget() const noexcept {
214 return *renderTarget_;
215 }
216
217 /**
218 * @brief Adds the viewport to the underlying RenderTarget of this Window.
219 *
220 * @param viewport The Viewport instance to add to the RenderTarget owned by this Window.
221 *
222 * @return The Viewport added to the Window's RenderTarget as a shared pointer.
223 */
224 std::shared_ptr<helios::rendering::Viewport> addViewport(std::shared_ptr<helios::rendering::Viewport> viewport) const {
225 return renderTarget_->addViewport(std::move(viewport));
226 }
227
228 /**
229 * @brief Returns snapshots of all viewports with assigned IDs.
230 *
231 * Collects immutable ViewportSnapshot objects from all viewports
232 * that have a valid ViewportId. Useful for passing viewport state
233 * to systems that need frame-consistent viewport data.
234 *
235 * @return A vector of ViewportSnapshot objects.
236 */
237 [[nodiscard]] std::vector<helios::rendering::ViewportSnapshot> viewportSnapshots() {
238 std::vector<helios::rendering::ViewportSnapshot> snapshots;
239 for (auto& viewport : renderTarget_->viewports()) {
240 if (viewport->viewportId()) {
241 snapshots.push_back(viewport->snapshot());
242 }
243 }
244 return snapshots;
245 }
246
247 /**
248 * @brief Compares two window instances for equality.
249 *
250 * Two windows are considered equal if their GUIDs are equal.
251 *
252 * @param win The window to compare with this window.
253 * @return true if both windows are equal, otherwise false.
254 */
255 virtual bool operator==(const Window& win) const noexcept {
256 return guid_ == win.guid();
257 }
258 };
259
260} // namespace helios::window

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.