AireEngine
A 3D Open-World Game Engine
Loading...
Searching...
No Matches
window.h
1#pragma once
2#include <glad/glad.h>
3#include <GLFW/glfw3.h>
4#include "../io-management/ioHandler.h"
5
6namespace Aire {
7
13 class Window {
14 public:
25 Window(int width, int height, const char* title, bool fullscreen = false);
26
27 // Delete copy constructor and assignment operator
28 Window(const Window&) = delete;
29 Window& operator=(const Window&) = delete;
30
32 GLFWwindow* getInternalPtr();
33
35 const char* getTitle() const;
36
38 IOHandler* getIOHandler() const;
39
41 int getWidth() const;
42
44 int getHeight() const;
45
50 void getFramebufferSize(int& width, int& height) const;
51
54 float getAspectRatio() const;
55
57 bool isFullscreen() const;
58
60 bool isMinimized() const;
61
63 bool shouldClose() const;
64
67 bool toggleFullscreen();
68
72 void attachIOHandler(IOHandler& handler);
73
77
79 void update();
80
82 void close();
83
85 ~Window();
86
87 private:
88 GLFWwindow* window;
89 const char* title;
90 IOHandler* ioHandler;
91
92 // Store the size and position of the window before entering
93 // fullscreen mode so they can be properly restored afterwards.
94 // DO NOT read these values for other purposes because
95 // they are not kept in sync with the current window size
96 // and position.
97 int prevWidth;
98 int prevHeight;
99 int prevXPos;
100 int prevYPos;
101
102 bool fullscreen;//< true if in fullscreen mode and false otherwise
103
104 static int numWindows;//< support for multiple windows
105 };
106
107 //##########################################//
108 //######## INLINE DEFINITIONS BELOW ########//
109 //##########################################//
110
111 inline GLFWwindow* Window::getInternalPtr() {
112 return window;
113 }
114
115 inline const char* Window::getTitle() const {
116 return title;
117 }
118
120 return ioHandler;
121 }
122
123 inline int Window::getWidth() const {
124 int width = 0;
125 glfwGetWindowSize(window, &width, nullptr);
126 return width;
127 }
128
129 inline int Window::getHeight() const {
130 int height = 0;
131 glfwGetWindowSize(window, nullptr, &height);
132 return height;
133 }
134
135 inline void Window::getFramebufferSize(int& width, int& height) const {
136 glfwGetFramebufferSize(window, &width, &height);
137 }
138
139 inline float Window::getAspectRatio() const {
140 int width = 0;
141 int height = 0;
142 getFramebufferSize(width, height);
143 return float(width) / float(height);
144 }
145
146 inline bool Window::isFullscreen() const {
147 return fullscreen;
148 }
149
150 inline bool Window::isMinimized() const {
151 return glfwGetWindowAttrib(window, GLFW_ICONIFIED);
152 }
153
154 inline bool Window::shouldClose() const {
155 return glfwWindowShouldClose(window);
156 }
157
159 glfwMakeContextCurrent(window);
160 }
161
162 inline void Window::close() {
163 glfwSetWindowShouldClose(window, GLFW_TRUE);
164 }
165}
166
167
168
A class that handles I/O events.
Definition ioHandler.h:7
Definition window.h:13
int getWidth() const
Definition window.h:123
bool isFullscreen() const
Definition window.h:146
bool shouldClose() const
Definition window.h:154
~Window()
Destroy the window. If this is the last window, terminate GLFW.
Definition window.cpp:185
GLFWwindow * getInternalPtr()
Definition window.h:111
bool toggleFullscreen()
Definition window.cpp:148
bool isMinimized() const
Definition window.h:150
Window(int width, int height, const char *title, bool fullscreen=false)
Definition window.cpp:42
IOHandler * getIOHandler() const
Definition window.h:119
void update()
Perform buffer swap and poll for I/O events.
Definition window.cpp:174
float getAspectRatio() const
Definition window.h:139
void setAsCurrentRenderWindow()
Definition window.h:158
void getFramebufferSize(int &width, int &height) const
Definition window.h:135
void close()
Close the window.
Definition window.h:162
void attachIOHandler(IOHandler &handler)
Definition window.cpp:167
const char * getTitle() const
Definition window.h:115
int getHeight() const
Definition window.h:129