CoriEngine
Loading...
Searching...
No Matches
Window.hpp
Go to the documentation of this file.
1#pragma once
5
6namespace Cori {
7 namespace Graphics {
8 namespace Internal {
9 class OpenGLContext;
10 }
11 }
12 namespace Core {
13 namespace Internal {
14 class ImGuiLayer;
15 }
16 struct ScreenMode {
17 int32_t m_Width{};
18 int32_t m_Height{};
20 std::string m_ModeName;
21
22 protected:
23 friend class Window;
24 ScreenMode() = default;
25
26 ScreenMode(const int32_t width, const int32_t height, const float refreshRate, const uint32_t modeIndex)
27 : m_Width(width), m_Height(height), m_RefreshRate(refreshRate), m_SDLModeIndex(modeIndex) {
28 m_ModeName = std::to_string(m_Width) + "x" + std::to_string(m_Height) + " " + std::to_string(m_RefreshRate) + " Hz";
29 }
30
31 uint32_t m_SDLModeIndex{ 1000 }; //impossible initial number
32 };
33
39
43 class Window : public Profiling::Trackable<Window> {
44 public:
45 ~Window();
46
51 [[nodiscard]] int32_t GetWidth() const;
52
57 [[nodiscard]] int32_t GetHeight() const;
58
63 [[nodiscard]] static Graphics::GraphicsAPIs GetCurrentAPI() { return s_API; } // NOLINT
64
69 void SetVSync(const bool status);
70
75 [[nodiscard]] bool IsVSync() const;
76
81 [[nodiscard]] const std::vector<ScreenMode>& GetScreenModes() const;
82
88 std::expected<void, CoriError<>> SetScreenMode(const uint32_t modeIndex);
89
94 [[nodiscard]] WindowMode GetWindowMode() const;
95
100 [[nodiscard]] uint32_t GetCurrentScreenMode() const;
101
107 std::expected<void, CoriError<>> SetWindowMode(WindowMode mode);
108
109 private:
112 [[nodiscard]] void* GetNativeContext() const;
113 [[nodiscard]] void* GetNativeWindow() const;
114
115 struct WindowSaveData {
116 int32_t m_Width{};
117 int32_t m_Height{};
118 float m_RefreshRate{};
119 WindowMode m_WindowMode{};
120 uint32_t m_SDLModeIndex{};
121 uint32_t m_ModeIndex{};
122 };
123
124 friend class Application;
125 [[nodiscard]] static std::unique_ptr<Window> Create(std::string name, const bool vsync = false);
126 void OnUpdate();
127 void SetEventCallback(const EventCallbackFn& callback);
128
129 explicit Window(std::string title, const bool vsync = false);
130
131 inline static auto s_API = Graphics::GraphicsAPIs::OpenGL;
132 struct Data;
133 Data* m_Data{nullptr};
134 };
135 }
136}
int32_t GetHeight() const
Give the current window height.
Definition Window.cpp:232
friend class Application
Definition Window.hpp:124
std::expected< void, CoriError<> > SetScreenMode(const uint32_t modeIndex)
Changes the current ScreenMode.
Definition Window.cpp:274
const std::vector< ScreenMode > & GetScreenModes() const
Retrieves a list of all available ScreenMode.
Definition Window.cpp:270
uint32_t GetCurrentScreenMode() const
Retrieves the current screen mode index.
Definition Window.cpp:283
static Graphics::GraphicsAPIs GetCurrentAPI()
Returns the graphical API used by this window.
Definition Window.hpp:63
int32_t GetWidth() const
Give the current window width.
Definition Window.cpp:225
WindowMode GetWindowMode() const
Gets the current WindowMode;.
Definition Window.cpp:279
void SetVSync(const bool status)
Changes the VSync state.
Definition Window.cpp:245
bool IsVSync() const
Checks is VSynch is currently enabled.
Definition Window.cpp:257
std::expected< void, CoriError<> > SetWindowMode(WindowMode mode)
Changes the current WindowMode.
Definition Window.cpp:288
For InstanceMetrics to work with a type it should derive from this.
Definition Trackable.hpp:29
Core systems of the engine are here.
std::function< void(Event &)> EventCallbackFn
Definition Event.hpp:112
Almost everything connected to graphics is in this namespace.
Definition Window.hpp:7
@ OpenGL
The only one available for now.
Global engine namespace.
friend class Window
Definition Window.hpp:23
uint32_t m_SDLModeIndex
Definition Window.hpp:31
std::string m_ModeName
Definition Window.hpp:20
ScreenMode(const int32_t width, const int32_t height, const float refreshRate, const uint32_t modeIndex)
Definition Window.hpp:26