PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
Window.hpp
1#pragma once
2
3#include <glm/glm.hpp>
4#include <volk.h>
5
6#include <cstdint>
7#include <functional>
8#include <string>
9#include <utility>
10
11struct GLFWwindow;
12
13namespace PixelBullet
14{
15 class Event;
16 class VirtualPath;
17 struct ApplicationSpecification;
18
19 class Window final
20 {
21 public:
22 enum class WindowState
23 {
24 Normal,
25 Minimized,
26 Maximized
27 };
28
29 explicit Window(const ApplicationSpecification& props);
30 ~Window();
31
33 void OnUpdate() noexcept;
34
36 void SetIcon(const VirtualPath& iconPath);
37
39 unsigned int GetWidth() const noexcept
40 {
41 return m_Width;
42 }
43 unsigned int GetHeight() const noexcept
44 {
45 return m_Height;
46 }
47 glm::ivec2 GetSize() const noexcept
48 {
49 return { m_Width, m_Height };
50 }
51
53 void SetEventCallback(const std::function<void(Event&)>& callback)
54 {
55 m_EventCallback = callback;
56 }
57
59 void* GetNativeWindow() const noexcept
60 {
61 return m_Window;
62 }
63
65 std::pair<const char**, uint32_t> GetInstanceExtensions() const;
66
68 VkResult CreateSurface(VkInstance instance, const VkAllocationCallbacks* allocator,
69 VkSurfaceKHR* surface) const;
70
72 void Minimize() noexcept;
73
75 void Maximize() noexcept;
76
78 void Restore() noexcept;
79
81 bool IsMinimized() const noexcept;
82
84 bool IsMaximized() const noexcept;
85
87 WindowState GetWindowState() const noexcept;
88
89 private:
90 void Init(const ApplicationSpecification& props);
91 void Shutdown();
92
93 private:
94 GLFWwindow* m_Window = nullptr;
95 std::string m_Title;
96 unsigned int m_Width = 0, m_Height = 0;
97 std::function<void(Event&)> m_EventCallback;
98
99 bool m_Fullscreen = false;
100 glm::ivec2 m_Size{ 0, 0 };
101 glm::ivec2 m_FullscreenSize{ 0, 0 };
102 uint32_t m_ID = 0;
103
104 private:
105 static uint8_t s_GLFWWindowCount;
106 static uint32_t s_WindowIDCounter;
107 };
108} // namespace PixelBullet
Definition Event.hpp:65
Definition VirtualPath.hpp:11
Definition Window.hpp:20
void Maximize() noexcept
Maximizes the window.
Definition Window.cpp:280
void Restore() noexcept
Restores the window from a minimized or maximized state.
Definition Window.cpp:288
bool IsMaximized() const noexcept
Returns whether the window is currently maximized.
Definition Window.cpp:301
void Minimize() noexcept
Minimizes the window.
Definition Window.cpp:272
std::pair< const char **, uint32_t > GetInstanceExtensions() const
Retrieves the Vulkan instance extensions required by GLFW.
Definition Window.cpp:253
bool IsMinimized() const noexcept
Returns whether the window is currently minimized.
Definition Window.cpp:296
void SetEventCallback(const std::function< void(Event &)> &callback)
Sets the callback that will be invoked when events occur.
Definition Window.hpp:53
unsigned int GetWidth() const noexcept
Accessors for window size.
Definition Window.hpp:39
WindowState GetWindowState() const noexcept
Returns the current window state.
Definition Window.cpp:306
VkResult CreateSurface(VkInstance instance, const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface) const
Creates a Vulkan surface for this window.
Definition Window.cpp:266
void SetIcon(const VirtualPath &iconPath)
Sets the window icon from an image file.
Definition Window.cpp:228
void * GetNativeWindow() const noexcept
Returns the underlying native window pointer.
Definition Window.hpp:59
void OnUpdate() noexcept
Polls for and processes events.
Definition Window.cpp:223
Contains configuration options for both the game and the engine.
Definition Specification.hpp:108