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
22
namespace
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
53
int
Monitor
;
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
104
void
SetDropCallback
(
DropCallback
cb);
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
126
void
SetRefreshCallback
(
RefreshCallback
cb);
127
132
using
CloseCallback
= std::function<void(
Window
*)>;
133
137
void
SetCloseCallback
(
CloseCallback
cb);
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
:
192
DropCallback
mp_DropCallback
;
193
CloseCallback
mp_CloseCallback
;
194
RefreshCallback
mp_RefreshCallback
;
195
196
private
:
197
GLFWwindow*
m_Handle
;
198
bool
m_CursorHidden
;
199
WindowSpec
m_Spec
;
200
GLFWcursor*
m_BlankCursor
=
nullptr
;
201
};
202
203
}
// namespace FuncDoodle::Platform
FuncDoodle::Platform::Window::SetCursorHidden
void SetCursorHidden(bool hidden)
Enables or disables cursor visibility.
Definition
Window.cc:282
FuncDoodle::Platform::Window::SwapBuffers
void SwapBuffers()
Swaps front and back buffers.
Definition
Window.cc:192
FuncDoodle::Platform::Window::~Window
~Window()
Definition
Window.cc:259
FuncDoodle::Platform::Window::ErrorCallback
void(*)(int err, const char *desc) ErrorCallback
Callback type invoked for GLFW errors.
Definition
Window.h:110
FuncDoodle::Platform::Window::ShouldClose
bool ShouldClose()
Returns whether the window should close.
Definition
Window.cc:180
FuncDoodle::Platform::Window::DropCallback
std::function< void(Window *, int, const char **)> DropCallback
Callback type invoked for file-drop events.
Definition
Window.h:99
FuncDoodle::Platform::Window::mp_CloseCallback
CloseCallback mp_CloseCallback
Stored close callback.
Definition
Window.h:193
FuncDoodle::Platform::Window::SetDropCallback
void SetDropCallback(DropCallback cb)
Sets callback for file drop events.
Definition
Window.cc:125
FuncDoodle::Platform::Window::m_BlankCursor
GLFWcursor * m_BlankCursor
Definition
Window.h:200
FuncDoodle::Platform::Window::SetRefreshCallback
void SetRefreshCallback(RefreshCallback cb)
Sets GLFW refresh callback.
Definition
Window.cc:133
FuncDoodle::Platform::Window::SetErrorCallback
static void SetErrorCallback(ErrorCallback cb)
Sets GLFW error callback.
Definition
Window.cc:129
FuncDoodle::Platform::Window::GlfwRefreshTrampoline
static void GlfwRefreshTrampoline(GLFWwindow *glfwWin)
Definition
Window.cc:115
FuncDoodle::Platform::Window::GlfwDropTrampoline
static void GlfwDropTrampoline(GLFWwindow *glfwWin, int count, const char **paths)
Definition
Window.cc:94
FuncDoodle::Platform::Window::SetIcon
void SetIcon(std::filesystem::path icon)
Sets the window icon from a file path.
Definition
Window.cc:145
FuncDoodle::Platform::Window::PollEvents
static void PollEvents()
Polls OS and input events.
Definition
Window.cc:184
FuncDoodle::Platform::Window::GetFramebufferSize
void GetFramebufferSize(int *width, int *height)
Retrieves framebuffer size in pixels.
Definition
Window.cc:188
FuncDoodle::Platform::Window::RefreshCallback
std::function< void(Window *)> RefreshCallback
Callback type invoked when the window is refreshed.
Definition
Window.h:121
FuncDoodle::Platform::Window::m_CursorHidden
bool m_CursorHidden
Definition
Window.h:198
FuncDoodle::Platform::Window::mp_RefreshCallback
RefreshCallback mp_RefreshCallback
Definition
Window.h:194
FuncDoodle::Platform::Window::SetCloseCallback
void SetCloseCallback(CloseCallback cb)
Sets callback for window close events.
Definition
Window.cc:137
FuncDoodle::Platform::Window::mp_DropCallback
DropCallback mp_DropCallback
Stored file-drop callback.
Definition
Window.h:192
FuncDoodle::Platform::Window::m_Spec
WindowSpec m_Spec
Definition
Window.h:199
FuncDoodle::Platform::Window::InitImGui
void InitImGui()
Initializes ImGui for this window.
Definition
Window.cc:207
FuncDoodle::Platform::Window::InitGlfw
static void InitGlfw()
Initializes GLFW (must be called once before creating windows).
Definition
Window.cc:196
FuncDoodle::Platform::Window::m_Handle
GLFWwindow * m_Handle
< Stored refresh callback.
Definition
Window.h:197
FuncDoodle::Platform::Window::GlfwCloseTrampoline
static void GlfwCloseTrampoline(GLFWwindow *glfwWin)
Definition
Window.cc:105
FuncDoodle::Platform::Window::GetCursorHidden
bool GetCursorHidden() const
Returns whether the cursor is currently hidden.
Definition
Window.h:172
FuncDoodle::Platform::Window::SetLimits
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
FuncDoodle::Platform::Window::Window
Window(WindowSpec spec)
Creates a window from an initial specification.
Definition
Window.cc:20
FuncDoodle::Platform::Window::SetTitle
void SetTitle(const char *title)
Sets the window title.
Definition
Window.cc:141
FuncDoodle::Platform::Window::CloseCallback
std::function< void(Window *)> CloseCallback
Callback type invoked when the window is asked to close.
Definition
Window.h:132
FuncDoodle::Platform::Window::SetShouldClose
void SetShouldClose(bool shouldClose)
Requests the window to close.
Definition
Window.cc:176
FuncDoodle::Platform
Definition
Window.cc:17
FuncDoodle::Platform::g_GlfwInitted
bool g_GlfwInitted
Global flag indicating whether GLFW has been initialized.
Definition
Window.cc:18
FuncDoodle::Platform::WindowSpec
Initial configuration used to create a window.
Definition
Window.h:33
FuncDoodle::Platform::WindowSpec::Height
int Height
Window height at startup.
Definition
Window.h:43
FuncDoodle::Platform::WindowSpec::Monitor
int Monitor
Monitor index (0 = primary, 1 = secondary, etc.).
Definition
Window.h:53
FuncDoodle::Platform::WindowSpec::Title
const char * Title
Window title at startup.
Definition
Window.h:48
FuncDoodle::Platform::WindowSpec::Width
int Width
Window width at startup.
Definition
Window.h:38
src
Platform
Window.h
Generated by
1.16.1