SpiecsEngine
 
Loading...
Searching...
No Matches

◆ GetDPIScale()

float Spices::ImGuiH::GetDPIScale ( )
staticprivate

Get GLFW DPI Scale.

Returns
If GLFW has been initializedreturns the DPI scale of the primary monitor. Otherwise, returns 1.

Definition at line 584 of file ImguiHelper.cpp.

585 {
587
588 // Cached DPI scale, so that this doesn't change after the first time code calls getDPIScale.
589 // A negative value indicates that the value hasn't been computed yet.
590 static float cached_dpi_scale = -1.0f;
591
592 if (cached_dpi_scale < 0.0f)
593 {
594 // Compute the product of the monitor DPI scale and any DPI scale
595 // set in the NVPRO_DPI_SCALE variable.
596 cached_dpi_scale = 1.0f;
597
598 GLFWmonitor* monitor = glfwGetPrimaryMonitor();
599 if (monitor != nullptr)
600 {
601 float y_scale;
602 glfwGetMonitorContentScale(monitor, &cached_dpi_scale, &y_scale);
603 }
604 // Otherwise, GLFW isn't initialized yet, but might be in the future.
605 // (Note that this code assumes all samples use GLFW.)
606
607 // Multiply by the value of the NVPRO_DPI_SCALE environment variable.
608 const char* dpi_env = getenv("NVPRO_DPI_SCALE");
609 if (dpi_env)
610 {
611 const float parsed_dpi_env = strtof(dpi_env, nullptr);
612 if (parsed_dpi_env != 0.0f)
613 {
614 cached_dpi_scale *= parsed_dpi_env;
615 }
616 }
617
618 cached_dpi_scale = (cached_dpi_scale > 0.0f ? cached_dpi_scale : 1.0f);
619 }
620
621 return cached_dpi_scale;
622 }
#define SPICES_PROFILE_ZONE

Referenced by SetFonts().