QuasarEngine
Cross-platform 3D engine and editor
Loading...
Searching...
No Matches
Window.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <quasar/core/Base.h>
10#include <quasar/events/Event.h>
11
12#include <cstdint>
13#include <functional>
14#include <string>
15
16struct GLFWwindow;
17
18namespace Quasar
19{
20 class OpenGLContext;
21
26 {
27 std::string Title = "QuasarEngine";
28 std::uint32_t Width = 1280;
29 std::uint32_t Height = 720;
30 bool VSync = true;
31
34 bool GraphicsContext = true;
35 };
36
41 class Window
42 {
43 public:
45 using EventCallback = std::function<void(Event&)>;
46 ~Window();
47
48 Window(const Window&) = delete;
49 Window& operator=(const Window&) = delete;
50 Window(Window&&) = delete;
51 Window& operator=(Window&&) = delete;
52
56 [[nodiscard]] static Scope<Window> Create(const WindowSpecification& specification);
57
61 void Update();
62
65
67 bool ShouldClose() const;
68
70 void Close();
71
75 void SetVSync(bool enabled);
76
78 bool IsVSync() const;
79
81 std::uint32_t GetWidth() const;
82
84 std::uint32_t GetHeight() const;
85
87 const std::string& GetTitle() const;
88
90 GLFWwindow* GetNativeWindow() const;
91
94 std::string GetKeyName(Key key) const;
95
96 private:
97 Window(GLFWwindow* handle, const WindowSpecification& specification);
98
99 void SetGlfwCallbacks();
100 void SendEvent(Event& event);
101
102 GLFWwindow* m_Handle = nullptr;
103 Scope<OpenGLContext> m_Context;
104 std::string m_Title;
105 bool m_VSync = false;
106 EventCallback m_EventCallback;
107 };
108}
Contains the base definitions and utilities for the Quasar engine.
Base class of all events, with their types and categories.
Codes of the keyboard keys, independent from GLFW.
Base class of all events.
Definition Event.h:95
const std::string & GetTitle() const
Returns the title of the window.
GLFWwindow * GetNativeWindow() const
Returns the GLFW window, for the code that needs to call GLFW directly.
void Close()
Asks the window to close. ShouldClose() then returns true.
void SetEventCallback(EventCallback callback)
Sets the function that receives every event of the window.
bool ShouldClose() const
Returns true when the window was asked to close, by the user or by Close().
void Update()
Shows the rendered image and processes the messages of the operating system.
static Scope< Window > Create(const WindowSpecification &specification)
Creates a window and shows it.
std::string GetKeyName(Key key) const
Returns the name of a key in the current keyboard layout, for example "z" for Key::W on AZERTY.
bool IsVSync() const
Returns true if vertical synchronization is enabled.
std::uint32_t GetHeight() const
Returns the height of the drawing area, in pixels.
void SetVSync(bool enabled)
Enables or disables vertical synchronization.
std::uint32_t GetWidth() const
Returns the width of the drawing area, in pixels.
std::function< void(Event &)> EventCallback
Function that receives the events of the window.
Definition Window.h:45
Contains all the engine code.
std::unique_ptr< T > Scope
Pointer with a single owner. Alias of std::unique_ptr.
Definition Base.h:23
Key
Physical key of the keyboard.
Definition KeyCodes.h:22
Settings used to create a window.
Definition Window.h:26
std::uint32_t Height
Height of the window when it is created.
Definition Window.h:29
bool GraphicsContext
Whether the window gets an OpenGL 4.5 core context.
Definition Window.h:34
std::string Title
Title of the window.
Definition Window.h:27
bool VSync
Whether vertical synchronization is enabled when it is created.
Definition Window.h:30
std::uint32_t Width
Width of the window when it is created.
Definition Window.h:28