Skip to content

Commit

Permalink
Netimgui: DPI Settings: transmit WindowDPISizeFactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Apr 12, 2024
1 parent c175b63 commit 21d1612
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
64 changes: 44 additions & 20 deletions src/hello_imgui/internal/backend_impls/abstract_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,32 +438,56 @@ void ReadDpiAwareParams(const std::string& appIniSettingLocation, DpiAwareParams
}


void _CheckDpiAwareParamsChanges(const std::string& msg)
void _LogDpiParams(const HelloImGui::DpiAwareParams& dpiAwareParams)
{
static bool isFirstTime = true;
auto& dpiAwareParams = HelloImGui::GetRunnerParams()->dpiAwareParams;
auto &io = ImGui::GetIO();
printf("dpiAwareParams: dpiWindowSizeFactor=%f\n", dpiAwareParams.dpiWindowSizeFactor);
printf("dpiAwareParams: fontRenderingScale=%f\n", dpiAwareParams.fontRenderingScale);
printf("dpiAwareParams: DpiFontLoadingFactor()=%f\n", dpiAwareParams.DpiFontLoadingFactor());
printf(" ImGui FontGlobalScale: %f\n", io.FontGlobalScale);
printf(" ImGui DisplayFramebufferScale=%f, %f\n", io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
}


void _CheckDpiAwareParamsChanges(HelloImGui::RunnerParams& params)
{
auto& dpiAwareParams = params.dpiAwareParams;
auto& io = ImGui::GetIO();

static bool isFirstTime = true;
if (isFirstTime)
{
isFirstTime = false;
printf("%s\n", msg.c_str());
printf("dpiAwareParams: dpiWindowSizeFactor=%f\n", dpiAwareParams.dpiWindowSizeFactor);
printf("dpiAwareParams: fontRenderingScale=%f\n", dpiAwareParams.fontRenderingScale);
printf(" ImGui FontGlobalScale: %f\n", ImGui::GetIO().FontGlobalScale);
printf("dpiAwareParams: DpiFontLoadingFactor()=%f\n", dpiAwareParams.DpiFontLoadingFactor());
printf("dpiAwareParams: io.DisplayFramebufferScale=%f, %f\n", io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
auto fbs = ImGui::GetIO().DisplayFramebufferScale;
printf(" ImGui DisplayFramebufferScale: %f,%f\n", fbs.x, fbs.y);
printf("-------------------------------------------------------------\n");
_LogDpiParams(dpiAwareParams);
isFirstTime = false;
}

bool didFontGlobalScaleChange = dpiAwareParams.fontRenderingScale != io.FontGlobalScale;

// Check changes
bool didFontGlobalScaleChange = dpiAwareParams.fontRenderingScale != io.FontGlobalScale;
if (didFontGlobalScaleChange)
{
printf("Warning: didDpiAwareParamsChange=:true\n");
{
printf("Warning: didFontGlobalScaleChange=:true\n");
dpiAwareParams.fontRenderingScale = io.FontGlobalScale;
}
}

bool didDpiWindowSizeFactorChange = false;
#ifdef HELLOIMGUI_WITH_NETIMGUI
if (params.remoteParams.enableRemoting)
{
float newWindowDPISizeFactor = NetImgui::GetWindowDPISizeFactor();
didDpiWindowSizeFactorChange = dpiAwareParams.dpiWindowSizeFactor != newWindowDPISizeFactor;
if (didDpiWindowSizeFactorChange)
{
printf("Warning: didDpiWindowSizeFactorChange=:true (from netImgui)\n");
dpiAwareParams.dpiWindowSizeFactor = newWindowDPISizeFactor;
}
}
#endif

if (didDpiWindowSizeFactorChange || didFontGlobalScaleChange)
{
printf("New DpiAwareParams:\n");
_LogDpiParams(dpiAwareParams);
}
}


Expand Down Expand Up @@ -519,7 +543,7 @@ void AbstractRunner::SetupDpiAwareParams()
}
ImGui::GetIO().FontGlobalScale = params.dpiAwareParams.fontRenderingScale;

_CheckDpiAwareParamsChanges("Setup End");
_CheckDpiAwareParamsChanges(params);
}


Expand Down Expand Up @@ -1219,7 +1243,7 @@ void AbstractRunner::CreateFramesAndRender()

mIdxFrame += 1;

_CheckDpiAwareParamsChanges("EndCreateFrameAndRenderer");
_CheckDpiAwareParamsChanges(params);
}

// Idling for non emscripten, where HelloImGui is responsible for the main loop.
Expand Down
2 changes: 1 addition & 1 deletion src/netimgui_remote_display/netimgui_remote_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main(int argc, char **argv)

runnerParams.callbacks.PostInit = [&pass_cmd_line_args_to_server]() {
pass_cmd_line_args_to_server();
NetImguiServer::UI::SetUseServerDisplayDpiSettings(true);
NetImguiServer::UI::SetUseServerDisplayDPISettings(true);
};

runnerParams.callbacks.PreNewFrame = []() {
Expand Down

0 comments on commit 21d1612

Please sign in to comment.