NcEngine
Window.h
Go to the documentation of this file.
1
5#pragma once
6
8#include "ncengine/type/EngineId.h"
10#include "ncengine/window/IOnResizeReceiver.h"
12
13#include "ncmath/Vector.h"
14
15struct GLFWwindow;
16
17namespace nc
18{
19namespace config
20{
21struct ProjectSettings;
22struct GraphicsSettings;
23} // namespace config
24
25namespace window
26{
29
32
35
37auto ToNormalizedDeviceCoordinates(const Vector2& screenCoordinates) -> Vector2;
38
44
50
55{
57 bool isHeadless = false;
58 bool useNativeResolution = false;
59 bool launchInFullScreen = false;
60 bool isResizable = false;
61};
62
66class NcWindow : public Module
67{
68 public:
69 explicit NcWindow() noexcept
70 : Module{NcWindowId} {}
71
72 // @brief Override OnBeforeSceneLoad to refresh the viewport
73 void OnBeforeSceneLoad(const Scene&) override { SetViewport(Viewport{}); };
74
76 auto GetDimensions() const noexcept -> const Vector2& { return m_dimensions; }
77
79 auto GetScreenExtent() const noexcept -> const Vector2& { return m_screenExtent; }
80
82 auto GetContentScale() const noexcept -> const Vector2& { return m_contentScale; }
83
85 auto GetWindowHandle() const noexcept -> GLFWwindow* { return m_window; }
86
88 auto OnResize() noexcept -> Signal<const Vector2&, bool>& { return m_onResize; }
89
91 auto OnViewportResize() noexcept -> Signal<const Viewport&>& {return m_onViewportResize; }
92
94 virtual void SetWindow(WindowInfo windowInfo) = 0;
95
99 virtual void SetViewport(const Viewport& viewport) = 0;
100
105 virtual void ProcessSystemMessages() = 0;
106
107 protected:
108 Vector2 m_dimensions;
109 Vector2 m_screenExtent;
110 Viewport m_viewport;
111 Vector2 m_contentScale;
112 GLFWwindow* m_window;
114 Signal<const Viewport&> m_onViewportResize;
115};
116
118auto BuildWindowModule(const config::ProjectSettings& projectSettings,
119 bool isGraphicsEnabled,
120 Signal<>& quit) -> std::unique_ptr<NcWindow>;
121} // namespace window
122} // namespace nc
auto GetDimensions() -> Vector2
Get the window dimensions.
auto ToNormalizedDeviceCoordinates(const Vector2 &screenCoordinates) -> Vector2
Convert screen space coordinates to normalized device coordinates (in the range [-1,...
void UnregisterOnResizeReceiver(IOnResizeReceiver *receiver) noexcept
Unregister an object from receiving window resize events.
auto BuildWindowModule(const config::ProjectSettings &projectSettings, bool isGraphicsEnabled, Signal<> &quit) -> std::unique_ptr< NcWindow >
Build an NcWindow module instance.
auto GetScreenExtent() -> Vector2
Get the dimensions of the screen after aspect ratio transformations.
auto GetContentScale() -> Vector2
Get the current DPI.
void RegisterOnResizeReceiver(IOnResizeReceiver *receiver)
Allow an object to receive window resize events. Receivers must be unregistered before they are destr...
Modules are extensions that provide functionality to the engine.
Definition: Module.h:19
Definition: Scene.h:20
An event source supporting multiple Connections.
Definition: Signal.h:65
Definition: IOnResizeReceiver.h:8
Window module interface.
Definition: Window.h:67
virtual void ProcessSystemMessages()=0
Process window and input events.
auto OnResize() noexcept -> Signal< const Vector2 &, bool > &
Get the Signal for window resize events.
Definition: Window.h:88
auto OnViewportResize() noexcept -> Signal< const Viewport & > &
Get the Signal for viewport resize events.
Definition: Window.h:91
virtual void SetWindow(WindowInfo windowInfo)=0
Set the window for the module.
virtual void SetViewport(const Viewport &viewport)=0
Set the dimensions and position of the renderable window. Values must be between [0....
void OnBeforeSceneLoad(const Scene &) override
Called on registered modules prior to loading a new scene.
Definition: Window.h:73
auto GetContentScale() const noexcept -> const Vector2 &
Get the ratio between the current DPI and the platform's default DPI.
Definition: Window.h:82
auto GetWindowHandle() const noexcept -> GLFWwindow *
Get the GLFW window handle.
Definition: Window.h:85
auto GetScreenExtent() const noexcept -> const Vector2 &
Get the dimensions of the renderable window region.
Definition: Window.h:79
auto GetDimensions() const noexcept -> const Vector2 &
Get the dimensions of the entire window.
Definition: Window.h:76
A two component vector.
Definition: Vector.h:13
A struct that controls the viewport and scissor size and placement.
Definition: WindowTypes.h:16
General project options.
Definition: Config.h:14
The window's create info.
Definition: Window.h:55
bool isResizable
True if the window is resizable.
Definition: Window.h:60
bool launchInFullScreen
True if the window should launch in full screen.
Definition: Window.h:59
bool isHeadless
True if this is a headless window. Still receives input events.
Definition: Window.h:57
bool useNativeResolution
True if the window should use the monitor's native resolution.
Definition: Window.h:58
Vector2 dimensions
The window's dimensions.
Definition: Window.h:56