aboutsummaryrefslogtreecommitdiff
path: root/src/Core/Window.h
blob: 64cde32c45c92ecc70db1bdc21b478cceffa9270 (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
53
54
55
56
57
58
59
60
61
#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 ShouldClose() const;
        void OnUpdate()    const;

        void SetEventCallback(const EventCallbackFn& callback)
        {
            m_EventHandler.SetEventCallback(callback);
        }

        EventHandler& GetEventHandler() { return m_EventHandler; }

        unsigned int GetWidth()  const { return m_Width;  }
        unsigned int GetHeight() const { return m_Height; }

        void* GetNativeWindow()  const { return m_Window; }

        void SetCursorLocked(bool locked);
        void SetCursorVisible(bool visible);
        bool IsCursorLocked()  const { return m_CursorLocked;  }
        bool IsCursorVisible() const { return m_CursorVisible; }
    private:
        void Init();
        void Shutdown();

        static void GLFWErrorCallback(int error, const char* description);
        static void GLFWWindowCloseCallback(GLFWwindow* window);
        static void GLFWWindowSizeCallback(GLFWwindow* window, int width, int height);
        static void GLFWWindowFocusCallback(GLFWwindow* window, int focused);
        static void GLFWWindowPosCallback(GLFWwindow* window, int xpos, int ypos);
        static void GLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
        static void GLFWCharCallback(GLFWwindow* window, unsigned int keycode);
        static void GLFWMouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
        static void GLFWMouseScrollCallback(GLFWwindow* window, double xOffset, double yOffset);
        static void GLFWCursorPosCallback(GLFWwindow* window, double xPos, double yPos);
    private:
        GLFWwindow*  m_Window;
        EventHandler m_EventHandler;

        std::string  m_Title;
        unsigned int m_Width;
        unsigned int m_Height;
        bool m_IsClosed;
        bool m_CursorLocked  = false;
        bool m_CursorVisible = true;
    };
}