Skip to content

Commit

Permalink
UI scale (#1880)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfedcafe authored Jan 6, 2025
1 parent 91310bd commit 1ec4c0c
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions application/F3DOptionsTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ static inline const std::array<CLIGroup, 8> CLIOptions = {{
{ "animation-speed-factor", "", "Set animation speed factor", "<factor>", "" },
{ "animation-time", "", "Set animation time to load", "<time>", "" },
{ "font-file", "", "Path to a FreeType compatible font file", "<file_path>", ""},
{ "font-scale", "", "Scale fonts", "<ratio>", ""},
{ "command-script", "", "Path to a script file containing commands to execute", "<file_path>", "" } } },
{ "Material",
{ {"point-sprites", "o", "Show sphere sprites instead of surfaces", "<bool>", "1" },
Expand Down
1 change: 1 addition & 0 deletions application/F3DOptionsTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static inline const std::map<std::string_view, std::string_view> LibOptionsNames
{ "animation-index", "scene.animation.index" },
{ "animation-speed-factor", "scene.animation.speed_factor" },
{ "font-file", "ui.font_file" },
{ "font-scale", "ui.scale" },
{ "point-sprites", "model.point_sprites.enable" },
{ "point-sprites-type", "model.point_sprites.type" },
{ "point-sprites-size", "model.point_sprites.size" },
Expand Down
2 changes: 2 additions & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ f3d_test(NAME TestLightIntensityDarkerFullScene DATA WaterBottle.glb ARGS --ligh
f3d_test(NAME TestUTF8 DATA "(ノಠ益ಠ )ノ.vtp")
f3d_test(NAME TestFilenameCommasSpaces DATA "tetrahedron, with commas & spaces.stl")
f3d_test(NAME TestFont DATA suzanne.ply ARGS -n --font-file=${F3D_SOURCE_DIR}/testing/data/Crosterian.ttf UI)
f3d_test(NAME TestFontScale2 DATA suzanne.ply ARGS -n --font-scale=2 UI)
f3d_test(NAME TestFontScale3 DATA suzanne.ply ARGS -n --font-scale=3 UI)
f3d_test(NAME TestAnimationIndex DATA InterpolationTest.glb ARGS --animation-index=7 --animation-time=0.5 --animation-progress)
f3d_test(NAME TestMultiFileAnimationIndex DATA InterpolationTest.glb BoxAnimated.gltf ARGS --animation-index=9 --animation-time=0.85 --animation-progress --multi-file-mode=all)
f3d_test(NAME TestMultiFileAnimationNoAnimationSupport DATA f3d.glb world.obj ARGS --multi-file-mode=all --animation-time=2 --animation-progress)
Expand Down
1 change: 1 addition & 0 deletions doc/libf3d/OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ ui.console|bool<br>false<br>render|Show the console
ui.filename|bool<br>false<br>render|Display the *filename info content* on top of the window.|\-\-filename
ui.filename_info|string<br>-<br>render|Content of *filename info* to display.
ui.font_file|string<br>optional<br>render|Use the provided FreeType compatible font file to display text.<br>Can be useful to display non-ASCII filenames.|\-\-font-file
ui.scale|ratio<br>1.0<br>render|Scale fonts.|\-\-font-scale
ui.fps|bool<br>false<br>render|Display a *frame per second counter*.|\-\-fps
ui.loader_progress|bool<br>false<br>load|Show a *progress bar* when loading the file.|\-\-progress
ui.animation_progress|bool<br>false<br>load|Show a *progress bar* when playing the animation.|\-\-animation-progress
Expand Down
1 change: 1 addition & 0 deletions doc/user/OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Options|Type<br>Default|Description
\-\-animation-speed-factor=\<factor\>|ratio<br>1|Set the animation speed factor to slow, speed up or even invert animation time.
\-\-animation-time=\<time\>|double<br>-|Set the animation time to load.
\-\-font-file=\<font file\>|string<br>-|Use the provided FreeType compatible font file to display text.<br>Can be useful to display non-ASCII filenames.
\-\-font-scale=\<scale\>|ratio<br>1.0|Scale fonts.
\-\-command-script=\<command script\>|script<br>-|Provide a script file containing a list of commands to be executed sequentially.<br>Allows automation of multiple commands or pre-defined tasks.

## Material options
Expand Down
4 changes: 4 additions & 0 deletions library/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@
"font_file": {
"type": "string"
},
"scale": {
"type": "ratio",
"default_value": "1.0"
},
"loader_progress": {
"type": "bool",
"default_value": "false"
Expand Down
1 change: 1 addition & 0 deletions library/src/window_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ void window_impl::UpdateDynamicOptions()
renderer->ShowHDRISkybox(opt.render.background.skybox);

renderer->SetFontFile(opt.ui.font_file);
renderer->SetFontScale(opt.ui.scale);

renderer->SetGridUnitSquare(opt.render.grid.unit);
renderer->SetGridSubdivisions(opt.render.grid.subdivisions);
Expand Down
3 changes: 3 additions & 0 deletions testing/baselines/TestFontScale2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestFontScale3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions vtkext/private/module/vtkF3DImguiActor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ void vtkF3DImguiActor::Initialize(vtkOpenGLRenderWindow* renWin)

io.Fonts->Build();
io.FontDefault = font;
io.FontGlobalScale = this->FontScale;

ImGuiStyle* style = &ImGui::GetStyle();
style->GrabRounding = 4.0f;
Expand Down
11 changes: 11 additions & 0 deletions vtkext/private/module/vtkF3DRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,8 @@ void vtkF3DRenderer::ConfigureTextActors()
}
}

this->UIActor->SetFontScale(this->FontScale);

this->TextActorsConfigured = true;
}

Expand Down Expand Up @@ -1129,6 +1131,15 @@ void vtkF3DRenderer::SetFontFile(const std::optional<std::string>& fontFile)
}
}

