Vesper 0.5.1
Vesper is short form for the Latin word for "Bat", as Vesper is designed to be small, lightweight, and easily handle things like particles and flocking behaviors in accordance with the nature of bats. \n It is meant to be a particle simulation, VFX editor, and CAN be used secondarily as a small game engine.
GitHub | Vesper Updates | Creator
Loading...
Searching...
No Matches
Vesper::WindowsWindow Class Reference

#include <WindowsWindow.h>

Inheritance diagram for Vesper::WindowsWindow:
Vesper::Window

Classes

struct  WindowData

Public Member Functions

 WindowsWindow (const WindowProps &props)
virtual ~WindowsWindow ()
void OnUpdate () override
 Called every frame to update the window.
unsigned int GetWidth () const override
 Retrieves the width of the window.
unsigned int GetHeight () const override
 Retrieves the height of the window.
void SetEventCallback (const EventCallbackFn &callback) override
 Sets the callback function for window events.
void SetVSync (bool enabled) override
 Sets whether vertical synchronization (VSync) is enabled.
bool IsVSync () const override
 Checks if vertical synchronization (VSync) is enabled.
virtual void * GetNativeWindow () const override
 Retrieves the native window handle.
Public Member Functions inherited from Vesper::Window
virtual ~Window ()

Private Member Functions

virtual void Init (const WindowProps &props)
virtual void Shutdown ()

Private Attributes

GLFWwindow * m_Window
GraphicsContextm_Context
WindowData m_Data

Additional Inherited Members

Public Types inherited from Vesper::Window
using EventCallbackFn = std::function<void(Event&)>
Static Public Member Functions inherited from Vesper::Window
static Scope< WindowCreate (const WindowProps &props=WindowProps())
 Creates a window instance with the specified properties.

Class Documentation

◆ Vesper::WindowsWindow::WindowData

struct Vesper::WindowsWindow::WindowData
Class Members
EventCallbackFn EventCallback
unsigned int Height
string Title
bool VSync
unsigned int Width

Constructor & Destructor Documentation

◆ WindowsWindow()

Vesper::WindowsWindow::WindowsWindow ( const WindowProps & props)
26 {
28 Init(props);
29 }
#define VZ_PROFILE_FUNCTION()
Definition Instrumentor.h:240
virtual void Init(const WindowProps &props)
Definition WindowsWindow.cpp:36

References Init().

◆ ~WindowsWindow()

Vesper::WindowsWindow::~WindowsWindow ( )
virtual
32 {
33 Shutdown();
34 }
virtual void Shutdown()
Definition WindowsWindow.cpp:150

References Shutdown().

Member Function Documentation

◆ GetHeight()

unsigned int Vesper::WindowsWindow::GetHeight ( ) const
inlineoverridevirtual

Retrieves the height of the window.

Implements Vesper::Window.

19{ return m_Data.Height; }
WindowData m_Data
Definition WindowsWindow.h:40

◆ GetNativeWindow()

virtual void * Vesper::WindowsWindow::GetNativeWindow ( ) const
inlineoverridevirtual

Retrieves the native window handle.

Implements Vesper::Window.

25{ return m_Window; }
GLFWwindow * m_Window
Definition WindowsWindow.h:30

◆ GetWidth()

unsigned int Vesper::WindowsWindow::GetWidth ( ) const
inlineoverridevirtual

Retrieves the width of the window.

Implements Vesper::Window.

18{ return m_Data.Width; }

◆ Init()

