From b9db257558fef7ac5a17dcb0e12131e8a2ef1fb3 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 7 Jun 2022 19:42:04 +0200 Subject: [PATCH] Gui: add SoColorBarLabel as workaround for a Coin3D bug --- src/Gui/SoFCColorGradient.cpp | 3 ++- src/Gui/SoFCDB.cpp | 1 + src/Gui/SoTextLabel.cpp | 27 +++++++++++++++++++++++++++ src/Gui/SoTextLabel.h | 20 +++++++++++++++++++- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/Gui/SoFCColorGradient.cpp b/src/Gui/SoFCColorGradient.cpp index e8fa0e8ae7..fbee2fc31a 100644 --- a/src/Gui/SoFCColorGradient.cpp +++ b/src/Gui/SoFCColorGradient.cpp @@ -35,6 +35,7 @@ #endif #include "SoFCColorGradient.h" +#include "SoTextLabel.h" #include "DlgSettingsColorGradientImp.h" #include "MainWindow.h" #include "MDIView.h" @@ -98,7 +99,7 @@ void SoFCColorGradient::setMarkerLabel(const SoMFString& label) for (int i = 0; i < num; i++) { SoTransform* trans = new SoTransform; SoBaseColor* color = new SoBaseColor; - SoText2 * text2 = new SoText2; + SoText2 * text2 = new SoColorBarLabel; trans->translation.setValue(0, -fStep, 0); color->rgb.setValue(0, 0, 0); diff --git a/src/Gui/SoFCDB.cpp b/src/Gui/SoFCDB.cpp index 16e7a930f6..95b758ab0f 100644 --- a/src/Gui/SoFCDB.cpp +++ b/src/Gui/SoFCDB.cpp @@ -124,6 +124,7 @@ void Gui::SoFCDB::init() SoVRMLAction ::initClass(); SoSkipBoundingGroup ::initClass(); SoTextLabel ::initClass(); + SoColorBarLabel ::initClass(); SoStringLabel ::initClass(); SoFrameLabel ::initClass(); TranslateManip ::initClass(); diff --git a/src/Gui/SoTextLabel.cpp b/src/Gui/SoTextLabel.cpp index f1bcad7242..4fe5a78463 100644 --- a/src/Gui/SoTextLabel.cpp +++ b/src/Gui/SoTextLabel.cpp @@ -298,6 +298,33 @@ void SoTextLabel::GLRender(SoGLRenderAction *action) // ------------------------------------------------------ +SO_NODE_SOURCE(SoColorBarLabel) + +void SoColorBarLabel::initClass() +{ + SO_NODE_INIT_CLASS(SoColorBarLabel, SoText2, "Text2"); +} + +SoColorBarLabel::SoColorBarLabel() +{ + SO_NODE_CONSTRUCTOR(SoColorBarLabel); +} + +void SoColorBarLabel::computeBBox(SoAction * action, SbBox3f & box, SbVec3f & center) +{ + inherited::computeBBox(action, box, center); + if (!box.hasVolume()) { + SbViewVolume vv = SoViewVolumeElement::get(action->getState()); + // workaround for https://github.com/coin3d/coin/issues/417: + // extend by 2 percent + vv.scaleWidth(1.02f); + SoViewVolumeElement::set(action->getState(), this, vv); + inherited::computeBBox(action, box, center); + } +} + +// ------------------------------------------------------ + SO_NODE_SOURCE(SoStringLabel) void SoStringLabel::initClass() diff --git a/src/Gui/SoTextLabel.h b/src/Gui/SoTextLabel.h index ba83c5b7c3..882527523e 100644 --- a/src/Gui/SoTextLabel.h +++ b/src/Gui/SoTextLabel.h @@ -32,6 +32,7 @@ #include #include #include +#include namespace Gui { @@ -54,10 +55,27 @@ public: SoSFFloat frameSize; protected: - virtual ~SoTextLabel() {}; + virtual ~SoTextLabel() {} virtual void GLRender(SoGLRenderAction *action); }; +/** + * A text label for the color bar. + * @author Werner Mayer + */ +class GuiExport SoColorBarLabel : public SoText2 { + typedef SoText2 inherited; + + SO_NODE_HEADER(SoColorBarLabel); + +public: + static void initClass(); + SoColorBarLabel(); + +protected: + void computeBBox(SoAction * action, SbBox3f & box, SbVec3f & center) override; +}; + class GuiExport SoStringLabel : public SoNode { typedef SoNode inherited;