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 <string>
5#include <memory>
6#include <glm/vec2.hpp>
7#include "event_handler.h"
8
9namespace oe
10{
11 struct Native;
12}
13
14namespace oe::core
15{
16 class Device;
17 class Renderer;
18 class Cursor;
19
23 class Window
24 {
25 public:
33 Window(const Device& device, const std::string& title, bool is_visible = true);
34
43 Window(const Device& device, const glm::ivec2& dimensions, const std::string& title, bool is_visible = true);
44 ~Window();
45
50 void setTitle(const std::string& title);
51
56
61
66 void endRender();
67
72 void lockCursor();
73
74 void setCursorVisible(bool visible = true);
75
79 void setCursorPosition(const double& x, const double& y);
80
85 glm::vec2 getCursorPosition(const bool& absolute = false);
86
91
95 void show();
96
100 void hide();
101
106 void blink();
107
108 void makeContextCurrent();
109
110 //Cursor* getCursor() { return _cursor; }
111 //void setCursor(Cursor* cursor);
112
116 void setPosition(const glm::ivec2&);
117
121 void setDimensions(const glm::ivec2&);
122
126 const glm::ivec2 getPosition() const;
127
131 const glm::ivec2 getDimensions() const
132 {
133 return _dimensions;
134 }
135
139 float getAspectRatio() const noexcept
140 {
141 return 1.0f * _dimensions.x / _dimensions.y;
142 }
143
147 glm::ivec2 getBufferDimensions() {return _buffer_dimensions;}
148
152 void setShouldClose(bool can_close = true);
153
157 bool shouldClose() const;
158
163 {
164 return _event_handler;
165 }
166
171 {
172 return _event_handler;
173 }
174
179 const std::string getClipboardContent();
180
185 void setClipboardContent(const std::string& contents);
186
190 bool isHovered() const noexcept;
191
195 bool isFocused() const noexcept;
196
200 bool isAlwaysOnTop() const noexcept;
201
205 bool isDecorated() const noexcept;
206
212 bool isResizable() const noexcept;
213
217 bool isMousePasthrough() const noexcept;
218
223 void setAlwaysOnTop(const bool enable = true) noexcept;
224
229 void setDecorated(const bool enable = true) noexcept;
230
235 void setResizable(const bool enable = true) noexcept;
236
241 void setMousePasthrough(const bool enable = true) noexcept;
242
243 #ifdef OXYGEN_ENGINE_DEBUG_VALIDATE_ORDERED_OPERATIONS
244 bool is_between_begin_end = false;
245 #endif
246
247 private:
248 glm::ivec2 _dimensions;
249 glm::ivec2 _buffer_dimensions;
250
251 void* _handle = nullptr;
252 EventHandler _event_handler;
253 Cursor* _cursor = nullptr;
254
255 std::shared_ptr<Renderer> _renderer;
256
257 void _init_window();
258
259 friend Native;
260 };
261}
262
263#endif
Definition cursor.h:11
The OxygenEngine device that will manage events, windows, scene, etc...
Definition device.h:17
Event handler.
Definition event_handler.h:18
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:147
glm::vec2 getCursorPosition(const bool &absolute=false)
Get cursor position relative to the window or screen.
Window(const Device &device, const std::string &title, bool is_visible=true)
Generate and open a fullscreen window.
void setPosition(const glm::ivec2 &)
Set window position (excluding decorations)
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:139
const glm::ivec2 getDimensions() const
Get window dimensions (excluding decorations)
Definition window.h:131
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.
Window(const Device &device, const glm::ivec2 &dimensions, const std::string &title, bool is_visible=true)
Generate and open a new window.
EventHandler & getEventHandler()
Get a reference to the event handler bound to this window.
Definition window.h:162
const EventHandler & getEventHandler() const
Get a const reference to the event handler bound to this window.
Definition window.h:170
Core functionality (windows, event handler, logger, ...)
Definition args.h:10
Oxygen Engine common namespace.
Definition debug.h:17
Class providing native access to underlying handles.
Definition native.h:20