CG-Project2
Loading...
Searching...
No Matches
Window.hpp
1#pragma once
2
3#include "../Graphic.hpp"
4
5#include "Layer.hpp"
6#include "Structs.hpp"
7#include "Utils.hpp"
8
9#include <functional>
10
11#include <string>
12
13namespace ogl {
14
16 std::function<void(GLFWwindow *, int, int)> resizeCallback;
17 std::function<void(GLFWwindow *, int, int, int, int)> keyCallback = nullptr;
18 std::function<void(GLFWwindow *, int, int, int)> mouseButtonCallback = nullptr;
19 std::function<void(GLFWwindow *, double, double)> cursorPosCallback = nullptr;
20 };
21
23 std::string name = "GLFW Window";
24 Pair<float> size{1600, 900};
25 Pair<int> position{0, 0};
26
27 bool maximized = false;
28 bool fullscreen = false;
29 bool focused = false;
30 bool decorated = true;
31 bool vsync = false;
32 bool debugMode = false;
33 Color bgColor = {0.3f, 0.3f, 0.3f, 1.0f};
34 };
35
36 class Window : public Layer {
37 public:
38 Window(const WindowSettings &settings);
39 Window() = delete;
40 ~Window() = default;
41
42 inline GLFWwindow *getContext() const { return this->m_context; }
43
44 inline Pair<float> getSize() const { return this->m_settings.size; }
45
46 inline float getWidth() const { return this->m_settings.size.x; }
47 void setWidth(const float &val) { this->m_settings.size.x = val; }
48
49 inline float getHeight() const { return this->m_settings.size.y; }
50 void setHeight(const float &val) { this->m_settings.size.y = val; }
51
52 void toggleVsync();
53 bool isVsyncEnabled() const;
54
55 void addClearMask(const unsigned int &val) { this->m_clearMask |= val; }
56
57 void setResizeCallback(std::function<void(GLFWwindow *, int, int)> &&func);
58 void execResizeCallback(GLFWwindow *context, const int &width, const int &height);
59
60 void setKeysCallback(std::function<void(GLFWwindow *, int, int, int, int)> &&func);
61 void execKeysCallback(GLFWwindow *context, const int &key, const int &code, const int &action, const int &mods);
62
63 void setMouseButtonCallback(std::function<void(GLFWwindow *, int, int, int)> &&func);
64 void execMouseButtonCallback(GLFWwindow *context, const int &button, const int &action, const int &mods);
65
66 void setCursorPosCallback(std::function<void(GLFWwindow *, double, double)> &&func);
67 void execCursorPosCallback(GLFWwindow *context, const double &xpos, const double &ypos);
68
69 virtual void onAttach() override;
70 virtual void onDetach() override;
71
72 virtual void onUpdate() override;
73 virtual void onRender() override;
74
75 virtual void begin() override;
76 virtual void end() override;
77
78 private:
79 GLFWwindow *m_context = nullptr;
80 WindowSettings m_settings{};
81 unsigned int m_clearMask = 0;
82
83 WindowCallbacks m_callbacks{};
84
85 void updateUserPointer();
86 };
87
88} // namespace ogl
Simple data structure to store a RGBA color.
Definition Structs.hpp:6
Definition Utils.hpp:4
Definition Window.hpp:15
Definition Window.hpp:22