Gui: add theming abilities to interactive gizmos
This commit is contained in:
committed by
Kacper Donat
parent
d22b44cc70
commit
01ed84c3c9
@@ -1161,6 +1161,7 @@ SET(Inventor_SRCS
|
||||
Inventor/Draggers/SoRotationDraggerGeometry.h
|
||||
Inventor/Draggers/Gizmo.h
|
||||
Inventor/Draggers/GizmoHelper.h
|
||||
Inventor/Draggers/GizmoStyleParameters.h
|
||||
SoFCColorBar.h
|
||||
SoFCColorBarNotifier.h
|
||||
SoFCColorGradient.h
|
||||
|
||||
@@ -38,8 +38,10 @@
|
||||
#include <Base/Converter.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Precision.h>
|
||||
#include "Base/ServiceProvider.h"
|
||||
#include <Base/Tools.h>
|
||||
#include <Document.h>
|
||||
#include <Gui/Inventor/Draggers/GizmoStyleParameters.h>
|
||||
#include <Gui/Inventor/So3DAnnotation.h>
|
||||
#include <Gui/Inventor/SoToggleSwitch.h>
|
||||
#include <Gui/QuantitySpinBox.h>
|
||||
@@ -125,6 +127,8 @@ SoInteractionKit* LinearGizmo::initDragger()
|
||||
arrow->cylinderHeight = 3.5;
|
||||
arrow->cylinderRadius = 0.2;
|
||||
|
||||
updateColorTheme();
|
||||
|
||||
return draggerContainer;
|
||||
}
|
||||
|
||||
@@ -134,6 +138,20 @@ void LinearGizmo::uninitDragger()
|
||||
draggerContainer = nullptr;
|
||||
}
|
||||
|
||||
void LinearGizmo::updateColorTheme()
|
||||
{
|
||||
auto* styleParameterManager = Base::provideService<Gui::StyleParameters::ParameterManager>();
|
||||
Base::Color baseColor = styleParameterManager->resolve(StyleParameters::LinearGizmoBaseColor);
|
||||
Base::Color activeColor = styleParameterManager->resolve(StyleParameters::LinearGizmoActiveColor);
|
||||
|
||||
dragger->color = baseColor.asValue<SbColor>();
|
||||
dragger->activeColor = activeColor.asValue<SbColor>();
|
||||
|
||||
auto baseGeom = SO_GET_PART(dragger, "baseGeom", SoArrowBase);
|
||||
Base::Color baseGeomColor = styleParameterManager->resolve(StyleParameters::DimensionVisualizerColor);
|
||||
baseGeom->color = baseGeomColor.asValue<SbColor>();
|
||||
}
|
||||
|
||||
GizmoPlacement LinearGizmo::getDraggerPlacement()
|
||||
{
|
||||
assert(draggerContainer && "Forgot to call GizmoContainer::initGizmos?");
|
||||
@@ -296,6 +314,8 @@ SoInteractionKit* RotationGizmo::initDragger()
|
||||
|
||||
setRotAngle(property->value().getValue());
|
||||
|
||||
updateColorTheme();
|
||||
|
||||
return draggerContainer;
|
||||
}
|
||||
|
||||
@@ -309,6 +329,16 @@ void RotationGizmo::uninitDragger()
|
||||
translationSensor.setFunction(nullptr);
|
||||
}
|
||||
|
||||
void RotationGizmo::updateColorTheme()
|
||||
{
|
||||
auto* styleParameterManager = Base::provideService<Gui::StyleParameters::ParameterManager>();
|
||||
Base::Color baseColor = styleParameterManager->resolve(StyleParameters::RotationGizmoBaseColor);
|
||||
Base::Color activeColor = styleParameterManager->resolve(StyleParameters::RotationGizmoActiveColor);
|
||||
|
||||
dragger->color = baseColor.asValue<SbColor>();
|
||||
dragger->activeColor = activeColor.asValue<SbColor>();
|
||||
}
|
||||
|
||||
GizmoPlacement RotationGizmo::getDraggerPlacement()
|
||||
{
|
||||
assert(draggerContainer && "Forgot to call GizmoContainer::initGizmos?");
|
||||
@@ -506,6 +536,8 @@ SoInteractionKit* DirectedRotationGizmo::initDragger()
|
||||
rotator->rightArrowVisible = false;
|
||||
dragger->setPart("rotator", rotator);
|
||||
|
||||
updateColorTheme();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -532,6 +564,8 @@ SoInteractionKit* RadialGizmo::initDragger()
|
||||
|
||||
dragger->instantiateBaseGeometry();
|
||||
|
||||
updateColorTheme();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -552,6 +586,22 @@ void RadialGizmo::flipArrow()
|
||||
rotator->flipArrow();
|
||||
}
|
||||
|
||||
void RadialGizmo::updateColorTheme()
|
||||
{
|
||||
auto dragger = getDraggerContainer()->getDragger();
|
||||
|
||||
auto* styleParameterManager = Base::provideService<Gui::StyleParameters::ParameterManager>();
|
||||
Base::Color baseColor = styleParameterManager->resolve(StyleParameters::RotationGizmoBaseColor);
|
||||
Base::Color activeColor = styleParameterManager->resolve(StyleParameters::RotationGizmoActiveColor);
|
||||
|
||||
dragger->color = baseColor.asValue<SbColor>();
|
||||
dragger->activeColor = activeColor.asValue<SbColor>();
|
||||
|
||||
auto baseGeom = SO_GET_PART(dragger, "baseGeom", SoRotatorBase);
|
||||
Base::Color baseGeomColor = styleParameterManager->resolve(StyleParameters::DimensionVisualizerColor);
|
||||
baseGeom->color = baseGeomColor.asValue<SbColor>();
|
||||
}
|
||||
|
||||
SO_KIT_SOURCE(GizmoContainer)
|
||||
|
||||
void GizmoContainer::initClass()
|
||||
|
||||
@@ -96,6 +96,8 @@ public:
|
||||
SoInteractionKit* initDragger() override;
|
||||
void uninitDragger() override;
|
||||
|
||||
void updateColorTheme();
|
||||
|
||||
// Returns the position and rotation of the base of the dragger
|
||||
GizmoPlacement getDraggerPlacement() override;
|
||||
void setDraggerPlacement(const SbVec3f& pos, const SbVec3f& dir) override;
|
||||
@@ -132,6 +134,8 @@ public:
|
||||
SoInteractionKit* initDragger() override;
|
||||
void uninitDragger() override;
|
||||
|
||||
void updateColorTheme();
|
||||
|
||||
// Distance between the linear gizmo base and rotation gizmo
|
||||
double sepDistance = 0;
|
||||
|
||||
@@ -190,6 +194,8 @@ public:
|
||||
|
||||
SoInteractionKit* initDragger() override;
|
||||
|
||||
void updateColorTheme();
|
||||
|
||||
void setRadius(float radius);
|
||||
void flipArrow();
|
||||
|
||||
|
||||
40
src/Gui/Inventor/Draggers/GizmoStyleParameters.h
Normal file
40
src/Gui/Inventor/Draggers/GizmoStyleParameters.h
Normal file
@@ -0,0 +1,40 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2025 Sayantan Deb <sayantandebin[at]gmail.com> *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
* *
|
||||
* FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 2.1 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* FreeCAD is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with FreeCAD. If not, see *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef GUI_GIZMO_STYLE_PARAMETERS_H
|
||||
#define GUI_GIZMO_STYLE_PARAMETERS_H
|
||||
|
||||
#include <Base/Builder3D.h>
|
||||
#include <Gui/StyleParameters/ParameterManager.h>
|
||||
|
||||
namespace Gui::StyleParameters {
|
||||
DEFINE_STYLE_PARAMETER(LinearGizmoBaseColor, Base::Color(1.0F, 0.0F, 0.0F));
|
||||
DEFINE_STYLE_PARAMETER(LinearGizmoActiveColor, Base::Color(1.0F, 1.0F, 0.0F));
|
||||
|
||||
DEFINE_STYLE_PARAMETER(RotationGizmoBaseColor, Base::Color(1.0F, 0.0F, 0.0F));
|
||||
DEFINE_STYLE_PARAMETER(RotationGizmoActiveColor, Base::Color(1.0F, 1.0F, 0.0F));
|
||||
|
||||
DEFINE_STYLE_PARAMETER(DimensionVisualizerColor, Base::Color(0.214F, 0.560F, 0.930F));
|
||||
}
|
||||
|
||||
#endif /* GUI_GIZMO_STYLE_PARAMETERS_H */
|
||||
@@ -151,7 +151,7 @@ SoArrowBase::SoArrowBase()
|
||||
|
||||
SO_KIT_ADD_FIELD(cylinderHeight, (1.0));
|
||||
SO_KIT_ADD_FIELD(cylinderRadius, (0.15));
|
||||
SO_KIT_ADD_FIELD(color, (0.214, 0.560, 0.930));
|
||||
SO_KIT_ADD_FIELD(color, (0, 0, 1));
|
||||
|
||||
SO_KIT_INIT_INSTANCE();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user