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