Navigation Menu

Skip to content

Commit

Permalink
Gui: add SoColorBarLabel as workaround for a Coin3D bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jun 7, 2022
1 parent b9b21dd commit 77627bb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Gui/SoFCColorGradient.cpp
Expand Up @@ -35,6 +35,7 @@
#endif

#include "SoFCColorGradient.h"
#include "SoTextLabel.h"
#include "DlgSettingsColorGradientImp.h"
#include "MainWindow.h"
#include "MDIView.h"
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/Gui/SoFCDB.cpp
Expand Up @@ -124,6 +124,7 @@ void Gui::SoFCDB::init()
SoVRMLAction ::initClass();
SoSkipBoundingGroup ::initClass();
SoTextLabel ::initClass();
SoColorBarLabel ::initClass();
SoStringLabel ::initClass();
SoFrameLabel ::initClass();
TranslateManip ::initClass();
Expand Down
27 changes: 27 additions & 0 deletions src/Gui/SoTextLabel.cpp
Expand Up @@ -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()
Expand Down
20 changes: 19 additions & 1 deletion src/Gui/SoTextLabel.h
Expand Up @@ -32,6 +32,7 @@
#include <Inventor/manips/SoTransformManip.h>
#include <Inventor/nodes/SoImage.h>
#include <Inventor/nodes/SoText2.h>
#include <FCGlobal.h>


namespace Gui {
Expand All @@ -54,10 +55,27 @@ class GuiExport SoTextLabel : public SoText2 {
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;

Expand Down

0 comments on commit 77627bb

Please sign in to comment.