Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
Muto::WindowsWindow Class Reference

#include <WindowsWindow.h>

Inheritance diagram for Muto::WindowsWindow:
Muto::Window

Classes

struct  WindowData
 

Public Member Functions

unsigned int GetHeight () const override
 Retrieves the height of the window.
 
virtual void * GetNativeWindow () const override
 Retrieves the native window handle.
 
unsigned int GetWidth () const override
 Retrieves the width of the window.
 
bool IsVSync () const override
 Checks if vertical synchronization (VSync) is enabled.
 
void OnUpdate () override
 Called every frame to update 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.
 
 WindowsWindow (const WindowProps &props)
 
virtual ~WindowsWindow ()
 
- Public Member Functions inherited from Muto::Window
virtual ~Window ()
 

Private Member Functions

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

Private Attributes

GraphicsContext * m_Context
 
WindowData m_Data
 
GLFWwindow * m_Window
 

Additional Inherited Members

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

Class Documentation

◆ Muto::WindowsWindow::WindowData

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

Constructor & Destructor Documentation

◆ WindowsWindow()

Muto::WindowsWindow::WindowsWindow ( const WindowProps &  props)
26 {
28 Init(props);
29 }
#define MU_PROFILE_FUNCTION()
Definition Instrumentor.h:240
virtual void Init(const WindowProps &props)
Definition WindowsWindow.cpp:36
constexpr Scope< T > CreateScope(Args &&... args)
Creates a Scope (unique_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:51

References Init().

◆ ~WindowsWindow()

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

References Shutdown().

Member Function Documentation

◆ GetHeight()

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

Retrieves the height of the window.

Implements Muto::Window.

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

◆ GetNativeWindow()

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

Retrieves the native window handle.

Implements Muto::Window.

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

◆ GetWidth()

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

Retrieves the width of the window.

Implements Muto::Window.

18{ return m_Data.Width; }
unsigned int Width
Definition WindowsWindow.h:35

◆ Init()

void Muto::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 MU_CORE_INFO("Creating window {0} ({1}, {2})", props.Title, props.Width, props.Height);
44
45
47 {
48 int success = glfwInit();
49 MU_CORE_ASSERT(success, "Could not initialize GLFW!");
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
61 SetVSync(true);
62
63 // Set GLFW callbacks
65 {
66 WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);
67 data.Height = height;
68 data.Width = width;
69
70 WindowResizeEvent event(width, height);
71 MU_CORE_WARN("Window resized to {0}, {1}", width, height);
72 data.EventCallback(event);
73 });
74
76 {
77 WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);
78 WindowCloseEvent event;
79 data.EventCallback(event);
80 });
81
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
109 {
110 WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);
111 KeyTypedEvent event(keycode);
112 data.EventCallback(event);
113 });
114
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
136 {
137 WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);
138 MouseScrolledEvent event((float)xOffset, (float)yOffset);
139 data.EventCallback(event);
140 });
141
143 {
144 WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window);
145 MouseMovedEvent event((float)xPos, (float)yPos);
146 data.EventCallback(event);
147 });
148 }
#define MU_CORE_ASSERT(x,...)
Definition Asserts.h:32
#define MU_CORE_WARN(...)
warn: indicates a potential issue or important event
Definition Log.h:40
#define MU_CORE_INFO(...)
info: general information about application flow
Definition Log.h:38
virtual void Init()=0
Initializes the graphics context.
void SetVSync(bool enabled) override
Sets whether vertical synchronization (VSync) is enabled.
Definition WindowsWindow.cpp:163
GraphicsContext * m_Context
Definition WindowsWindow.h:31
std::string Title
Definition WindowsWindow.h:34
static bool s_GLFWInitialized
Definition WindowsWindow.cpp:13
static void GLFWErrorCallback(int error, const char *description)
Definition WindowsWindow.cpp:15

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

Referenced by WindowsWindow().

◆ IsVSync()

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

Checks if vertical synchronization (VSync) is enabled.

Implements Muto::Window.

175 {
176 return m_Data.VSync;
177 }
bool VSync
Definition WindowsWindow.h:36

◆ OnUpdate()

void Muto::WindowsWindow::OnUpdate ( )
overridevirtual

Called every frame to update the window.

Implements Muto::Window.

157 {
161 }
virtual void SwapBuffers()=0

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

◆ SetEventCallback()

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

Sets the callback function for window events.

Implements Muto::Window.

EventCallbackFn EventCallback
Definition WindowsWindow.h:38

◆ SetVSync()

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

Sets whether vertical synchronization (VSync) is enabled.

Implements Muto::Window.

164 {
166
167 if (enabled)
169 else
172 }

Referenced by Init().

◆ Shutdown()

void Muto::WindowsWindow::Shutdown ( )
privatevirtual

Referenced by ~WindowsWindow().

Member Data Documentation

◆ m_Context

GraphicsContext* Muto::WindowsWindow::m_Context
private

Referenced by Init(), and OnUpdate().

◆ m_Data

WindowData Muto::WindowsWindow::m_Data
private

◆ m_Window

GLFWwindow* Muto::WindowsWindow::m_Window
private

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