Added a very basic window object that essentially just wraps an GLFW window object. TODO: Set the window userdata pointer to point to its wrapping object
73 lines
1.8 KiB
C++
73 lines
1.8 KiB
C++
#include "basalt_window.h"
|
|
|
|
basalt::Window::Window(Window&& other) noexcept
|
|
{
|
|
this->window = other.window;
|
|
this->window_title = other.window_title;
|
|
this->height = other.height;
|
|
this->width = other.width;
|
|
other.height = 0;
|
|
other.width = 0;
|
|
other.window = nullptr;
|
|
other.window_title = nullptr;
|
|
|
|
}
|
|
|
|
basalt::Window& basalt::Window::operator=(Window&& other) noexcept
|
|
{
|
|
if (&other == this) return *this;
|
|
this->~Window();
|
|
this->window = other.window;
|
|
this->window_title = other.window_title;
|
|
this->height = other.height;
|
|
this->width = other.width;
|
|
other.height = 0;
|
|
other.width = 0;
|
|
other.window = nullptr;
|
|
other.window_title = nullptr;
|
|
return *this;
|
|
}
|
|
|
|
basalt::Window::Window(uint16_t width, uint16_t height, const char* title) :
|
|
width(width), height(height), window_title(title)
|
|
{
|
|
glfwInit();
|
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
|
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
|
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
|
|
this->window = glfwCreateWindow(width, height, title, nullptr, nullptr);
|
|
}
|
|
|
|
basalt::Window::~Window(void) noexcept
|
|
{
|
|
glfwDestroyWindow(this->window);
|
|
}
|
|
|
|
void basalt::Window::swap(Window& other) noexcept
|
|
{
|
|
{
|
|
uint16_t tmp = this->height;
|
|
this->height = other.height;
|
|
other.height = tmp;
|
|
tmp = this->width;
|
|
this->width = other.width;
|
|
other.width = tmp;
|
|
}
|
|
{
|
|
void* tmp_ptr = this->window;
|
|
this->window = other.window;
|
|
other.window = static_cast<GLFWwindow*>(tmp_ptr);
|
|
tmp_ptr = const_cast<char*>(this->window_title);
|
|
this->window_title = other.window_title;
|
|
other.window_title = static_cast<const char*>(tmp_ptr);
|
|
}
|
|
}
|
|
|
|
basalt::Window::operator GLFWwindow* (void) const noexcept
|
|
{ return this->window; }
|
|
|
|
const bool basalt::Window::should_close(void) const noexcept
|
|
{
|
|
return glfwWindowShouldClose(this->window);
|
|
}
|