Skip to content

Commit

Permalink
Use a manual scaling factor argument instead of disabling scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
virokannas committed Nov 8, 2023
1 parent 9e9b324 commit 4e4148b
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions source/MaterialXGraphEditor/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const std::string options =
" --path [FILEPATH] Specify an additional data search path location (e.g. '/projects/MaterialX'). This absolute path will be queried when locating data libraries, XInclude references, and referenced images.\n"
" --library [FILEPATH] Specify an additional data library folder (e.g. 'vendorlib', 'studiolib'). This relative path will be appended to each location in the data search path when loading data libraries.\n"
" --captureFilename [FILENAME] Specify the filename to which the first rendered frame should be written\n"
" --disableScaling Disable automatic HiDPI scaling\n"
" --scaleFactor [FACTOR] Manually specify a HiDPI scaling factor\n"
" --help Display the complete list of command-line options\n";

template <class T> void parseToken(std::string token, std::string type, T& res)
Expand Down Expand Up @@ -66,7 +66,7 @@ int main(int argc, char* const argv[])
mx::FilePathVec libraryFolders;
int viewWidth = 256;
int viewHeight = 256;
bool disableScaling = false;
float scaleFactor = 0.0;
std::string captureFilename;

for (size_t i = 0; i < tokens.size(); i++)
Expand Down Expand Up @@ -102,9 +102,9 @@ int main(int argc, char* const argv[])
{
parseToken(nextToken, "string", captureFilename);
}
else if (token == "--disableScaling")
else if (token == "--scaleFactor")
{
disableScaling = true;
parseToken(nextToken, "float", scaleFactor);
}
else if (token == "--help")
{
Expand Down Expand Up @@ -199,17 +199,15 @@ int main(int argc, char* const argv[])
// Fonts are not handled, so a global font scale factor is set.
// There appears to be no multi-monitor solution so use the primary monitor
// for now.
if(!disableScaling) {
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
if (monitor)
{
float xscale = 1.0f, yscale = 1.0f;
glfwGetMonitorContentScale(monitor, &xscale, &yscale);
ImGuiStyle& style = ImGui::GetStyle();
float dpiScale = xscale > yscale ? xscale : yscale;
style.ScaleAllSizes(dpiScale);
graph->setFontScale(dpiScale);
}
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
if (monitor)
{
float xscale = 1.0f, yscale = 1.0f;
glfwGetMonitorContentScale(monitor, &xscale, &yscale);
ImGuiStyle& style = ImGui::GetStyle();
float dpiScale = scaleFactor == 0.0 ? (xscale > yscale ? xscale : yscale) : scaleFactor;
style.ScaleAllSizes(dpiScale);
graph->setFontScale(dpiScale);
}

// Create editor config and context.
Expand Down

0 comments on commit 4e4148b

Please sign in to comment.