diff options
Diffstat (limited to 'src/Core/Window.cpp')
| -rw-r--r-- | src/Core/Window.cpp | 220 |
1 files changed, 110 insertions, 110 deletions
diff --git a/src/Core/Window.cpp b/src/Core/Window.cpp index ade0c26..047ef0d 100644 --- a/src/Core/Window.cpp +++ b/src/Core/Window.cpp @@ -1,7 +1,7 @@ #include <glad/glad.h> -#include "Window.h" -#include "ThemeManager.h" -#include "Rendering/Renderer.h" // RendererAPI::GetAPI() +#include "window.h" +#include "theme_manager.h" +#include "rendering/renderer.h" // RendererAPI::get_api() #include <cstdint> @@ -11,26 +11,26 @@ namespace Donut { - static bool s_GLFWInitialized = false; - static uint32_t s_GLFWWindowCount = 0; + static bool s_glfw_initialized = false; + static uint32_t s_glfw_window_count = 0; Window::Window(const std::string& title, int width, int height) - : m_Title(title), m_Width(width), - m_Height(height), m_IsClosed(false) + : m_title(title), m_width(width), + m_height(height), m_is_closed(false) { - Init(); + init(); } Window::~Window() { - Shutdown(); + shutdown(); } - void Window::Init() + auto Window::init() -> void { - DONUT_INFO("Initializing window: ", m_Title, " (", m_Width, "x", m_Height, ")"); - - if (!s_GLFWInitialized) + DONUT_INFO("Initializing window: ", m_title, " (", m_width, "x", m_height, ")"); + + if (!s_glfw_initialized) { int success = glfwInit(); if (!success) @@ -39,11 +39,11 @@ namespace Donut return; } - s_GLFWInitialized = true; + s_glfw_initialized = true; DONUT_INFO("GLFW initialized successfully"); } - if (RendererAPI::GetAPI() == RendererAPI::API::Vulkan) + if (RendererAPI::get_api() == RendererAPI::API::Vulkan) { // Vulkan manages presentation itself; GLFW must not create a GL context. glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); @@ -62,78 +62,78 @@ namespace Donut #endif } - m_Window = glfwCreateWindow(m_Width, m_Height, m_Title.c_str(), nullptr, nullptr); - if (!m_Window) + m_window = glfwCreateWindow(m_width, m_height, m_title.c_str(), nullptr, nullptr); + if (!m_window) { DONUT_ERROR("Could not create GLFW window!"); glfwTerminate(); return; } - + DONUT_INFO("GLFW window created successfully"); - if (RendererAPI::GetAPI() != RendererAPI::API::Vulkan) - glfwMakeContextCurrent(m_Window); - glfwSetWindowUserPointer(m_Window, this); + if (RendererAPI::get_api() != RendererAPI::API::Vulkan) + glfwMakeContextCurrent(m_window); + glfwSetWindowUserPointer(m_window, this); - glfwSetErrorCallback(GLFWErrorCallback); - glfwSetWindowCloseCallback(m_Window, GLFWWindowCloseCallback); - glfwSetWindowSizeCallback(m_Window, GLFWWindowSizeCallback); - glfwSetWindowFocusCallback(m_Window, GLFWWindowFocusCallback); - glfwSetWindowPosCallback(m_Window, GLFWWindowPosCallback); - glfwSetKeyCallback(m_Window, GLFWKeyCallback); - glfwSetCharCallback(m_Window, GLFWCharCallback); - glfwSetMouseButtonCallback(m_Window, GLFWMouseButtonCallback); - glfwSetScrollCallback(m_Window, GLFWMouseScrollCallback); - glfwSetCursorPosCallback(m_Window, GLFWCursorPosCallback); + glfwSetErrorCallback(glfw_error_callback); + glfwSetWindowCloseCallback(m_window, glfw_window_close_callback); + glfwSetWindowSizeCallback(m_window, glfw_window_size_callback); + glfwSetWindowFocusCallback(m_window, glfw_window_focus_callback); + glfwSetWindowPosCallback(m_window, glfw_window_pos_callback); + glfwSetKeyCallback(m_window, glfw_key_callback); + glfwSetCharCallback(m_window, glfw_char_callback); + glfwSetMouseButtonCallback(m_window, glfw_mouse_button_callback); + glfwSetScrollCallback(m_window, glfw_mouse_scroll_callback); + glfwSetCursorPosCallback(m_window, glfw_cursor_pos_callback); - s_GLFWWindowCount++; + s_glfw_window_count++; } - void Window::Shutdown() + auto Window::shutdown() -> void { - DONUT_INFO("Shutting down window: ", m_Title); - - ShutdownImGui(); - - glfwDestroyWindow(m_Window); - s_GLFWWindowCount--; + DONUT_INFO("Shutting down window: ", m_title); + + shutdown_im_gui(); + + glfwDestroyWindow(m_window); + s_glfw_window_count--; - if (s_GLFWWindowCount == 0) + if (s_glfw_window_count == 0) { glfwTerminate(); - s_GLFWInitialized = false; + s_glfw_initialized = false; DONUT_INFO("GLFW terminated (no more windows)"); } } - void Window::OnUpdate() const + auto Window::on_update() const -> void { glfwPollEvents(); - if (RendererAPI::GetAPI() != RendererAPI::API::Vulkan) - glfwSwapBuffers(m_Window); // Vulkan presents via the swapchain instead + if (RendererAPI::get_api() != RendererAPI::API::Vulkan) + glfwSwapBuffers(m_window); // Vulkan presents via the swapchain instead } - bool Window::ShouldClose() const + auto Window::should_close() const -> bool { - return glfwWindowShouldClose(m_Window) || m_IsClosed; + return glfwWindowShouldClose(m_window) || m_is_closed; } - void Window::SetCursorLocked(bool locked) + auto Window::set_cursor_locked(bool locked) -> void { - m_CursorLocked = locked; - glfwSetInputMode(m_Window, GLFW_CURSOR, locked ? + m_cursor_locked = locked; + glfwSetInputMode(m_window, GLFW_CURSOR, locked ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL); } - void Window::SetCursorVisible(bool visible) + auto Window::set_cursor_visible(bool visible) -> void { - m_CursorVisible = visible; - glfwSetInputMode(m_Window, GLFW_CURSOR, visible ? + m_cursor_visible = visible; + glfwSetInputMode(m_window, GLFW_CURSOR, visible ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN); } - void Window::InitImGui() + auto Window::init_im_gui() -> void { IMGUI_CHECKVERSION(); ImGui::CreateContext(); @@ -148,8 +148,8 @@ namespace Donut io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; #endif - SetupImGuiFonts(); - ThemeManager::SetTheme(Theme::Dark); + setup_im_gui_fonts(); + ThemeManager::set_theme(Theme::Dark); ImGuiStyle& style = ImGui::GetStyle(); if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) @@ -158,7 +158,7 @@ namespace Donut style.Colors[ImGuiCol_WindowBg].w = 1.0f; } - ImGui_ImplGlfw_InitForOpenGL(m_Window, true); + ImGui_ImplGlfw_InitForOpenGL(m_window, true); #ifdef __APPLE__ // macOS uses a core-profile context, which rejects the legacy // "#version 130" GLSL the ImGui backend defaults to. 150 is the @@ -167,53 +167,53 @@ namespace Donut #else ImGui_ImplOpenGL3_Init("#version 130"); #endif - + DONUT_INFO("ImGUI initialized successfully"); } - void Window::SetupImGuiFonts() + auto Window::setup_im_gui_fonts() -> void { ImGuiIO& io = ImGui::GetIO(); io.Fonts->Clear(); - - m_MainFont = io.Fonts->AddFontFromFileTTF("Assets/Fonts/Inter/static/Inter_18pt-Regular.ttf", 16.0f); - if (!m_MainFont) + + m_main_font = io.Fonts->AddFontFromFileTTF("assets/fonts/inter/static/Inter_18pt-Regular.ttf", 16.0f); + if (!m_main_font) { DONUT_WARN("Failed to load Inter font, falling back to default"); - m_MainFont = io.Fonts->AddFontDefault(); + m_main_font = io.Fonts->AddFontDefault(); } else DONUT_INFO("Successfully loaded Inter font"); - - m_LargeFont = io.Fonts->AddFontFromFileTTF("Assets/Fonts/Inter/static/Inter_18pt-Bold.ttf", 20.0f); - if (!m_LargeFont) - m_LargeFont = m_MainFont; - - m_SmallFont = io.Fonts->AddFontFromFileTTF("Assets/Fonts/Inter/static/Inter_18pt-Light.ttf", 12.0f); - if (!m_SmallFont) - m_SmallFont = m_MainFont; - - io.FontDefault = m_MainFont; + + m_large_font = io.Fonts->AddFontFromFileTTF("assets/fonts/inter/static/Inter_18pt-Bold.ttf", 20.0f); + if (!m_large_font) + m_large_font = m_main_font; + + m_small_font = io.Fonts->AddFontFromFileTTF("assets/fonts/inter/static/Inter_18pt-Light.ttf", 12.0f); + if (!m_small_font) + m_small_font = m_main_font; + + io.FontDefault = m_main_font; DONUT_INFO("ImGUI fonts loaded successfully"); } - void Window::ShutdownImGui() + auto Window::shutdown_im_gui() -> void { ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); - + DONUT_INFO("ImGUI shutdown"); } - void Window::BeginImGuiFrame() + auto Window::begin_im_gui_frame() -> void { ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); } - void Window::EndImGuiFrame() + auto Window::end_im_gui_frame() -> void { ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); @@ -228,114 +228,114 @@ namespace Donut } } - void Window::GLFWErrorCallback(int error, const char* description) + auto Window::glfw_error_callback(int error, const char* description) -> void { DONUT_ERROR("GLFW Error ({}): {}", error, description ? description : ""); } - void Window::GLFWWindowCloseCallback(GLFWwindow* window) + auto Window::glfw_window_close_callback(GLFWwindow* window) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); WindowCloseEvent event; - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } - void Window::GLFWWindowSizeCallback(GLFWwindow* window, int width, int height) + auto Window::glfw_window_size_callback(GLFWwindow* window, int width, int height) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); - win->m_Width = width; - win->m_Height = height; - + win->m_width = width; + win->m_height = height; + WindowResizeEvent event(width, height); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } - void Window::GLFWWindowFocusCallback(GLFWwindow* window, int focused) + auto Window::glfw_window_focus_callback(GLFWwindow* window, int focused) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); - + if (focused) { WindowFocusEvent event; - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } else { WindowLostFocusEvent event; - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } } - void Window::GLFWWindowPosCallback(GLFWwindow* window, int xpos, int ypos) + auto Window::glfw_window_pos_callback(GLFWwindow* window, int xpos, int ypos) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); WindowMovedEvent event(xpos, ypos); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } - void Window::GLFWKeyCallback(GLFWwindow* window, int key, int scancode, - int action, int mods) + auto Window::glfw_key_callback(GLFWwindow* window, int key, int scancode, + int action, int mods) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); - + switch (action) { case GLFW_PRESS: { KeyPressedEvent event(key, false); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } break; case GLFW_RELEASE: { KeyReleasedEvent event(key); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } break; case GLFW_REPEAT: { KeyPressedEvent event(key, true); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } break; } } - void Window::GLFWCharCallback(GLFWwindow* window, unsigned int keycode) + auto Window::glfw_char_callback(GLFWwindow* window, unsigned int keycode) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); KeyTypedEvent event(keycode); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } - void Window::GLFWMouseButtonCallback(GLFWwindow* window, int button, - int action, int mods) + auto Window::glfw_mouse_button_callback(GLFWwindow* window, int button, + int action, int mods) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); - + switch (action) { case GLFW_PRESS: { MouseButtonPressedEvent event(button); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } break; case GLFW_RELEASE: { MouseButtonReleasedEvent event(button); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } break; } } - void Window::GLFWMouseScrollCallback(GLFWwindow* window, double xOffset, double yOffset) + auto Window::glfw_mouse_scroll_callback(GLFWwindow* window, double x_offset, double y_offset) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); - MouseScrolledEvent event((float)xOffset, (float)yOffset); - win->m_EventHandler.OnEvent(event); + MouseScrolledEvent event((float)x_offset, (float)y_offset); + win->m_event_handler.on_event(event); } - void Window::GLFWCursorPosCallback(GLFWwindow* window, double xPos, double yPos) + auto Window::glfw_cursor_pos_callback(GLFWwindow* window, double x_pos, double y_pos) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); - MouseMovedEvent event((float)xPos, (float)yPos); - win->m_EventHandler.OnEvent(event); + MouseMovedEvent event((float)x_pos, (float)y_pos); + win->m_event_handler.on_event(event); } -}
\ No newline at end of file +} |
