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