Enigma  3.2.0
A Simple, Reliable and Efficient Encryption Tool
Window.hpp
Go to the documentation of this file.
1 #pragma once
2 #ifndef ENIGMA_WINDOW_H
3 #define ENIGMA_WINDOW_H
4 
5 #include <glad/glad.h> // Warning! MUST ALWAYS BE INCLUDED BEFORE glfw3
6 #include <GLFW/glfw3.h>
7 #include <stb_image.h>
8 
9 #include <Core/Core.hpp>
10 #include <Events/Event.hpp>
11 #include <Window/Cursor/Cursor.hpp>
12 
13 #include <exception>
14 #include <string>
15 #include <utility>
16 
17 #include "WindowSettings.hpp"
18 
19 
21 class RAMInfo;
22 class CPUInfo;
23 /*
24 * OpenGL Based Window
25 */
26 class Window {
27  using EventCallback = std::function<void(Event&)>;
28 
29  public:
30  Window(const WindowSettings& window_settings = WindowSettings());
31  virtual ~Window();
32 
33  private:
34  /*
35  * Polls GLFW Events
36  */
37  void PollEvents() const noexcept;
38 
39  /*
40  * Swaps GLFW Buffets
41  */
42  void SwapBuffers() const noexcept;
43 
44  /*
45  * Destroys GLFW Window and Terminates
46  */
47  void Destroy() noexcept;
48 
49  public: /* Accessors */
50  /*
51  * Returns size (width, height) of this window
52  */
53  [[nodiscard]] const std::pair<std::int32_t, std::int32_t>& GetSize() const noexcept;
54 
55  /*
56  * Returns the width of this window
57  */
58  std::int32_t GetWidth() const noexcept;
59 
60  /*
61  * Returns the height of this window
62  */
63  std::int32_t GetHeight() const noexcept;
64 
65  /*
66  * Returns frame buffer size of this window
67  */
68  [[nodiscard]] const std::pair<std::int32_t, std::int32_t>& GetFrameBufferSize() noexcept;
69 
70  /*
71  * Returns frame buffer width of this window
72  */
73  std::int32_t GetFrameBufferWidth() noexcept;
74 
75  /*
76  * Returns frame buffer height of this window
77  */
78  std::int32_t GetFrameBufferHeight() noexcept;
79 
80  /*
81  * Returns the aspect ratio ( width / height ) of this window
82  * Returns 1.0f if height is 0 (to avoid division by zero error)
83  */
84  float GetAspectRatio() const noexcept;
85 
86  /*
87  * Returns const pointer of GLFW window
88  */
89  const GLFWwindow *GetGLFWwindow() const noexcept;
90 
91  /*
92  * Returns pointer of GLFW window
93  */
94  GLFWwindow *GetGLFWwindow() noexcept;
95 
96  /*
97  * Returns the title of this window
98  */
99  [[nodiscard]] const std::string& GetTitle() const noexcept;
100 
101  /*
102  * Returns minimum width, height of this window
103  */
104  [[nodiscard]] const std::pair<std::int32_t, std::int32_t>& GetMinimumSize() const noexcept;
105 
106  /*
107  * Returns maximum width, height of this window
108  */
109  [[nodiscard]] const std::pair<std::int32_t, std::int32_t>& GetMaximumSize() const noexcept;
110 
111  /*
112  * Returns window top left position
113  */
114  [[nodiscard]] const std::pair<std::int32_t, std::int32_t>& GetPosition() const noexcept;
115 
116  /*
117  * Returns vsync swap interval level
118  * Interval 0: unlimited FPS
119  * Interval 1: 60 FPS
120  * Interval 2: 30 FPS
121  */
122  std::int32_t GetSwapInterval() const noexcept;
123 
124  /*
125  * Returns true if the window should be closed
126  */
127  bool ShouldClose() const noexcept;
128 
129  /*
130  * Return true if the window is hidden
131  */
132  bool IsHidden() const noexcept;
133 
134  /*
135  * Return true if the window is visible
136  */
137  bool IsVisible() const noexcept;
138 
142  bool IsMaximized() const noexcept;
143 
144  /*
145  * Return true if the windows is minimized
146  */
147  bool IsMinimized() const noexcept;
148 
149  /*
150  * Return true if the windows is focused
151  */
152  bool IsFocused() const noexcept;
153 
154  /*
155  * Return true if the windows is resizable
156  */
157  bool IsResizable() const noexcept;
158 
159  /*
160  * Return true if the windows is decorated
161  */
162  bool IsDecorated() const noexcept;
163 
164  /*
165  * Returns true if the window is fullscreen mode
166  */
167  bool IsFullscreen() const noexcept;
168 
169  /*
170  * Returns refresh rate of this window
171  */
172  std::int32_t GetRefreshRate() noexcept;
173 
174  /*
175  * Returns size (width, height) of the primary monitor
176  */
177  std::pair<std::int32_t, std::int32_t> GetMonitorSize() noexcept;
178 
179  public: /* Modifiers */
180  /*
181  * Sets event callback function
182  */
183  void SetEventCallback(const EventCallback& callback) noexcept;
184 
185  /*
186  * Set window minimum width, height
187  */
188  void SetMinimumSize(const std::int32_t minimum_width, const std::int32_t minimum_height) noexcept;
189 
190  /*
191  * Set window maximum width, height
192  */
193  void SetMaximumSize(const std::int32_t maximum_width, const std::int32_t maximum_height) noexcept;
194 
195  /*
196  * Close Window
197  */
198  void SetShouldClose(const bool close) const noexcept;
199 
200  /*
201  * Sets Vertical Sync swap interval
202  * Interval 0: unlimited FPS
203  * Interval 1: 60 FPS
204  * Interval 2: 30 FPS
205  */
206  void SetSwapInterval(const std::int32_t interval) noexcept;
207 
208  /*
209  * Set Window Title
210  */
211  //void SetTitle(const std::string& title) noexcept;
212  void SetTitle(const std::string& title, const std::unique_ptr<std::uint32_t>& fps, const std::unique_ptr<RAMInfo>& ram_info, const std::unique_ptr<CPUInfo>& cpu_info) noexcept;
213 
214  /*
215  * Set window top left position
216  */
217  void SetPosition(const std::int32_t x, const std::int32_t y) const noexcept;
218 
219  /*
220  * Set Window runtime icon
221  */
222  void SetIcon(const std::string& icon_path) noexcept;
223  void SetIcon(const byte* iconData, std::size_t iconDataSize) noexcept;
224 
225  /*
226  * Set Window cursor mode
227  */
228  void SetCursor(CursorMode mode) noexcept;
229 
230  /*
231  * Set Window cursor image
232  */
233  void SetCursor(const std::string& image_path, const std::int32_t xhot, const std::int32_t yhot) noexcept;
234 
235  /*
236  * Disable Window Cursor
237  */
238  void DisableCursor() const noexcept;
239 
240  /*
241  * Enable Window Cursor
242  */
243  void EnableCursor() const noexcept;
244 
245  /*
246  * Hide Window Cursor
247  */
248  void HideCursor() const noexcept;
249 
250  /*
251  * Sets cursor position at given point
252  */
253  void SetCursorPosition(const double xPos, const double yPos) const noexcept;
254 
255  /*
256  * Minimize Window
257  */
258  void Minimize() const noexcept;
259 
260  /*
261  * Maximize Window
262  */
263  void Maximize() const noexcept;
264 
265  /*
266  * Restore Window
267  */
268  void Restore() const noexcept;
269 
270  /*
271  * Hide Window
272  */
273  void Hide() const noexcept;
274 
275  /*
276  * Show Window
277  */
278  void Show() const noexcept;
279 
280  /*
281  * Focus Window
282  */
283  void Focus() const noexcept;
284 
285  /*
286  * Enable / Disable Fullscreen mode
287  */
288  void SetFullscreen(bool full_screen) noexcept;
289 
290  /*
291  * Set window refresh rate
292  */
293  void SetRefreshRate(const std::int32_t refresh_rate) noexcept;
294 
295  private: /* Initializer Functions */
296  bool InitGLFW(const WindowSettings& window_settings);
297  bool InitGLFWCallbacks();
298  bool InitGLAD();
299  bool InitOpenGLOptions();
300 
301 
302  private: /* Events */
303  EventCallback m_event_callback{};
304 
305 
306  private: /* Properties */
307  // Window properties
308  std::string m_title{};
309  std::pair<std::int32_t, std::int32_t> m_position{};
310  std::pair<std::int32_t, std::int32_t> m_size{};
311  std::pair<std::int32_t, std::int32_t> m_minimum_size{};
312  std::pair<std::int32_t, std::int32_t> m_maximum_size{};
313  std::pair<std::int32_t, std::int32_t> m_frame_buffer_size{};
314  std::int32_t m_swap_interval{};
315 
316  // Monitor & Video Mode
317  GLFWwindow *m_GLFWwindow{};
318  GLFWmonitor *m_monitor{};
319  const GLFWvidmode *m_video_mode{};
320 
321  // Window Cursor
322  std::unique_ptr<Cursor> m_cursor{};
323 
324  public: /* Good Friends :) */
325  friend class Application;
326 };
327 
329 
330 
331 #endif // !ENIGMA_WINDOW_H
CursorMode
Definition: Cursor.hpp:11
#define NS_ENIGMA_BEGIN
Enable/Disable Assertions.
Definition: Macros.hpp:13
#define NS_ENIGMA_END
Definition: Macros.hpp:14
Definition: Event.hpp:66
void SetTitle(const std::string &title, const std::unique_ptr< std::uint32_t > &fps, const std::unique_ptr< RAMInfo > &ram_info, const std::unique_ptr< CPUInfo > &cpu_info) noexcept
std::int32_t GetHeight() const noexcept
bool IsMinimized() const noexcept
void SetCursorPosition(const double xPos, const double yPos) const noexcept
void SetShouldClose(const bool close) const noexcept
const std::pair< std::int32_t, std::int32_t > & GetPosition() const noexcept
bool IsResizable() const noexcept
void Maximize() const noexcept
void Hide() const noexcept
void SetSwapInterval(const std::int32_t interval) noexcept
const std::string & GetTitle() const noexcept
void SetCursor(CursorMode mode) noexcept
float GetAspectRatio() const noexcept
bool IsFocused() const noexcept
bool ShouldClose() const noexcept
void Show() const noexcept
void SetMaximumSize(const std::int32_t maximum_width, const std::int32_t maximum_height) noexcept
bool IsFullscreen() const noexcept
virtual ~Window()
const std::pair< std::int32_t, std::int32_t > & GetMaximumSize() const noexcept
std::int32_t GetSwapInterval() const noexcept
const std::pair< std::int32_t, std::int32_t > & GetSize() const noexcept
const std::pair< std::int32_t, std::int32_t > & GetFrameBufferSize() noexcept
void SetRefreshRate(const std::int32_t refresh_rate) noexcept
const std::pair< std::int32_t, std::int32_t > & GetMinimumSize() const noexcept
std::pair< std::int32_t, std::int32_t > GetMonitorSize() noexcept
std::int32_t GetWidth() const noexcept
std::int32_t GetFrameBufferWidth() noexcept
void Minimize() const noexcept
bool IsHidden() const noexcept
void SetMinimumSize(const std::int32_t minimum_width, const std::int32_t minimum_height) noexcept
std::int32_t GetRefreshRate() noexcept
const GLFWwindow * GetGLFWwindow() const noexcept
void SetFullscreen(bool full_screen) noexcept
Window(const WindowSettings &window_settings=WindowSettings())
void DisableCursor() const noexcept
void SetEventCallback(const EventCallback &callback) noexcept
void EnableCursor() const noexcept
void Focus() const noexcept
std::int32_t GetFrameBufferHeight() noexcept
void HideCursor() const noexcept
void Restore() const noexcept
void SetPosition(const std::int32_t x, const std::int32_t y) const noexcept
bool IsVisible() const noexcept
bool IsDecorated() const noexcept
void SetIcon(const std::string &icon_path) noexcept
bool IsMaximized() const noexcept