aboutsummaryrefslogtreecommitdiff
path: root/src/window
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-18 01:54:59 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-18 01:54:59 +0200
commit3e081d1669622bbc276b038ddc38ecf0600683c3 (patch)
tree0a92c34f257c75a2b26e63b0ea9da3d594e89cc8 /src/window
Initial commit with an example
Diffstat (limited to 'src/window')
-rw-r--r--src/window/Window.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/window/Window.cpp b/src/window/Window.cpp
new file mode 100644
index 0000000..d4518eb
--- /dev/null
+++ b/src/window/Window.cpp
@@ -0,0 +1,52 @@
+#include "../../include/mglpp/window/Window.hpp"
+#include "../../include/mglpp/graphics/Drawable.hpp"
+
+namespace mgl {
+ static void draw_callback(mgl_window *window, void *userdata) {
+ Window *windowpp = (Window*)userdata;
+ windowpp->get_delegate()->draw();
+ }
+
+ Window::Window(Delegate *delegate) : delegate(delegate) {
+ window.window = 0;
+ }
+
+ Window::~Window() {
+ mgl_window_deinit(&window);
+ }
+
+ bool Window::create(const char *title, int width, int height) {
+ if(window.window)
+ return false;
+
+ mgl_window_callback callback;
+ callback.userdata = this;
+ callback.draw = draw_callback;
+ return mgl_window_create_with_params(&window, title, width, height, 0, &callback) == 0;
+ }
+
+ void Window::poll_events() {
+ if(!window.window)
+ return;
+ mgl_window_events_poll(&window);
+ }
+
+ void Window::draw() {
+ if(!window.window)
+ return;
+ mgl_window_draw(&window);
+ }
+
+ void Window::draw(Drawable &drawable) {
+ // TODO: Make the opengl context active for this thread and window, if it already isn't
+ drawable.draw(*this);
+ }
+
+ vec2i Window::get_cursor_position() const {
+ return { window.cursor_position.x, window.cursor_position.y };
+ }
+
+ Window::Delegate* Window::get_delegate() {
+ return delegate;
+ }
+} \ No newline at end of file