FuncDoodle
Loading...
Searching...
No Matches
Window.h
Go to the documentation of this file.
1
13
14#pragma once
15
16#define GLFW_INCLUDE_NONE
17#include "GLFW/glfw3.h"
18
19#include <filesystem>
20#include <functional>
21
22namespace FuncDoodle::Platform {
23
27 extern bool g_GlfwInitted;
28
33 struct WindowSpec {
34
38 int Width;
39
43 int Height;
44
48 const char* Title;
49
54 };
55
61 class Window {
62 public:
69 Window(WindowSpec spec);
70 ~Window();
71
75 void SetTitle(const char* title);
76
88 void SetLimits(int minW, int minH, int maxW, int maxH);
89
93 void SetIcon(std::filesystem::path icon);
94
99 using DropCallback = std::function<void(Window*, int, const char**)>;
100
105
110 using ErrorCallback = void (*)(int err, const char* desc);
111
115 static void SetErrorCallback(ErrorCallback cb);
116
121 using RefreshCallback = std::function<void(Window*)>;
122
127
132 using CloseCallback = std::function<void(Window*)>;
133
138
142 void SetShouldClose(bool shouldClose);
143
147 bool ShouldClose();
148
152 static void PollEvents();
153
157 void GetFramebufferSize(int* width, int* height);
158
162 void SwapBuffers();
163
167 void SetCursorHidden(bool hidden);
168
172 [[nodiscard]] bool GetCursorHidden() const { return m_CursorHidden; }
173
178 static void InitGlfw();
179
183 void InitImGui();
184
185 private:
186 static void GlfwDropTrampoline(
187 GLFWwindow* glfwWin, int count, const char** paths);
188 static void GlfwCloseTrampoline(GLFWwindow* glfwWin);
189 static void GlfwRefreshTrampoline(GLFWwindow* glfwWin);
190
191 protected:
195
196 private:
197 GLFWwindow* m_Handle;
200 GLFWcursor* m_BlankCursor = nullptr;
201 };
202
203} // namespace FuncDoodle::Platform
void SetCursorHidden(bool hidden)
Enables or disables cursor visibility.
Definition Window.cc:282
void SwapBuffers()
Swaps front and back buffers.
Definition Window.cc:192
~Window()
Definition Window.cc:259
void(*)(int err, const char *desc) ErrorCallback
Callback type invoked for GLFW errors.
Definition Window.h:110
bool ShouldClose()
Returns whether the window should close.
Definition Window.cc:180
std::function< void(Window *, int, const char **)> DropCallback
Callback type invoked for file-drop events.
Definition Window.h:99
CloseCallback mp_CloseCallback
Stored close callback.
Definition Window.h:193
void SetDropCallback(DropCallback cb)
Sets callback for file drop events.
Definition Window.cc:125
GLFWcursor * m_BlankCursor
Definition Window.h:200
void SetRefreshCallback(RefreshCallback cb)
Sets GLFW refresh callback.
Definition Window.cc:133
static void SetErrorCallback(ErrorCallback cb)
Sets GLFW error callback.
Definition Window.cc:129
static void GlfwRefreshTrampoline(GLFWwindow *glfwWin)
Definition Window.cc:115
static void GlfwDropTrampoline(GLFWwindow *glfwWin, int count, const char **paths)
Definition Window.cc:94
void SetIcon(std::filesystem::path icon)
Sets the window icon from a file path.
Definition Window.cc:145
static void PollEvents()
Polls OS and input events.
Definition Window.cc:184
void GetFramebufferSize(int *width, int *height)
Retrieves framebuffer size in pixels.
Definition Window.cc:188
std::function< void(Window *)> RefreshCallback
Callback type invoked when the window is refreshed.
Definition Window.h:121
bool m_CursorHidden
Definition Window.h:198
RefreshCallback mp_RefreshCallback
Definition Window.h:194
void SetCloseCallback(CloseCallback cb)
Sets callback for window close events.
Definition Window.cc:137
DropCallback mp_DropCallback
Stored file-drop callback.
Definition Window.h:192
WindowSpec m_Spec
Definition Window.h:199
void InitImGui()
Initializes ImGui for this window.
Definition Window.cc:207
static void InitGlfw()
Initializes GLFW (must be called once before creating windows).
Definition Window.cc:196
GLFWwindow * m_Handle
< Stored refresh callback.
Definition Window.h:197
static void GlfwCloseTrampoline(GLFWwindow *glfwWin)
Definition Window.cc:105
bool GetCursorHidden() const
Returns whether the cursor is currently hidden.
Definition Window.h:172
void SetLimits(int minW, int minH, int maxW, int maxH)
Sets the window size limits (minimum window size and maximum window size).
Definition Window.cc:167
Window(WindowSpec spec)
Creates a window from an initial specification.
Definition Window.cc:20
void SetTitle(const char *title)
Sets the window title.
Definition Window.cc:141
std::function< void(Window *)> CloseCallback
Callback type invoked when the window is asked to close.
Definition Window.h:132
void SetShouldClose(bool shouldClose)
Requests the window to close.
Definition Window.cc:176
Definition Window.cc:17
bool g_GlfwInitted
Global flag indicating whether GLFW has been initialized.
Definition Window.cc:18
Initial configuration used to create a window.
Definition Window.h:33
int Height
Window height at startup.
Definition Window.h:43
int Monitor
Monitor index (0 = primary, 1 = secondary, etc.).
Definition Window.h:53
const char * Title
Window title at startup.
Definition Window.h:48
int Width
Window width at startup.
Definition Window.h:38