diff --git a/.gitmodules b/.gitmodules index b7806391f3..042543cce2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -23,3 +23,7 @@ [submodule "dependencies/runtime/src"] path = dependencies/runtime/src url = https://gitea.thebrokenrail.com/minecraft-pi-reborn/runtime.git +[submodule "dependencies/imgui/src"] + path = dependencies/imgui/src + url = https://github.com/ocornut/imgui.git + ignore = dirty diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt index e17bf157c0..6fa9e838e1 100644 --- a/dependencies/CMakeLists.txt +++ b/dependencies/CMakeLists.txt @@ -19,12 +19,16 @@ endif() # Extra Runtime add_subdirectory(runtime) # GLFW -if(BUILD_MEDIA_LAYER_CORE) +if(BUILD_NATIVE_COMPONENTS OR BUILD_MEDIA_LAYER_CORE) add_subdirectory(glfw) endif() +# ImGui +if(BUILD_NATIVE_COMPONENTS) + add_subdirectory(imgui) +endif() # UTF8-CPP add_subdirectory(utf8cpp) -# Symbol Prcoessor +# Symbol Processor if(BUILD_ARM_COMPONENTS) add_subdirectory(symbol-processor) endif() diff --git a/dependencies/glfw/CMakeLists.txt b/dependencies/glfw/CMakeLists.txt index 74941f5f62..8addea7de0 100644 --- a/dependencies/glfw/CMakeLists.txt +++ b/dependencies/glfw/CMakeLists.txt @@ -24,4 +24,4 @@ unset(MESSAGE_QUIET) setup_library(glfw TRUE FALSE) # License -install(FILES src/LICENSE.md DESTINATION "${MCPI_LEGAL_DIR}/glfw") +install(FILES src/LICENSE.md DESTINATION "${MCPI_LEGAL_DIR}/GLFW") diff --git a/dependencies/imgui/CMakeLists.txt b/dependencies/imgui/CMakeLists.txt new file mode 100644 index 0000000000..2a785c5aa4 --- /dev/null +++ b/dependencies/imgui/CMakeLists.txt @@ -0,0 +1,41 @@ +project(imgui) + +# Silence Warnings +add_compile_options(-w) + +## ImGui + +# Build +add_library(imgui SHARED + src/imgui.cpp + src/imgui_draw.cpp + src/imgui_tables.cpp + src/imgui_widgets.cpp + src/backends/imgui_impl_glfw.cpp + src/backends/imgui_impl_opengl2.cpp +) +setup_header_dirs(imgui + "${CMAKE_CURRENT_SOURCE_DIR}/src" + "${CMAKE_CURRENT_SOURCE_DIR}/src/backends" +) +find_package(OpenGL REQUIRED) +target_link_libraries(imgui PUBLIC glfw OpenGL::GL) + +# Patch +function(run_patch) + execute_process( + COMMAND "patch" "-p1" "--quiet" ${ARGN} + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" + INPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/fix-hidpi.patch" + COMMAND_ERROR_IS_FATAL ANY + ) +endfunction() +# https://stackoverflow.com/a/79041978 +run_patch("--batch" "--reverse") +run_patch() + +# Install +setup_library(imgui TRUE TRUE) + +# License +install(FILES src/LICENSE.txt DESTINATION "${MCPI_LEGAL_DIR}/ImGui") diff --git a/dependencies/imgui/fix-hidpi.patch b/dependencies/imgui/fix-hidpi.patch new file mode 100644 index 0000000000..af8a9f4b76 --- /dev/null +++ b/dependencies/imgui/fix-hidpi.patch @@ -0,0 +1,55 @@ +--- a/backends/imgui_impl_glfw.cpp ++++ b/backends/imgui_impl_glfw.cpp +@@ -422,6 +422,21 @@ void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused) + io.AddFocusEvent(focused != 0); + } + ++static void ImGui_ImplGlfw_ScaleMousePos(GLFWwindow* window, double &x, double &y) { ++ // Get Window Size ++ int window_width, window_height; ++ glfwGetWindowSize(window, &window_width, &window_height); ++ if (window_width <= 0 || window_height <= 0) { ++ return; ++ } ++ // Get Framebuffer Size ++ int framebuffer_width, framebuffer_height; ++ glfwGetFramebufferSize(window, &framebuffer_width, &framebuffer_height); ++ // Multiply ++ x *= double(framebuffer_width) / double(window_width); ++ y *= double(framebuffer_height) / double(window_height); ++} ++ + void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y) + { + ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); +@@ -429,6 +444,7 @@ void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y) + bd->PrevUserCallbackCursorPos(window, x, y); + + ImGuiIO& io = ImGui::GetIO(); ++ ImGui_ImplGlfw_ScaleMousePos(window, x, y); + io.AddMousePosEvent((float)x, (float)y); + bd->LastValidMousePos = ImVec2((float)x, (float)y); + } +@@ -738,6 +754,7 @@ static void ImGui_ImplGlfw_UpdateMouseData() + { + double mouse_x, mouse_y; + glfwGetCursorPos(window, &mouse_x, &mouse_y); ++ ImGui_ImplGlfw_ScaleMousePos(window, mouse_x, mouse_y); + bd->LastValidMousePos = ImVec2((float)mouse_x, (float)mouse_y); + io.AddMousePosEvent((float)mouse_x, (float)mouse_y); + } +@@ -831,13 +848,9 @@ void ImGui_ImplGlfw_NewFrame() + IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplGlfw_InitForXXX()?"); + + // Setup display size (every frame to accommodate for window resizing) +- int w, h; + int display_w, display_h; +- glfwGetWindowSize(bd->Window, &w, &h); + glfwGetFramebufferSize(bd->Window, &display_w, &display_h); +- io.DisplaySize = ImVec2((float)w, (float)h); +- if (w > 0 && h > 0) +- io.DisplayFramebufferScale = ImVec2((float)display_w / (float)w, (float)display_h / (float)h); ++ io.DisplaySize = ImVec2((float)display_w, (float)display_h); + + // Setup time step + // (Accept glfwGetTime() not returning a monotonically increasing value. Seems to happens on disconnecting peripherals and probably on VMs and Emscripten, see #6491, #6189, #6114, #3644) diff --git a/dependencies/imgui/src b/dependencies/imgui/src new file mode 160000 index 0000000000..eb0ad66d88 --- /dev/null +++ b/dependencies/imgui/src @@ -0,0 +1 @@ +Subproject commit eb0ad66d88d96be3ccad31e22ef9d3126ec79ef2 diff --git a/dependencies/runtime/CMakeLists.txt b/dependencies/runtime/CMakeLists.txt index db358fdf99..694a5257be 100644 --- a/dependencies/runtime/CMakeLists.txt +++ b/dependencies/runtime/CMakeLists.txt @@ -10,4 +10,10 @@ if(NOT BUILD_NATIVE_COMPONENTS) endif() # Build -add_subdirectory(src) \ No newline at end of file +add_subdirectory(src) + +# RPath +if(TARGET runtime) + set_target_properties(runtime PROPERTIES INSTALL_RPATH "$ORIGIN/../lib/native") + target_link_options(runtime PRIVATE "LINKER:--disable-new-dtags") +endif() \ No newline at end of file diff --git a/dependencies/runtime/src b/dependencies/runtime/src index b42021ba5d..043d926f32 160000 --- a/dependencies/runtime/src +++ b/dependencies/runtime/src @@ -1 +1 @@ -Subproject commit b42021ba5d45c29e22cbdd887e2fae5a1c1334a1 +Subproject commit 043d926f32a3315d92bce1d9bbb0ccdcf99c11a2 diff --git a/dependencies/utf8cpp/CMakeLists.txt b/dependencies/utf8cpp/CMakeLists.txt index 8a62c7d297..b9aef19bb2 100644 --- a/dependencies/utf8cpp/CMakeLists.txt +++ b/dependencies/utf8cpp/CMakeLists.txt @@ -9,4 +9,4 @@ add_compile_options(-w) add_subdirectory(src EXCLUDE_FROM_ALL) # License -install(FILES src/LICENSE DESTINATION "${MCPI_LEGAL_DIR}/utf8cpp") +install(FILES src/LICENSE DESTINATION "${MCPI_LEGAL_DIR}/UTF8-CPP")