feat: implement configurable font settings for VTK viewports and GUI elements with persistent preferences.
This commit is contained in:
@@ -123,10 +123,9 @@ void Viewport::SetupPipeline(vtkRenderWindowInteractor* iren)
|
||||
iren->SetInteractorStyle(style);
|
||||
|
||||
// Corner annotation
|
||||
pv->m_Annotation->GetTextProperty()->SetColor(1, 1, 1);
|
||||
pv->m_Annotation->GetTextProperty()->SetFontFamilyToArial();
|
||||
SetFontColor(Vector3d(1.0, 1.0, 1.0));
|
||||
SetFont(FontConfig("Arial", 10));
|
||||
pv->m_Annotation->GetTextProperty()->SetOpacity(0.5);
|
||||
pv->m_Annotation->SetMaximumFontSize(10);
|
||||
pv->m_Annotation->SetText(0, "uLib VTK viewer.");
|
||||
pv->m_Renderer->AddViewProp(pv->m_Annotation);
|
||||
|
||||
@@ -603,6 +602,44 @@ bool Viewport::GetParallelProjection() const
|
||||
return false;
|
||||
}
|
||||
|
||||
void Viewport::SetFont(const FontConfig& font) {
|
||||
if (!pv->m_Annotation) return;
|
||||
auto* prop = pv->m_Annotation->GetTextProperty();
|
||||
if (font.family == "Arial") prop->SetFontFamilyToArial();
|
||||
else if (font.family == "Courier") prop->SetFontFamilyToCourier();
|
||||
else if (font.family == "Times") prop->SetFontFamilyToTimes();
|
||||
else prop->SetFontFamilyToArial(); // fallback
|
||||
|
||||
pv->m_Annotation->SetMaximumFontSize(font.size);
|
||||
prop->SetBold(font.bold);
|
||||
prop->SetItalic(font.italic);
|
||||
this->Render();
|
||||
}
|
||||
|
||||
FontConfig Viewport::GetFont() const {
|
||||
if (!pv->m_Annotation) return FontConfig();
|
||||
auto* prop = pv->m_Annotation->GetTextProperty();
|
||||
FontConfig f;
|
||||
f.family = prop->GetFontFamilyAsString();
|
||||
f.size = pv->m_Annotation->GetMaximumFontSize();
|
||||
f.bold = prop->GetBold();
|
||||
f.italic = prop->GetItalic();
|
||||
return f;
|
||||
}
|
||||
|
||||
void Viewport::SetFontColor(const Vector3d& color) {
|
||||
if (!pv->m_Annotation) return;
|
||||
pv->m_Annotation->GetTextProperty()->SetColor(color.x(), color.y(), color.z());
|
||||
this->Render();
|
||||
}
|
||||
|
||||
Vector3d Viewport::GetFontColor() const {
|
||||
if (!pv->m_Annotation) return Vector3d(1,1,1);
|
||||
double c[3];
|
||||
pv->m_Annotation->GetTextProperty()->GetColor(c);
|
||||
return Vector3d(c[0], c[1], c[2]);
|
||||
}
|
||||
|
||||
void Viewport::SetGridAxis(Axis axis)
|
||||
{
|
||||
m_GridAxis = axis;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "uLibVtkInterface.h"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "Core/FontConfig.h"
|
||||
#include "Math/Dense.h"
|
||||
|
||||
namespace uLib { class Object; }
|
||||
|
||||
@@ -83,6 +85,12 @@ public:
|
||||
void SetParallelProjection(bool parallel);
|
||||
bool GetParallelProjection() const;
|
||||
|
||||
// Font configuration
|
||||
void SetFont(const FontConfig& font);
|
||||
FontConfig GetFont() const;
|
||||
void SetFontColor(const Vector3d& color);
|
||||
Vector3d GetFontColor() const;
|
||||
|
||||
protected:
|
||||
void SetupPipeline(vtkRenderWindowInteractor* iren);
|
||||
|
||||
|
||||
56
src/Vtk/vtkViewportProperties.h
Normal file
56
src/Vtk/vtkViewportProperties.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef ULIB_VTK_VIEWPORTPROPERTIES_H
|
||||
#define ULIB_VTK_VIEWPORTPROPERTIES_H
|
||||
|
||||
#include "uLibVtkInterface.h"
|
||||
#include "vtkViewport.h"
|
||||
#include "Core/Property.h"
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
/**
|
||||
* @class ViewportProperties
|
||||
* @brief Exposes Viewport settings as a uLib::Object for the properties panel.
|
||||
*/
|
||||
class ViewportProperties : public uLib::Object {
|
||||
public:
|
||||
uLibTypeMacro(ViewportProperties, uLib::Object)
|
||||
|
||||
ViewportProperties(Viewport* vp) : m_Viewport(vp)
|
||||
{
|
||||
SetInstanceName("Viewport Settings");
|
||||
|
||||
// Initialize properties from viewport
|
||||
Font.Set(vp->GetFont());
|
||||
Color.Set(vp->GetFontColor());
|
||||
GridVisible.Set(vp->GetGridVisible());
|
||||
Parallel.Set(vp->GetParallelProjection());
|
||||
|
||||
// Connect properties to viewport setters
|
||||
uLib::Object::connect(&Font, &Property<FontConfig>::Updated, [this](){
|
||||
if (m_Viewport) m_Viewport->SetFont(Font.Get());
|
||||
});
|
||||
uLib::Object::connect(&Color, &Property<Vector3d>::Updated, [this](){
|
||||
if (m_Viewport) m_Viewport->SetFontColor(Color.Get());
|
||||
});
|
||||
uLib::Object::connect(&GridVisible, &Property<bool>::Updated, [this](){
|
||||
if (m_Viewport) m_Viewport->SetGridVisible(GridVisible.Get());
|
||||
});
|
||||
uLib::Object::connect(&Parallel, &Property<bool>::Updated, [this](){
|
||||
if (m_Viewport) m_Viewport->SetParallelProjection(Parallel.Get());
|
||||
});
|
||||
}
|
||||
|
||||
ULIB_PROPERTY(FontConfig, Font, FontConfig())
|
||||
ULIB_PROPERTY(Vector3d, Color, Vector3d(1.0, 1.0, 1.0))
|
||||
ULIB_PROPERTY(bool, GridVisible, true)
|
||||
ULIB_PROPERTY(bool, Parallel, false)
|
||||
|
||||
private:
|
||||
Viewport* m_Viewport;
|
||||
};
|
||||
|
||||
} // namespace Vtk
|
||||
} // namespace uLib
|
||||
|
||||
#endif // ULIB_VTK_VIEWPORTPROPERTIES_H
|
||||
Reference in New Issue
Block a user