mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-22 02:27:01 +08:00
feat: add Config class
This commit is contained in:
@@ -5,6 +5,9 @@
|
||||
#include <Cubed/window.hpp>
|
||||
namespace Cubed {
|
||||
|
||||
static int windowed_xpos = 0, windowed_ypos = 0;
|
||||
static int windowed_width = 800, windowed_height = 600;
|
||||
|
||||
Window::Window(Renderer& renderer) :
|
||||
m_renderer(renderer)
|
||||
{
|
||||
@@ -37,7 +40,10 @@ void Window::update_viewport() {
|
||||
m_aspect = (float)m_width / (float)m_height;
|
||||
glViewport(0, 0, m_width, m_height);
|
||||
m_renderer.update_proj_matrix(m_aspect, m_width, m_height) ;
|
||||
auto& config = Config::get();
|
||||
|
||||
config.set("window.width", windowed_width);
|
||||
config.set("window.height", windowed_height);
|
||||
}
|
||||
|
||||
void Window::init() {
|
||||
@@ -49,11 +55,23 @@ void Window::init() {
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
|
||||
m_window = glfwCreateWindow(800, 600, "Cubed", NULL, NULL);
|
||||
auto& config= Config::get();
|
||||
m_width = config.get<int>("window.width");
|
||||
m_height = config.get<int>("window.height");
|
||||
if (config.get<bool>("window.fullscreen")) {
|
||||
GLFWmonitor* primary_monitor = glfwGetPrimaryMonitor();
|
||||
m_window = glfwCreateWindow(m_width, m_height, "Cubed", primary_monitor, NULL);
|
||||
} else {
|
||||
m_window = glfwCreateWindow(m_width, m_height, "Cubed", NULL, NULL);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(m_window);
|
||||
|
||||
glfwSwapInterval(1);
|
||||
if (config.get<bool>("window.V-Sync")) {
|
||||
glfwSwapInterval(1);
|
||||
} else {
|
||||
glfwSwapInterval(0);
|
||||
}
|
||||
|
||||
|
||||
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
if (glfwRawMouseMotionSupported()) {
|
||||
@@ -69,12 +87,21 @@ void Window::init() {
|
||||
|
||||
}
|
||||
|
||||
void Window::toggle_fullscreen() {
|
||||
static int windowed_xpos = 0, windowed_ypos = 0;
|
||||
static int windowed_width = 800, windowed_height = 600;
|
||||
void Window::hot_reload() {
|
||||
auto& config= Config::get();
|
||||
// V-Sync
|
||||
if (config.get<bool>("window.V-Sync")) {
|
||||
glfwSwapInterval(1);
|
||||
} else {
|
||||
glfwSwapInterval(0);
|
||||
}
|
||||
// Window
|
||||
windowed_width = config.get<int>("window.width");
|
||||
windowed_height = config.get<int>("window.height");
|
||||
|
||||
GLFWmonitor* monitor = glfwGetWindowMonitor(m_window);
|
||||
if (monitor != nullptr) {
|
||||
if (config.get<bool>("window.fullscreen.V-Sync")) {
|
||||
GLFWmonitor* monitor = glfwGetWindowMonitor(m_window);
|
||||
if (monitor != nullptr) {
|
||||
glfwSetWindowMonitor(
|
||||
m_window,
|
||||
nullptr,
|
||||
@@ -84,6 +111,10 @@ void Window::toggle_fullscreen() {
|
||||
windowed_height,
|
||||
0
|
||||
);
|
||||
} else {
|
||||
|
||||
}
|
||||
config.set("window.fullscreen", false);
|
||||
} else {
|
||||
glfwGetWindowPos(m_window, &windowed_xpos, &windowed_ypos);
|
||||
glfwGetWindowSize(m_window, &windowed_width, &windowed_height);
|
||||
@@ -100,6 +131,47 @@ void Window::toggle_fullscreen() {
|
||||
mode->height,
|
||||
GL_DONT_CARE
|
||||
);
|
||||
config.set("window.fullscreen", true);
|
||||
|
||||
}
|
||||
update_viewport();
|
||||
|
||||
}
|
||||
|
||||
void Window::toggle_fullscreen() {
|
||||
|
||||
auto& config = Config::get();
|
||||
GLFWmonitor* monitor = glfwGetWindowMonitor(m_window);
|
||||
if (monitor != nullptr) {
|
||||
glfwSetWindowMonitor(
|
||||
m_window,
|
||||
nullptr,
|
||||
windowed_xpos,
|
||||
windowed_ypos,
|
||||
windowed_width,
|
||||
windowed_height,
|
||||
0
|
||||
);
|
||||
|
||||
config.set("window.fullscreen", false);
|
||||
} else {
|
||||
glfwGetWindowPos(m_window, &windowed_xpos, &windowed_ypos);
|
||||
glfwGetWindowSize(m_window, &windowed_width, &windowed_height);
|
||||
|
||||
GLFWmonitor* primary = glfwGetPrimaryMonitor();
|
||||
const GLFWvidmode* mode = glfwGetVideoMode(primary);
|
||||
|
||||
glfwSetWindowMonitor(
|
||||
m_window,
|
||||
primary,
|
||||
0,
|
||||
0,
|
||||
mode->width,
|
||||
mode->height,
|
||||
GL_DONT_CARE
|
||||
);
|
||||
config.set("window.fullscreen", true);
|
||||
|
||||
}
|
||||
update_viewport();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user