Skip to content

Commit

Permalink
Add command line option to choice font file.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwokcb committed Oct 1, 2024
1 parent 923ffd9 commit 23dd19b
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion source/MaterialXGraphEditor/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T> void parseToken(std::string token, std::string type, T& res)
Expand Down Expand Up @@ -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++)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -239,13 +254,15 @@ int main(int argc, char* const argv[])
break;
}


double xpos = 0.0;
double ypos = 0.0;
glfwGetCursorPos(window, &xpos, &ypos);
graph->drawGraph(ImVec2((float) xpos, (float) ypos));
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);

}

// Cleanup
Expand Down

0 comments on commit 23dd19b

Please sign in to comment.