Repository navigation
Expand file tree
/
Copy pathFEWindow.h
More file actions
155 lines (126 loc) · 5.78 KB
/
Copy pathFEWindow.h
File metadata and controls
155 lines (126 loc) · 5.78 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#pragma once
#include "FEConsoleWindow.h"
#define IMGUI_DEFINE_MATH_OPERATORS
#include "imgui/imgui.h"
#include "imgui/imgui_impl_glfw.h"
#include "imgui/imgui_impl_opengl3.h"
#include "imgui/imgui_internal.h"
#include "imgui/misc/cpp/imgui_stdlib.h"
#include "GL/glew.h"
#include "GL/wglew.h"
#include <GLFW/glfw3.h>
#include <GL/GL.h>
namespace FocalEngine
{
// Since 1.92.8 ImGui OpenGL3 backend binds its own mipmap-less sampler object, which overrides texture filtering.
// This function restores previous behavior.
void RestoreImGuiTextureFilteringForCurrentFrame();
struct MonitorInfo
{
GLFWmonitor* Monitor = nullptr;
std::string Name;
int VirtualX = 0;
int VirtualY = 0;
const GLFWvidmode* VideoMode;
};
class FEWindow
{
friend class FEBasicApplication;
GLFWwindow* GLFWWindow = nullptr;
ImGuiContext* ImguiContext = nullptr;
std::string ID;
std::string Title = "FEWindow";
bool bShouldClose = false;
bool bShouldTerminate = false;
bool bOverrideImGuiTextureFiltering = true;
bool bDefaultDockspaceEnabled = false;
ImGuiID DefaultDockspaceID = 0;
FEWindow(int Width = 1280, int Height = 720, std::string WindowTitle = "FEWindow");
FEWindow(MonitorInfo* Monitor);
void InitializeImGui();
void TerminateImGui();
~FEWindow();
// User Callbacks
std::vector<std::pair<std::string, std::function<void()>>> UserOnCloseCallbackFuncs;
std::vector<std::pair<std::string, std::function<void(int)>>> UserOnFocusCallbackFuncs;
std::vector<std::pair<std::string, std::function<void()>>> UserOnTerminateCallbackFuncs;
std::vector<std::pair<std::string, std::function<void(int, int)>>> UserOnResizeCallbackFuncs;
std::vector<std::pair<std::string, std::function<void(int)>>> UserOnMouseEnterCallbackFuncs;
std::vector<std::pair<std::string, std::function<void(int, int, int)>>> UserOnMouseButtonCallbackFuncs;
std::vector<std::pair<std::string, std::function<void(double, double)>>> UserOnMouseMoveCallbackFuncs;
std::vector<std::pair<std::string, std::function<void(unsigned int)>>> UserOnCharCallbackFuncs;
std::vector<std::pair<std::string, std::function<void(int, int, int, int)>>> UserOnKeyCallbackFuncs;
std::vector<std::pair<std::string, std::function<void(int, const char**)>>> UserOnDropCallbackFuncs;
std::vector<std::pair<std::string, std::function<void(double, double)>>> UserOnScrollCallbackFuncs;
std::vector< std::pair<std::string, std::function<void(GLFWmonitor*, int)>>> UserOnMonitorCallbackFuncs;
// User Render Function
std::function<void()> UserRenderFunctionImpl;
ImGuiContext* TempImguiContext = nullptr;
GLFWwindow* TempGLFWContext = nullptr;
void EnsureCorrectContextBegin();
void EnsureCorrectContextEnd();
// Callback functions that will be invoked from APPLICATION
void InvokeCloseCallback();
void InvokeOnFocusCallback(int Focused);
void InvokeTerminateCallback();
void InvokeResizeCallback(int Width, int Height);
void InvokeMouseEnterCallback(int Entered);
void InvokeMouseButtonCallback(int Button, int Action, int Mods);
void InvokeMouseMoveCallback(double Xpos, double Ypos);
void InvokeCharCallback(unsigned int Codepoint);
void InvokeKeyCallback(int Key, int Scancode, int Action, int Mods);
void InvokeDropCallback(int Count, const char** Paths);
void InvokeScrollCallback(double Xoffset, double Yoffset);
void InvokeMonitorCallback(GLFWmonitor* Monitor, int Event);
public:
// Prevent copying and assignment
FEWindow(const FEWindow&) = delete;
FEWindow& operator=(const FEWindow&) = delete;
std::string GetID() const;
// Properties Getters and Setters
std::string GetTitle() const;
void SetTitle(const std::string NewValue);
void GetPosition(int* Xpos, int* Ypos) const;
int GetXPosition() const;
int GetYPosition() const;
void GetSize(int* Width, int* Height) const;
void SetSize(int NewWidth, int NewHeight);
int GetWidth() const;
int GetHeight() const;
std::function<void()> GetRenderFunction();
void SetRenderFunction(std::function<void()> UserRenderFunction);
void ClearRenderFunction();
void Render();
void BeginFrame();
void EndFrame();
// Window state
bool IsInFocus() const;
void Minimize() const;
void Restore() const;
void EnableDefaultDockspace();
bool HasDefaultDockspace() const;
ImGuiID GetDefaultDockspaceID() const;
void SetOverrideImGuiTextureFiltering(bool bNewValue);
bool GetOverrideImGuiTextureFiltering() const;
void CancelClose();
void Terminate();
// Event Handling
std::string AddOnCloseCallback(std::function<void()> UserOnCloseCallback);
std::string AddOnFocusCallback(std::function<void(int)> UserOnFocusCallback);
std::string AddOnTerminateCallback(std::function<void()> UserOnTerminateCallback);
std::string AddOnResizeCallback(std::function<void(int, int)> UserOnResizeCallback);
std::string AddOnMouseEnterCallback(std::function<void(int)> UserOnMouseEnterCallback);
std::string AddOnMouseButtonCallback(std::function<void(int, int, int)> UserOnMouseButtonCallback);
std::string AddOnMouseMoveCallback(std::function<void(double, double)> UserOnMouseMoveCallback);
std::string AddOnCharCallback(std::function<void(unsigned int)> UserOnCharCallback);
std::string AddOnKeyCallback(std::function<void(int, int, int, int)> UserOnKeyCallback);
std::string AddOnDropCallback(std::function<void(int, const char**)> UserOnDropCallback);
std::string AddOnScrollCallback(std::function<void(double, double)> UserOnScrollCallback);
std::string AddOnMonitorCallback(std::function<void(GLFWmonitor*, int)> UserOnMonitorCallback);
// TO-DO: It is problematic to require the user to remove the callback or the application will crash. We should remove it automatically.
void RemoveCallback(std::string CallbackID);
GLFWwindow* GetGlfwWindow() const;
ImGuiContext* GetImGuiContext() const;
MonitorInfo DetermineCurrentMonitor();
};
}