-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.hpp
102 lines (81 loc) · 2.46 KB
/
window.hpp
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
98
99
100
101
102
#pragma once
#include "event.hpp"
#include "mouse_events_refiner.hpp"
struct GLFWwindow;
class camera;
class game_object;
class shader_program;
class viewport;
class window
{
private:
enum class state
{
uninitialized,
initialized,
closed,
};
public:
struct layout
{
virtual ~layout() = default;
virtual void calculate_layout(window*) = 0;
};
struct layout_single : layout
{
void calculate_layout(window*) override;
};
public:
void init();
void set_active();
size_t get_width() const;
size_t get_height() const;
glm::vec<2, size_t> get_size() const;
void resize(size_t width, size_t height);
glm::vec<2, size_t> position() const;
void move(size_t x, size_t y);
void update();
void toggle_indexing();
bool has_grab() const;
void add_viewport(std::shared_ptr<viewport> vp);
std::vector<std::shared_ptr<viewport>> get_viewports() const;
void remove_viewport(std::shared_ptr<viewport> vp);
std::shared_ptr<viewport> get_main_viewport();
template <typename T>
requires std::is_base_of_v<layout, T>
void set_layout()
{
_layout = std::make_unique<T>();
update_layout();
}
event<void(window*)> on_window_closed;
event<void(window*, size_t w, size_t h)> on_window_resized;
// TODO: handling should be improved
event<void()> on_custom_draw;
void set_mouse_events_refiner(mouse_events_refiner* mouse_events_refiner_);
mouse_events_refiner* mouse_events() const;
game_object* find_game_object_at_position(double x, double y);
static window* get_main_window();
private:
void update_layout();
void setup_mouse_callbacks();
void configure_object_index_mapping();
void configure_input_system();
static void key_callback(int key, int scancode, int action, int mods);
private:
GLFWwindow* _window { nullptr };
state _state = state::uninitialized;
glm::vec<2, size_t> _size { 800, 600 };
bool _is_main_window { false };
camera* _view_camera { nullptr };
std::unique_ptr<layout> _layout { nullptr };
mouse_events_refiner* _mouse_events { nullptr };
std::vector<std::shared_ptr<viewport>> _viewports;
bool _has_grab = false;
unsigned _object_index_map;
unsigned _object_index_depth_map;
unsigned _object_index_fbo;
shader_program* _object_index_map_shader;
bool _index_rendering { false };
static window* _main_window;
};