-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathglfw_window.hpp
More file actions
97 lines (75 loc) · 1.9 KB
/
Copy pathglfw_window.hpp
File metadata and controls
97 lines (75 loc) · 1.9 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <string_view>
#include <cstdint>
#include <functional>
namespace bnb::example
{
enum class glfw_event_t : int32_t
{
window_move,
window_resize,
window_close,
framebuffer_resize,
mouse_press,
mouse_release,
mouse_move,
mouse_hower,
mouse_left,
scroll,
key_press,
key_repeat,
key_release,
input_codepoint,
drop_files
};
struct glfw_event
{
glfw_event_t type;
GLFWwindow* window;
union {
double scroll_x;
const char** file_paths;
int32_t pos_x;
int32_t size_width;
int32_t keyboard_key;
int32_t mouse_button;
uint32_t codepoint;
};
union {
double scroll_y;
int32_t file_count;
int32_t pos_y;
int32_t size_height;
int32_t keyboard_scancode;
int32_t mouse_mods;
};
union {
int32_t keyboard_mods;
};
}; /* glfw_event */
class glfw_window
{
public:
using glfw_event_callback = std::function<void(const glfw_event& event)>;
public:
glfw_window(const std::string_view& title);
~glfw_window();
void make_context_current();
void make_nothing_current();
void swap_buffers();
void set_glfw_events_callback(glfw_event_callback callback);
void show_window_and_run_events_loop();
[[nodiscard]] GLFWwindow* get_window() const
{
return m_window;
}
private:
void track_events();
void untrack_events();
private:
GLFWwindow* m_window {nullptr};
glfw_event_callback m_glfw_event_callback;
}; /* class glfw_window */
} /* namespace bnb */