void Vesper::WindowsWindow::Init ( const WindowProps & props)
privatevirtual
37 {
39 m_Data.Title = props.Title;
40 m_Data.Width = props.Width;
41 m_Data.Height = props.Height;
42
43 VZ_CORE_INFO("Creating window {0} ({1}, {2})", props.Title, props.Width, props.Height);
44
45
47 {
48 int success = glfwInit();
49 VZ_CORE_ASSERT(success, "Could not initialize GLFW!");
50 glfwSetErrorCallback(GLFWErrorCallback);
51 s_GLFWInitialized = true;
52 }
53
54 m_Window = glfwCreateWindow((int)props.Width, (int)props.Height, m_Data.Title.c_str(), nullptr, nullptr);
55
56 m_Context = new OpenGLContext(m_Window);
57 m_Context->Init();
58
59
60 glfwSetWindowUserPointer(m_Window, &m_Data);
61 SetVSync(true);
62
63 // Set GLFW callbacks
64 glfwSetWindowSizeCallback(m_Window, [](GLFWwindow* window, int width, int height)
65 {
66 WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);
67 data.Height = height;
68 data.Width = width;
69
70 WindowResizeEvent event(width, height);
71 VZ_CORE_WARN("Window resized to {0}, {1}", width, height);
72 data.EventCallback(event);
73 });
74
75 glfwSetWindowCloseCallback(m_Window, [](GLFWwindow* window)
76 {
77 WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);
78 WindowCloseEvent event;
79 data.EventCallback(event);
80 });
81
82 glfwSetKeyCallback(m_Window, [](GLFWwindow* window, int key, int scancode, int action, int mods)
83 {
84 WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);
85 switch (action)
86 {
87 case GLFW_PRESS:
88 {
89 KeyPressedEvent event(key, 0);
90 data.EventCallback(event);
91 break;
92 }
93 case GLFW_RELEASE:
94 {
95 KeyReleasedEvent event(key);
96 data.EventCallback(event);
97 break;
98 }
99 case GLFW_REPEAT:
100 {
101 KeyPressedEvent event(key, 1);
102 data.EventCallback(event);
103 break;
104 }
105 }
106 });
107
108 glfwSetCharCallback(m_Window, [](GLFWwindow* window, unsigned int keycode)
109 {
110 WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);
111 KeyTypedEvent event(keycode);
112 data.EventCallback(event);
113 });
114
115 glfwSetMouseButtonCallback(m_Window, [](GLFWwindow* window, int button, int action, int mods)
116 {
117 WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);
118 switch (action)
119 {
120 case GLFW_PRESS:
121 {
122 MouseButtonPressedEvent event(button);
123 data.EventCallback(event);
124 break;
125 }
126 case GLFW_RELEASE:
127 {
128 MouseButtonReleasedEvent event(button);
129 data.EventCallback(event);
130 break;
131 }
132 }
133 });
134
135 glfwSetScrollCallback(m_Window, [](GLFWwindow* window, double xOffset, double yOffset)
136 {
137 WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);
138 MouseScrolledEvent event((float)xOffset, (float)yOffset);
139 data.EventCallback(event);
140 });
141
142 glfwSetCursorPosCallback(m_Window, [](GLFWwindow* window, double xPos, double yPos)
143 {
144 WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);
145 MouseMovedEvent event((float)xPos, (float)yPos);
146 data.EventCallback(event);
147 });
148 }
#define VZ_CORE_ASSERT(x,...)
Definition Asserts.h:20
#define VZ_CORE_WARN(...)
warn: indicates a potential issue or important event
Definition Log.h:39
#define VZ_CORE_INFO(...)
info: general information about application flow
Definition Log.h:37
GraphicsContext * m_Context
Definition WindowsWindow.h:31
unsigned int Height
Definition WindowsWindow.h:35
EventCallbackFn EventCallback
Definition WindowsWindow.h:38
void SetVSync(bool enabled) override
Sets whether vertical synchronization (VSync) is enabled.
Definition WindowsWindow.cpp:163
Definition WindowsWindow.h:33
static bool s_GLFWInitialized
Definition WindowsWindow.cpp:13
static void GLFWErrorCallback(int error, const char *description)
Definition WindowsWindow.cpp:15

References Vesper::GLFWErrorCallback(), Vesper::WindowProps::Height, Vesper::GraphicsContext::Init(), m_Context, Vesper::s_GLFWInitialized, SetVSync(), and Vesper::WindowProps::Width.

Referenced by WindowsWindow().

◆ IsVSync()

bool Vesper::WindowsWindow::IsVSync ( ) const
overridevirtual

Checks if vertical synchronization (VSync) is enabled.

Implements Vesper::Window.

175 {
176 return m_Data.VSync;
177 }

◆ OnUpdate()

void Vesper::WindowsWindow::OnUpdate ( )
overridevirtual

Called every frame to update the window.

Implements Vesper::Window.

157 {
159 glfwPollEvents();
160 m_Context->SwapBuffers();
161 }

References m_Context, and Vesper::GraphicsContext::SwapBuffers().

◆ SetEventCallback()

void Vesper::WindowsWindow::SetEventCallback ( const EventCallbackFn & callback)
inlineoverridevirtual

Sets the callback function for window events.

Implements Vesper::Window.

22{ m_Data.EventCallback = callback; }

◆ SetVSync()

void Vesper::WindowsWindow::SetVSync ( bool enabled)
overridevirtual

Sets whether vertical synchronization (VSync) is enabled.

Implements Vesper::Window.

164 {
166
167 if (enabled)
168 glfwSwapInterval(1);
169 else
170 glfwSwapInterval(0);
171 m_Data.VSync = enabled;
172 }

Referenced by Init().

◆ Shutdown()

void Vesper::WindowsWindow::Shutdown ( )
privatevirtual
151 {
153 glfwDestroyWindow(m_Window);
154 }

Referenced by ~WindowsWindow().

Member Data Documentation

◆ m_Context

GraphicsContext* Vesper::WindowsWindow::m_Context
private

Referenced by Init(), and OnUpdate().

◆ m_Data

WindowData Vesper::WindowsWindow::m_Data
private

◆ m_Window

GLFWwindow* Vesper::WindowsWindow::m_Window
private

The documentation for this class was generated from the following files: