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
80 void SetIcon(std::filesystem::path icon);
81
86 using DropCallback = std::function<void(Window*, int, const char**)>;
87
92
97 using ErrorCallback = void (*)(int err, const char* desc);
98
102 static void SetErrorCallback(ErrorCallback cb);
103
108 using CloseCallback = std::function<void(Window*)>;
109
114
118 void SetShouldClose(bool shouldClose);
119
123 bool ShouldClose();
124
128 static void PollEvents();
129
133 void GetFramebufferSize(int* width, int* height);
134
138 void SwapBuffers();
139
143 void SetCursorHidden(bool hidden);
144
148 [[nodiscard]] bool GetCursorHidden() const { return m_CursorHidden; }
149
154 static void InitGlfw();
155
159 void InitImGui();
160
161 private:
162 static void GlfwDropTrampoline(
163 GLFWwindow* glfwWin, int count, const char** paths);
164 static void GlfwCloseTrampoline(GLFWwindow* glfwWin);
165
166 protected:
169
170 private:
171 GLFWwindow* m_Handle;
174 GLFWcursor* m_BlankCursor = nullptr;
175 };
176
177} // namespace FuncDoodle::Platform
void SetCursorHidden(bool hidden)
Enables or disables cursor visibility.
Definition Window.cc:258
void SwapBuffers()
Swaps front and back buffers.
Definition Window.cc:165
~Window()
Definition Window.cc:235
void(*)(int err, const char *desc) ErrorCallback
Callback type invoked for GLFW errors.
Definition Window.h:97
bool ShouldClose()
Returns whether the window should close.
Definition Window.cc:153
std::function< void(Window *, int, const char **)> DropCallback
Callback type invoked for file-drop events.
Definition Window.h:86
CloseCallback mp_CloseCallback
Stored close callback.
Definition Window.h:168
void SetDropCallback(DropCallback cb)
Sets callback for file drop events.
Definition Window.cc:111
GLFWcursor * m_BlankCursor
Definition Window.h:174
static void SetErrorCallback(ErrorCallback cb)
Sets GLFW error callback.
Definition Window.cc:115
static void GlfwDropTrampoline(GLFWwindow *glfwWin, int count, const char **paths)
Definition Window.cc:90
void SetIcon(std::filesystem::path icon)
Sets the window icon from a file path.
Definition Window.cc:127
static void PollEvents()
Polls OS and input events.
Definition Window.cc:157
void GetFramebufferSize(int *width, int *height)
Retrieves framebuffer size in pixels.
Definition Window.cc:161
bool m_CursorHidden
Definition Window.h:172
void SetCloseCallback(CloseCallback cb)
Sets callback for window close events.
Definition Window.cc:119
DropCallback mp_DropCallback
Stored file-drop callback.
Definition Window.h:167
WindowSpec m_Spec
Definition Window.h:173
void InitImGui()
Initializes ImGui for this window.
Definition Window.cc:183
static void InitGlfw()
Initializes GLFW (must be called once before creating windows).
Definition Window.cc:169
GLFWwindow * m_Handle
Definition Window.h:171
static void GlfwCloseTrampoline(GLFWwindow *glfwWin)
Definition Window.cc:101
bool GetCursorHidden() const
Returns whether the cursor is currently hidden.
Definition Window.h:148
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:123
std::function< void(Window *)> CloseCallback
Callback type invoked when the window is asked to close.
Definition Window.h:108
void SetShouldClose(bool shouldClose)
Requests the window to close.
Definition Window.cc:149
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