#pragma once #include "event.h" #include "log.h" #include #include #include namespace Donut { class Window { public: using EventCallbackFn = std::function; Window(const std::string& title, int width, int height); ~Window(); bool should_close() const; void on_update() const; void set_event_callback(const EventCallbackFn& callback) { m_event_handler.set_event_callback(callback); } EventHandler& get_event_handler() { return m_event_handler; } unsigned int get_width() const { return m_width; } unsigned int get_height() const { return m_height; } void* get_native_window() const { return m_window; } void set_cursor_locked(bool locked); void set_cursor_visible(bool visible); bool is_cursor_locked() const { return m_cursor_locked; } bool is_cursor_visible() const { return m_cursor_visible; } void init_im_gui(); void begin_im_gui_frame(); void end_im_gui_frame(); private: void init(); void shutdown(); void setup_im_gui_fonts(); void apply_im_gui_theme(); void shutdown_im_gui(); static void glfw_error_callback(int error, const char* description); static void glfw_window_close_callback(GLFWwindow* window); static void glfw_window_size_callback(GLFWwindow* window, int width, int height); static void glfw_window_focus_callback(GLFWwindow* window, int focused); static void glfw_window_pos_callback(GLFWwindow* window, int xpos, int ypos); static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); static void glfw_char_callback(GLFWwindow* window, unsigned int keycode); static void glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods); static void glfw_mouse_scroll_callback(GLFWwindow* window, double x_offset, double y_offset); static void glfw_cursor_pos_callback(GLFWwindow* window, double x_pos, double y_pos); private: GLFWwindow* m_window; EventHandler m_event_handler; std::string m_title; unsigned int m_width; unsigned int m_height; bool m_is_closed; bool m_cursor_locked = false; bool m_cursor_visible = true; ImFont* m_main_font = nullptr; ImFont* m_small_font = nullptr; ImFont* m_large_font = nullptr; }; }