From faa103850d3477d46ab4956a7c5bf01500188920 Mon Sep 17 00:00:00 2001 From: Brotcrunsher Date: Fri, 24 Nov 2023 09:27:56 +0100 Subject: [PATCH] Wrapped some glfw calls. --- .gitignore | 1 + BrotBoxEngine/BBE/glfwWrapper.h | 6 +++++ BrotBoxEngine/Window.cpp | 30 ++++++++++----------- BrotBoxEngine/glfwWrapper.cpp | 46 +++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index a4c55682..bd234525 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ [Bb]uildEmscripten/ [Bb]uildPortaudio/ [Bb]uildLinuxNull/ +[Bb]uildVulkan/ bld/ [Bb]in/ [Oo]bj/ diff --git a/BrotBoxEngine/BBE/glfwWrapper.h b/BrotBoxEngine/BBE/glfwWrapper.h index 9680ed63..344d2d22 100644 --- a/BrotBoxEngine/BBE/glfwWrapper.h +++ b/BrotBoxEngine/BBE/glfwWrapper.h @@ -32,5 +32,11 @@ namespace bbe void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos); const char* glfwGetClipboardString(GLFWwindow* handle); void glfwSetClipboardString(GLFWwindow* handle, const char* string); + void glfwSetWindowShouldClose(GLFWwindow* window, int value); + void glfwShowWindow(GLFWwindow* window); + void glfwHideWindow(GLFWwindow* window); + int glfwGetWindowAttrib(GLFWwindow* window, int attrib); + void glfwSetWindowUserPointer(GLFWwindow* window, void* pointer); + void* glfwGetWindowUserPointer(GLFWwindow* window); } } diff --git a/BrotBoxEngine/Window.cpp b/BrotBoxEngine/Window.cpp index f7469605..2a2da242 100644 --- a/BrotBoxEngine/Window.cpp +++ b/BrotBoxEngine/Window.cpp @@ -69,7 +69,7 @@ bbe::Window::Window(int width, int height, const char * title, uint32_t major, u #endif m_pwindow = glfwWrapper::glfwCreateWindow(width, height, title, nullptr, nullptr); - glfwSetWindowUserPointer(m_pwindow, this); + glfwWrapper::glfwSetWindowUserPointer(m_pwindow, this); if (m_pwindow == nullptr) { bbe::INTERNAL::triggerFatalError("Could not create window!"); @@ -239,17 +239,17 @@ bbe::WindowCloseMode bbe::Window::getWindowCloseMode() const void bbe::Window::showWindow() { - glfwShowWindow(m_pwindow); + glfwWrapper::glfwShowWindow(m_pwindow); } void bbe::Window::hideWindow() { - glfwHideWindow(m_pwindow); + glfwWrapper::glfwHideWindow(m_pwindow); } bool bbe::Window::isShown() const { - int visible = glfwGetWindowAttrib(m_pwindow, GLFW_VISIBLE); + int visible = glfwWrapper::glfwGetWindowAttrib(m_pwindow, GLFW_VISIBLE); return visible; } @@ -287,7 +287,7 @@ void bbe::Window::setVideoRenderingMode(const char* path) void bbe::Window::close() { - glfwSetWindowShouldClose(m_pwindow, GLFW_TRUE); + glfwWrapper::glfwSetWindowShouldClose(m_pwindow, GLFW_TRUE); } void bbe::Window::registerCloseListener(const std::function& listener) @@ -336,11 +336,11 @@ void bbe::INTERNAL_keyCallback(GLFWwindow * window, int keyCode, int scanCode, i if (ImGui::GetIO().WantCaptureKeyboard) return; if (action == GLFW_PRESS) { - ((bbe::Window*)glfwGetWindowUserPointer(window))->INTERNAL_keyboard.INTERNAL_press((bbe::Key)keyCode); + ((bbe::Window*)glfwWrapper::glfwGetWindowUserPointer(window))->INTERNAL_keyboard.INTERNAL_press((bbe::Key)keyCode); } else if (action == GLFW_RELEASE) { - ((bbe::Window*)glfwGetWindowUserPointer(window))->INTERNAL_keyboard.INTERNAL_release((bbe::Key)keyCode); + ((bbe::Window*)glfwWrapper::glfwGetWindowUserPointer(window))->INTERNAL_keyboard.INTERNAL_release((bbe::Key)keyCode); } #endif } @@ -360,12 +360,12 @@ void bbe::INTERNAL_cursorPosCallback(GLFWwindow * window, double xpos, double yp float windowXScale = 0; float windowYScale = 0; glfwWrapper::glfwGetWindowContentScale(window, &windowXScale, &windowYScale); - ((bbe::Window*)glfwGetWindowUserPointer(window))->INTERNAL_mouse.INTERNAL_moveMouse((float)(xpos / windowXScale), (float)(ypos / windowYScale)); + ((bbe::Window*)glfwWrapper::glfwGetWindowUserPointer(window))->INTERNAL_mouse.INTERNAL_moveMouse((float)(xpos / windowXScale), (float)(ypos / windowYScale)); } void bbe::INTERNAL_windowResizeCallback(GLFWwindow * window, int width, int height) { - ((bbe::Window*)glfwGetWindowUserPointer(window))->INTERNAL_resize(width, height); + ((bbe::Window*)glfwWrapper::glfwGetWindowUserPointer(window))->INTERNAL_resize(width, height); } void bbe::INTERNAL_mouseButtonCallback(GLFWwindow * window, int button, int action, int mods) @@ -377,11 +377,11 @@ void bbe::INTERNAL_mouseButtonCallback(GLFWwindow * window, int button, int acti if (action == GLFW_PRESS) { - ((bbe::Window*)glfwGetWindowUserPointer(window))->INTERNAL_mouse.INTERNAL_press((bbe::MouseButton)button); + ((bbe::Window*)glfwWrapper::glfwGetWindowUserPointer(window))->INTERNAL_mouse.INTERNAL_press((bbe::MouseButton)button); } else if (action == GLFW_RELEASE) { - ((bbe::Window*)glfwGetWindowUserPointer(window))->INTERNAL_mouse.INTERNAL_release((bbe::MouseButton)button); + ((bbe::Window*)glfwWrapper::glfwGetWindowUserPointer(window))->INTERNAL_mouse.INTERNAL_release((bbe::MouseButton)button); } } @@ -391,19 +391,19 @@ void bbe::INTERNAL_mouseScrollCallback(GLFWwindow * window, double xoffset, doub ImGui_ImplGlfw_ScrollCallback(window, xoffset, yoffset); if (ImGui::GetIO().WantCaptureMouse) return; #endif - ((bbe::Window*)glfwGetWindowUserPointer(window))->INTERNAL_mouse.INTERNAL_scroll(static_cast(xoffset), static_cast(yoffset)); + ((bbe::Window*)glfwWrapper::glfwGetWindowUserPointer(window))->INTERNAL_mouse.INTERNAL_scroll(static_cast(xoffset), static_cast(yoffset)); } void bbe::INTERNAL_windowCloseCallback(GLFWwindow* window) { - switch (((bbe::Window*)glfwGetWindowUserPointer(window))->getWindowCloseMode()) + switch (((bbe::Window*)glfwWrapper::glfwGetWindowUserPointer(window))->getWindowCloseMode()) { case bbe::WindowCloseMode::CLOSE: // Do nothing break; case bbe::WindowCloseMode::HIDE: - glfwSetWindowShouldClose(window, GLFW_FALSE); - glfwHideWindow(window); + glfwWrapper::glfwSetWindowShouldClose(window, GLFW_FALSE); + glfwWrapper::glfwHideWindow(window); break; default: throw bbe::IllegalStateException(); diff --git a/BrotBoxEngine/glfwWrapper.cpp b/BrotBoxEngine/glfwWrapper.cpp index 4b4abee3..fab3cecf 100644 --- a/BrotBoxEngine/glfwWrapper.cpp +++ b/BrotBoxEngine/glfwWrapper.cpp @@ -175,3 +175,49 @@ void bbe::glfwWrapper::glfwSetClipboardString(GLFWwindow* handle, const char* st ::glfwSetClipboardString(handle, string); #endif } + +void bbe::glfwWrapper::glfwSetWindowShouldClose(GLFWwindow* window, int value) +{ +#ifndef BBE_RENDERER_NULL + ::glfwSetWindowShouldClose(window, value); +#endif +} + +void bbe::glfwWrapper::glfwShowWindow(GLFWwindow* window) +{ +#ifndef BBE_RENDERER_NULL + ::glfwShowWindow(window); +#endif +} + +void bbe::glfwWrapper::glfwHideWindow(GLFWwindow* window) +{ +#ifndef BBE_RENDERER_NULL + ::glfwHideWindow(window); +#endif +} + +int bbe::glfwWrapper::glfwGetWindowAttrib(GLFWwindow* window, int attrib) +{ +#ifndef BBE_RENDERER_NULL + return ::glfwGetWindowAttrib(window, attrib); +#else + return 0; +#endif +} + +void bbe::glfwWrapper::glfwSetWindowUserPointer(GLFWwindow* window, void* pointer) +{ +#ifndef BBE_RENDERER_NULL + return ::glfwSetWindowUserPointer(window, pointer); +#endif +} + +void* bbe::glfwWrapper::glfwGetWindowUserPointer(GLFWwindow* window) +{ +#ifndef BBE_RENDERER_NULL + return ::glfwGetWindowUserPointer(window); +#else + return nullptr; +#endif +}