Build ImGui

This commit is contained in:
TheBrokenRail 2024-11-19 22:48:50 -05:00
parent 386f52a85f
commit 2785e3f138
9 changed files with 117 additions and 6 deletions

4
.gitmodules vendored
View File

@ -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

View File

@ -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()

View File

@ -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")

41
dependencies/imgui/CMakeLists.txt vendored Normal file
View File

@ -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")

55
dependencies/imgui/fix-hidpi.patch vendored Normal file
View File

@ -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)

1
dependencies/imgui/src vendored Submodule

@ -0,0 +1 @@
Subproject commit eb0ad66d88d96be3ccad31e22ef9d3126ec79ef2

View File

@ -11,3 +11,9 @@ endif()
# Build
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()

@ -1 +1 @@
Subproject commit b42021ba5d45c29e22cbdd887e2fae5a1c1334a1
Subproject commit 043d926f32a3315d92bce1d9bbb0ccdcf99c11a2

View File

@ -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")