blob: d4518eb351aac4901bc8a888c1134282b376dbc8 (
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
|
#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;
}
}
|