hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/core/window.h
blob: 8e9778e76911734416aa03668ae24e19f1878901 (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
#pragma once

#include <GLFW/glfw3.h>
#include <string>
#include "event.h"

namespace Donut
{
    class Window
    {
    public:
        using EventCallbackFn = std::function<void(Event&)>;

        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; }

    private:
        void init();
        void shutdown();

        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;
    };
}