From 2fb2b4409dc928778e223d5f43e3b33cf1d76d66 Mon Sep 17 00:00:00 2001 From: Pascal Thomet Date: Thu, 18 Apr 2024 23:45:18 +0200 Subject: [PATCH] Add HELLOIMGUI_WITH_REMOTE_DISPLAY --- external/.gitignore | 1 + hello_imgui_cmake/hello_imgui_build_lib.cmake | 2 ++ src/hello_imgui/impl/hello_imgui.cpp | 2 ++ .../internal/backend_impls/abstract_runner.cpp | 12 ++++++++---- .../internal/backend_impls/runner_factory.cpp | 2 ++ src/hello_imgui/remote_params.h | 3 +-- src/hello_imgui/runner_params.h | 5 +++-- 7 files changed, 19 insertions(+), 8 deletions(-) diff --git a/external/.gitignore b/external/.gitignore index 972ae40c..28f855dd 100644 --- a/external/.gitignore +++ b/external/.gitignore @@ -2,3 +2,4 @@ SDL SDL2-*/ qtimgui/ netImgui/ +imgui-ws/ diff --git a/hello_imgui_cmake/hello_imgui_build_lib.cmake b/hello_imgui_cmake/hello_imgui_build_lib.cmake index 3b5295fb..4ea07184 100644 --- a/hello_imgui_cmake/hello_imgui_build_lib.cmake +++ b/hello_imgui_cmake/hello_imgui_build_lib.cmake @@ -1036,6 +1036,7 @@ endfunction() ################################################################################################### function(him_with_netimgui) target_compile_definitions(${HELLOIMGUI_TARGET} PUBLIC HELLOIMGUI_WITH_NETIMGUI) + target_compile_definitions(${HELLOIMGUI_TARGET} PUBLIC HELLOIMGUI_WITH_REMOTE_DISPLAY) # message(STATUS "HelloImGui: downloading and building netImgui") # include(FetchContent) @@ -1070,6 +1071,7 @@ endfunction() ################################################################################################### function(him_with_imguiws) target_compile_definitions(${HELLOIMGUI_TARGET} PUBLIC HELLOIMGUI_WITH_IMGUIWS) + target_compile_definitions(${HELLOIMGUI_TARGET} PUBLIC HELLOIMGUI_WITH_REMOTE_DISPLAY) # Add imgui-ws to the project set(IMGUIWS_DIR ${HELLOIMGUI_BASEPATH}/external/imgui-ws CACHE STRING "" FORCE) diff --git a/src/hello_imgui/impl/hello_imgui.cpp b/src/hello_imgui/impl/hello_imgui.cpp index 11164b6c..f02002cd 100644 --- a/src/hello_imgui/impl/hello_imgui.cpp +++ b/src/hello_imgui/impl/hello_imgui.cpp @@ -224,8 +224,10 @@ std::string RendererBackendTypeToString(RendererBackendType rendererBackendType) std::string GetBackendDescription() { const auto& params = GetRunnerParams(); + #ifdef HELLOIMGUI_WITH_REMOTE_DISPLAY if (params->remoteParams.enableRemoting) return "Remote"; + #endif std::string platformBackend = PlatformBackendTypeToString(params->platformBackendType); std::string rendererBackend = RendererBackendTypeToString(params->rendererBackendType); return platformBackend + " - " + rendererBackend; diff --git a/src/hello_imgui/internal/backend_impls/abstract_runner.cpp b/src/hello_imgui/internal/backend_impls/abstract_runner.cpp index 86d23cfd..81e46243 100644 --- a/src/hello_imgui/internal/backend_impls/abstract_runner.cpp +++ b/src/hello_imgui/internal/backend_impls/abstract_runner.cpp @@ -360,6 +360,11 @@ float _DefaultOsFontRenderingScale() fontSizeIncreaseFactor = (float) NSScreen.mainScreen.backingScaleFactor; #endif + #ifdef HELLOIMGUI_WITH_REMOTE_DISPLAY + if (HelloImGui::GetRunnerParams()->remoteParams.enableRemoting) + fontSizeIncreaseFactor = 1.f; + #endif + return 1.0f / fontSizeIncreaseFactor; } @@ -381,10 +386,7 @@ void AbstractRunner::SetupDpiAwareParams() if (params.dpiAwareParams.fontRenderingScale == 0.f) { - if (params.remoteParams.enableRemoting) - params.dpiAwareParams.fontRenderingScale = 1.f; - else - params.dpiAwareParams.fontRenderingScale = _DefaultOsFontRenderingScale(); + params.dpiAwareParams.fontRenderingScale = _DefaultOsFontRenderingScale(); } ImGui::GetIO().FontGlobalScale = params.dpiAwareParams.fontRenderingScale; @@ -965,11 +967,13 @@ void AbstractRunner::CreateFramesAndRender() } // Transmit window size to remote server (if needed) + #ifdef HELLOIMGUI_WITH_REMOTE_DISPLAY if ((mIdxFrame > 3) && params.remoteParams.transmitWindowSize) { auto windowSize = params.appWindowParams.windowGeometry.size; mRemoteDisplayHandler.TransmitWindowSizeToDisplay(windowSize); } + #endif } // SCOPED_RELEASE_GIL_ON_MAIN_THREAD end if(foldable_region) // Handle idling diff --git a/src/hello_imgui/internal/backend_impls/runner_factory.cpp b/src/hello_imgui/internal/backend_impls/runner_factory.cpp index b80c52fa..24b915dd 100644 --- a/src/hello_imgui/internal/backend_impls/runner_factory.cpp +++ b/src/hello_imgui/internal/backend_impls/runner_factory.cpp @@ -41,11 +41,13 @@ void ChooseBackendTypesIfSelectedAsFirstAvailable(RunnerParams* runnerParams) void ChooseNullBackendsIfUsingRemote(RunnerParams* runnerParams) { + #ifdef HELLOIMGUI_WITH_REMOTE_DISPLAY if (runnerParams->remoteParams.enableRemoting) { runnerParams->platformBackendType = PlatformBackendType::Null; runnerParams->rendererBackendType = RendererBackendType::Null; } + #endif } diff --git a/src/hello_imgui/remote_params.h b/src/hello_imgui/remote_params.h index 59077136..f37e9ffd 100644 --- a/src/hello_imgui/remote_params.h +++ b/src/hello_imgui/remote_params.h @@ -10,8 +10,7 @@ namespace HelloImGui // RemoteParams is a struct that contains the settings for displaying the application on a remote device. // using https://github.com/sammyfreg/netImgui // or using https://github.com/ggerganov/imgui-ws -// Those feature are experimental and not supported with the standard version of HelloImGui. -// (they require specific versions of netImgui and imgui-ws, and will not compile with their standard versions) +// Those features are experimental and not supported with the standard version of HelloImGui, struct RemoteParams { bool enableRemoting = false; diff --git a/src/hello_imgui/runner_params.h b/src/hello_imgui/runner_params.h index 37a4d9ea..91a33c67 100644 --- a/src/hello_imgui/runner_params.h +++ b/src/hello_imgui/runner_params.h @@ -260,8 +260,9 @@ struct RunnerParams // (only used on emscripten: 0 stands for "let the app or the browser decide") int emscripten_fps = 0; - // Parameters for Remote display (experimental, unsupported) - RemoteParams remoteParams; + #ifdef HELLOIMGUI_WITH_REMOTE_DISPLAY + RemoteParams remoteParams; // Parameters for Remote display (experimental, unsupported) + #endif }; // @@md