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 canRun() 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
185 private:
186 glm::ivec2 _dimensions;
187 glm::ivec2 _buffer_dimensions;
188
189 void* _handle = nullptr;
190 EventHandler _event_handler;
191 Cursor* _cursor = nullptr;
192
193 std::shared_ptr<Renderer> _renderer;
194
195 void _init_window();
196
197 friend Native;
198 };
199}
200
201#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.
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)
bool canRun() const
Check if nothing prevented the window to close.
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)
void setClipboardContent(const std::string &contents)
Set the contents of the system clipboard to the UTF-8 string.
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.
void blink()
Make the window blink to get user attention.
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