#ifndef MGL_WINDOW_H #define MGL_WINDOW_H #include "../graphics/color.h" #include "../system/vec.h" #include "../system/clock.h" #include "key.h" #include /* Vsync is automatically set for created windows, if supported by the system */ typedef struct mgl_event mgl_event; /* x11 window handle. TODO: Add others when wayland, etc is added */ typedef unsigned long mgl_window_handle; typedef struct mgl_window mgl_window; typedef struct { mgl_vec2i position; mgl_vec2i size; } mgl_view; struct mgl_window { mgl_window_handle window; void *context; mgl_vec2i size; /* relative to the top left of the window. only updates when the cursor is inside the window */ mgl_vec2i cursor_position; mgl_view view; bool open; bool focused; double frame_time_limit; mgl_clock frame_timer; }; int mgl_window_create(mgl_window *self, const char *title, int width, int height); /* if |parent_window| is 0 then the root window is used */ int mgl_window_create_with_params(mgl_window *self, const char *title, int width, int height, mgl_window_handle parent_window); int mgl_window_init_from_existing_window(mgl_window *self, mgl_window_handle existing_window); void mgl_window_deinit(mgl_window *self); void mgl_window_clear(mgl_window *self, mgl_color color); bool mgl_window_poll_event(mgl_window *self, mgl_event *event); void mgl_window_display(mgl_window *self); /* This should be called every frame to retain the view. Make sure to set the view back to the previous view after rendering items by saving the previous view with |mgl_window_get_view| and then call |mgl_window_set_view| with that saved view. */ void mgl_window_set_view(mgl_window *self, mgl_view *new_view); void mgl_window_get_view(mgl_window *self, mgl_view *view); bool mgl_window_is_open(const mgl_window *self); bool mgl_window_has_focus(const mgl_window *self); bool mgl_window_is_key_pressed(const mgl_window *self, mgl_key key); void mgl_window_close(mgl_window *self); void mgl_window_set_title(mgl_window *self, const char *title); void mgl_window_set_cursor_visible(mgl_window *self, bool visible); /* 0 = no fps limit */ void mgl_window_set_framerate_limit(mgl_window *self, int fps); #endif /* MGL_WINDOW_H */