From 23dd19b7a00db2615da3d5381599d3fecd947024 Mon Sep 17 00:00:00 2001 From: Bernard Kwok Date: Tue, 1 Oct 2024 10:56:37 -0400 Subject: [PATCH 1/3] Add command line option to choice font file. --- source/MaterialXGraphEditor/Main.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/source/MaterialXGraphEditor/Main.cpp b/source/MaterialXGraphEditor/Main.cpp index 38c755cdd9..b1071e6608 100644 --- a/source/MaterialXGraphEditor/Main.cpp +++ b/source/MaterialXGraphEditor/Main.cpp @@ -31,6 +31,7 @@ const std::string options = " --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" " --uiScale [FACTOR] Manually specify a UI scaling factor\n" " --captureFilename [FILENAME] Specify the filename to which the first rendered frame should be written\n" + " --font [FILE] Specify the name of the font file to use. If not specified the default font will be used\n" " --help Display the complete list of command-line options\n"; template void parseToken(std::string token, std::string type, T& res) @@ -68,6 +69,7 @@ int main(int argc, char* const argv[]) int viewHeight = 256; float uiScale = 0.0f; std::string captureFilename; + std::string fontFilename; for (size_t i = 0; i < tokens.size(); i++) { @@ -106,6 +108,10 @@ int main(int argc, char* const argv[]) { parseToken(nextToken, "string", captureFilename); } + else if (token == "--font") + { + parseToken(nextToken, "string", fontFilename); + } else if (token == "--help") { std::cout << " MaterialXGraphEditor version " << mx::getVersionString() << std::endl; @@ -172,7 +178,16 @@ int main(int argc, char* const argv[]) io.IniFilename = NULL; io.LogFilename = NULL; - io.Fonts->AddFontDefault(); + ImFont* customFont = nullptr; + float fontSize = 13.0f; // Font size used for AddFontDefault() + if (!fontFilename.empty()) + { + customFont = io.Fonts->AddFontFromFileTTF(fontFilename.c_str(), fontSize); + } + if (!customFont) + { + io.Fonts->AddFontDefault(); + } // Setup Dear ImGui style ImGui::StyleColorsDark(); @@ -239,6 +254,7 @@ int main(int argc, char* const argv[]) break; } + double xpos = 0.0; double ypos = 0.0; glfwGetCursorPos(window, &xpos, &ypos); @@ -246,6 +262,7 @@ int main(int argc, char* const argv[]) ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); glfwSwapBuffers(window); + } // Cleanup From 57f8f39eed6671a998b962b24c943ba3d7372fbe Mon Sep 17 00:00:00 2001 From: Bernard Kwok Date: Tue, 1 Oct 2024 13:25:33 -0400 Subject: [PATCH 2/3] Add --fontSize and docs. --- documents/DeveloperGuide/GraphEditor.md | 2 ++ source/MaterialXGraphEditor/Main.cpp | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/documents/DeveloperGuide/GraphEditor.md b/documents/DeveloperGuide/GraphEditor.md index 394754c309..ca6f8ef5a3 100644 --- a/documents/DeveloperGuide/GraphEditor.md +++ b/documents/DeveloperGuide/GraphEditor.md @@ -75,6 +75,8 @@ The following are common command-line options for MaterialXGraphEditor, and a co - `--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. - `--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. - `--captureFilename [FILENAME]` : Specify the filename to which the first rendered frame should be written +- `--font [FILE]` : Specify the name of the custom font file to use. If not specified the default font will be used" +- `--fontSize [SIZE]` : Specify font size to use for the custom font. If not specified a default of 18 will be used" ## Known Limitations diff --git a/source/MaterialXGraphEditor/Main.cpp b/source/MaterialXGraphEditor/Main.cpp index b1071e6608..098f6db89f 100644 --- a/source/MaterialXGraphEditor/Main.cpp +++ b/source/MaterialXGraphEditor/Main.cpp @@ -31,7 +31,8 @@ const std::string options = " --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" " --uiScale [FACTOR] Manually specify a UI scaling factor\n" " --captureFilename [FILENAME] Specify the filename to which the first rendered frame should be written\n" - " --font [FILE] Specify the name of the font file to use. If not specified the default font will be used\n" + " --font [FILE] Specify the name of the custom font file to use. If not specified the default font will be used\n" + " --fontSize [SIZE] Specify font size to use for the custom font. If not specified a default of 18 will be used\n" " --help Display the complete list of command-line options\n"; template void parseToken(std::string token, std::string type, T& res) @@ -70,6 +71,7 @@ int main(int argc, char* const argv[]) float uiScale = 0.0f; std::string captureFilename; std::string fontFilename; + int fontSize = 18; for (size_t i = 0; i < tokens.size(); i++) { @@ -112,6 +114,14 @@ int main(int argc, char* const argv[]) { parseToken(nextToken, "string", fontFilename); } + else if (token == "--fontSize") + { + parseToken(nextToken, "integer", fontSize); + if (fontSize < 12) + { + fontSize = 12; + } + } else if (token == "--help") { std::cout << " MaterialXGraphEditor version " << mx::getVersionString() << std::endl; @@ -179,7 +189,6 @@ int main(int argc, char* const argv[]) io.LogFilename = NULL; ImFont* customFont = nullptr; - float fontSize = 13.0f; // Font size used for AddFontDefault() if (!fontFilename.empty()) { customFont = io.Fonts->AddFontFromFileTTF(fontFilename.c_str(), fontSize); From 7333501bf19618c72fb861d57cc49b0350c81d1f Mon Sep 17 00:00:00 2001 From: Bernard Kwok Date: Tue, 1 Oct 2024 13:37:13 -0400 Subject: [PATCH 3/3] Cleanup. --- source/MaterialXGraphEditor/Main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/MaterialXGraphEditor/Main.cpp b/source/MaterialXGraphEditor/Main.cpp index 098f6db89f..a8cec09fee 100644 --- a/source/MaterialXGraphEditor/Main.cpp +++ b/source/MaterialXGraphEditor/Main.cpp @@ -263,7 +263,6 @@ int main(int argc, char* const argv[]) break; } - double xpos = 0.0; double ypos = 0.0; glfwGetCursorPos(window, &xpos, &ypos); @@ -271,7 +270,6 @@ int main(int argc, char* const argv[]) ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); glfwSwapBuffers(window); - } // Cleanup