aboutsummaryrefslogtreecommitdiff
path: root/src/window/Window.cpp
blob: bc1f5ac47422a59249892562bc433286b5af91a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "../../include/mglpp/window/Window.hpp"
#include "../../include/mglpp/window/Event.hpp"
#include "../../include/mglpp/graphics/Drawable.hpp"

extern "C" {
#include <mgl/window/event.h>
}

namespace mgl {
    Window::Window() {
        window.window = 0;
    }

    Window::~Window() {
        mgl_window_deinit(&window);
    }

    bool Window::create(const char *title, int width, int height) {
        if(window.window)
            return false;
        return mgl_window_create_with_params(&window, title, width, height, 0) == 0;
    }

    bool Window::poll_event(Event &event) {
        if(!window.window)
            return false;

        /* TODO: Convert c_event to |event| */
        mgl_event c_event;
        return mgl_window_poll_event(&window, &c_event);
    }

    void Window::clear(mgl::Color color) {
        if(!window.window)
            return;
        mgl_window_clear(&window, mgl_color{color.r, color.g, color.b, color.a});
    }

    void Window::draw(Drawable &drawable) {
        // TODO: Make the opengl context active for this thread and window, if it already isn't
        drawable.draw(*this);
    }

    void Window::display() {
        if(!window.window)
            return;
        mgl_window_display(&window);
    }

    vec2i Window::get_cursor_position() const {
        return { window.cursor_position.x, window.cursor_position.y };
    }
}