Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
window.h
1#ifndef OE_CORE_WINDOW_H
2#define OE_CORE_WINDOW_H
3
4#include "../common.h"
5#include <string>
6#include <memory>
7#include <glm/vec2.hpp>
8#include "event_handler.h"
9
10namespace oe
11{
12 struct Native;
13}
14
15namespace oe::core
16{
17 class Renderer;
18 class Cursor;
19
23 class Window
24 {
25 public:
32 Window(const std::string& title, bool is_visible = true);
33
41 Window(const glm::ivec2& dimensions, const std::string& title, bool is_visible = true);
42 ~Window();
43
48 void setTitle(const std::string& title);
49
54
59
64 void endRender();
65
70 void lockCursor();
71
72 void setCursorVisible(bool visible = true);
73
77 void setCursorPosition(const double& x, const double& y);
78
83 glm::vec2 getCursorPosition(const bool& absolute = false);
84
89
93 void show();
94
98 void hide();
99
104 void blink();
105
106 void makeContextCurrent();
107
108 //Cursor* getCursor() { return _cursor; }
109 //void setCursor(Cursor* cursor);
110
114 void setPosition(const glm::ivec2&);
115
119 void setDimensions(const glm::ivec2&);
120
124 const glm::ivec2 getPosition() const;
125
129 const glm::ivec2 getDimensions() const
130 {
131 return _dimensions;
132 }
133
137 float getAspectRatio() const noexcept
138 {
139 return 1.0f * _dimensions.x / _dimensions.y;
140 }
141
145 glm::ivec2 getBufferDimensions() {return _buffer_dimensions;}
146
150 void setShouldClose(bool can_close = true);
151
155 bool shouldClose() const;
156
161 {
162 return _event_handler;
163 }
164
169 {
170 return _event_handler;
171 }
172
177 const std::string getClipboardContent();
178
183 void setClipboardContent(const std::string& contents);
184
188 bool isHovered() const noexcept;
189
193 bool isFocused() const noexcept;
194
198 bool isAlwaysOnTop() const noexcept;
199
203 bool isDecorated() const noexcept;
204
210 bool isResizable() const noexcept;
211
215 bool isMousePasthrough() const noexcept;
216
221 void setAlwaysOnTop(const bool enable = true) noexcept;
222
227 void setDecorated(const bool enable = true) noexcept;
228
233 void setResizable(const bool enable = true) noexcept;
234
239 void setMousePasthrough(const bool enable = true) noexcept;
240
241 #ifdef OXYGEN_ENGINE_DEBUG_VALIDATE_ORDERED_OPERATIONS
242 bool is_between_begin_end = false;
243 #endif
244
245 private:
246 glm::ivec2 _dimensions;
247 glm::ivec2 _buffer_dimensions;
248
249 void* _handle = nullptr;
250 EventHandler _event_handler;
251 Cursor* _cursor = nullptr;
252
253 std::shared_ptr<Renderer> _renderer;
254
255 void _init_window();
256
257 friend Native;
258 };
259}
260
261#endif
Definition cursor.h:11
Event handler.
Definition event_handler.h:22
Definition window.h:24
void beginRender()
Begin rendering to the main framebuffer.
void setDimensions(const glm::ivec2 &)
Set window dimensions (excluding decorations)
void setCursorPosition(const double &x, const double &y)
Set cursor position relative to the window.
void setResizable(const bool enable=true) noexcept
Toggle to let the window being resizable by the user.
bool isResizable() const noexcept
Check if the window is resizable by the user.
void setDecorated(const bool enable=true) noexcept
Toggle the decorations (title bar and OS specific borders)
void setMousePasthrough(const bool enable=true) noexcept
Toggle to let the window being transparent to mouse input.
glm::ivec2 getBufferDimensions()
Get main framebuffer dimensions.
Definition window.h:145
glm::vec2 getCursorPosition(const bool &absolute=false)
Get cursor position relative to the window or screen.
void setPosition(const glm::ivec2 &)
Set window position (excluding decorations)
Window(const glm::ivec2 &dimensions, const std::string &title, bool is_visible=true)
Generate and open a new window.
const glm::ivec2 getPosition() const
Get window position (excluding decorations)
bool isMousePasthrough() const noexcept
Check if the window is transparent to mouse input, letting any mouse events pass through to whatever ...
void setClipboardContent(const std::string &contents)
Set the contents of the system clipboard to the UTF-8 string.
bool isHovered() const noexcept
Check if the cursor is currently directly over the content area of the window, with no other windows ...
float getAspectRatio() const noexcept
Get window aspect ratio.
Definition window.h:137
const glm::ivec2 getDimensions() const
Get window dimensions (excluding decorations)
Definition window.h:129
void moveToCenter()
Center the window.
void endRender()
End framebuffer rendering.
const std::string getClipboardContent()
Returns the contents of the system clipboard, if the content contains or is convertible to a UTF-8 en...
void setTitle(const std::string &title)
Set window title.
void hide()
Hide the window.
void setShouldClose(bool can_close=true)
Tell the window to close.
void show()
Display the window.
void lockCursor()
Hide cursor and lock it at window center.
bool isAlwaysOnTop() const noexcept
Check if the window is forced at foreground.
void setAlwaysOnTop(const bool enable=true) noexcept
Toggle if the window should be always on top.
bool isDecorated() const noexcept
Check if the window has decorations (title bar and OS specific borders)
void blink()
Make the window blink to get user attention.
bool shouldClose() const
Check if nothing prevented the window to close.
bool isFocused() const noexcept
Check if the window has input focus.
void processEvents()
Process window events.
EventHandler & getEventHandler()
Get a reference to the event handler bound to this window.
Definition window.h:160
Window(const std::string &title, bool is_visible=true)
Generate and open a fullscreen window.
const EventHandler & getEventHandler() const
Get a const reference to the event handler bound to this window.
Definition window.h:168
Core functionality (windows, event handler, logger, ...)
Definition cursor.h:8
Oxygen Engine common namespace.
Definition cursor.h:8
Class providing native access to underlying handles.
Definition native.h:20