aboutsummaryrefslogtreecommitdiff
path: root/src/window
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-19 22:22:07 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-19 22:22:07 +0200
commitfe1588ef18163c7557d3d0a62c085f42f2abfab2 (patch)
treed73f54a47ebfe6b2d289ed42c9a738a94e6095d1 /src/window
parent6a524b46cb9c74c8d1b710c23bbc62bdafd54bb2 (diff)
Change event layout to similar to same as sfml
Diffstat (limited to 'src/window')
-rw-r--r--src/window/Window.cpp41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/window/Window.cpp b/src/window/Window.cpp
index d4518eb..bc1f5ac 100644
--- a/src/window/Window.cpp
+++ b/src/window/Window.cpp
@@ -1,13 +1,13 @@
#include "../../include/mglpp/window/Window.hpp"
+#include "../../include/mglpp/window/Event.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();
- }
+extern "C" {
+#include <mgl/window/event.h>
+}
- Window::Window(Delegate *delegate) : delegate(delegate) {
+namespace mgl {
+ Window::Window() {
window.window = 0;
}
@@ -18,23 +18,22 @@ namespace mgl {
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;
+ return mgl_window_create_with_params(&window, title, width, height, 0) == 0;
}
- void Window::poll_events() {
+ bool Window::poll_event(Event &event) {
if(!window.window)
- return;
- mgl_window_events_poll(&window);
+ return false;
+
+ /* TODO: Convert c_event to |event| */
+ mgl_event c_event;
+ return mgl_window_poll_event(&window, &c_event);
}
- void Window::draw() {
+ void Window::clear(mgl::Color color) {
if(!window.window)
return;
- mgl_window_draw(&window);
+ mgl_window_clear(&window, mgl_color{color.r, color.g, color.b, color.a});
}
void Window::draw(Drawable &drawable) {
@@ -42,11 +41,13 @@ namespace mgl {
drawable.draw(*this);
}
- vec2i Window::get_cursor_position() const {
- return { window.cursor_position.x, window.cursor_position.y };
+ void Window::display() {
+ if(!window.window)
+ return;
+ mgl_window_display(&window);
}
- Window::Delegate* Window::get_delegate() {
- return delegate;
+ vec2i Window::get_cursor_position() const {
+ return { window.cursor_position.x, window.cursor_position.y };
}
} \ No newline at end of file