//----------------------------------------------------------------------------
void vtkF3DRenderer::SetFontScale(const double fontScale)
{
if (this->FontScale != fontScale)
{
this->FontScale = fontScale;
this->TextActorsConfigured = false;
}
}
//----------------------------------------------------------------------------
void vtkF3DRenderer::SetBackground(const double* color)
{
Expand Down
2 changes: 2 additions & 0 deletions vtkext/private/module/vtkF3DRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class vtkF3DRenderer : public vtkOpenGLRenderer
void SetLineWidth(const std::optional<double>& lineWidth);
void SetPointSize(const std::optional<double>& pointSize);
void SetFontFile(const std::optional<std::string>& fontFile);
void SetFontScale(const double fontScale);
void SetHDRIFile(const std::optional<std::string>& hdriFile);
void SetUseImageBasedLighting(bool use) override;
void SetBackground(const double* backgroundColor) override;
Expand Down Expand Up @@ -545,6 +546,7 @@ class vtkF3DRenderer : public vtkOpenGLRenderer
bool HasValidHDRISpec = false;

std::optional<std::string> FontFile;
double FontScale = 1.0;

double LightIntensity = 1.0;
std::map<vtkLight*, double> OriginalLightIntensities;
Expand Down
10 changes: 10 additions & 0 deletions vtkext/private/module/vtkF3DUIActor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ void vtkF3DUIActor::SetFontFile(const std::string& font)
}
}

//----------------------------------------------------------------------------
void vtkF3DUIActor::SetFontScale(const double fontScale)
{
if (this->FontScale != fontScale)
{
this->FontScale = fontScale;
this->Initialized = false;
}
}

//----------------------------------------------------------------------------
int vtkF3DUIActor::RenderOverlay(vtkViewport* vp)
{
Expand Down
6 changes: 6 additions & 0 deletions vtkext/private/module/vtkF3DUIActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ class vtkF3DUIActor : public vtkProp
*/
void SetFontFile(const std::string& font);

/**
* Set the font scale
*/
void SetFontScale(const double fontScale);

/**
* Render the UI actor
*/
Expand Down Expand Up @@ -162,6 +167,7 @@ class vtkF3DUIActor : public vtkProp
int FpsValue = 0;

std::string FontFile = "";
double FontScale = 1.0;

private:
vtkF3DUIActor(const vtkF3DUIActor&) = delete;
Expand Down

0 comments on commit 1ec4c0c

Please sign in to comment.