Program Listing for File Window.cpp¶
↰ Return to documentation for file (Source\Azura\RenderSystem\Src\Generic\Window.cpp
)
#include "Generic/Window.h"
#include <utility>
namespace Azura {
Window::Window(String title, const U32 width, const U32 height)
: log_Window(std::move(Log("Window"))),
m_midWidth(width / 2.0f),
m_midHeight(height / 2.0f),
m_rate(UpdateRate::RateUnlocked),
m_width(width),
m_height(height),
m_title(std::move(title)),
p_windowResource(nullptr) {
}
void Window::SetUpdateCallback(std::function<void(float)> eventUpdate) {
p_updateFunc = eventUpdate;
}
void Window::SetMouseEventCallback(std::function<void(MouseEvent)> eventFunc) {
p_mouseEventFunc = eventFunc;
}
void Window::SetKeyEventCallback(std::function<void(KeyEvent)> eventFunc) {
p_keyEventFunc = eventFunc;
}
ViewportDimensions Window::GetViewport() const {
ViewportDimensions dimension{};
dimension.m_x = 0;
dimension.m_y = 0;
dimension.m_width = static_cast<float>(m_width);
dimension.m_height = static_cast<float>(m_height);
dimension.m_minDepth = 0.0f;
dimension.m_maxDepth = 1.0f;
return dimension;
}
void Window::SetUpdateRate(UpdateRate rate) {
m_rate = rate;
}
SwapChainRequirements Window::GetSwapChainRequirements() const {
SwapChainRequirements requirement;
requirement.m_colorSpace = ColorSpace::SRGB;
requirement.m_format = RawStorageFormat::B8G8R8A8_UNORM;
requirement.m_depthFormat = RawStorageFormat::D32_FLOAT;
requirement.m_extent = Bounds2D(m_width, m_height);
requirement.m_framesInFlight = 2u;
return requirement;
}
U32 Window::GetWidth() const {
return m_width;
}
U32 Window::GetHeight() const {
return m_height;
}
const void* Window::GetHandle() const {
return p_windowResource;
}
void Window::SetHandle(void* window) {
p_windowResource = window;
}
const char* Window::GetTitle() const {
return m_title.c_str();
}
void Window::CallUpdateFunction(float timeDelta) const {
p_updateFunc(timeDelta);
}
void Window::CallMouseEventFunction(MouseEvent e) const {
if (!p_mouseEventFunc) {
return;
}
p_mouseEventFunc(e);
}
void Window::CallKeyEventFunction(KeyEvent e) const {
if (!p_keyEventFunc) {
return;
}
p_keyEventFunc(e);
}
} // namespace Azura