#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; } }