diff options
Diffstat (limited to 'src/window')
-rw-r--r-- | src/window/Window.cpp | 52 |
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 |