Gui: fix number display issue of color bar
This commit is contained in:
@@ -23,9 +23,11 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <Inventor/actions/SoGetBoundingBoxAction.h>
|
||||
# include <Inventor/actions/SoGLRenderAction.h>
|
||||
# include <Inventor/events/SoMouseButtonEvent.h>
|
||||
# include <Inventor/nodes/SoEventCallback.h>
|
||||
# include <Inventor/nodes/SoOrthographicCamera.h>
|
||||
# include <Inventor/nodes/SoSwitch.h>
|
||||
# include <QApplication>
|
||||
# include <QMenu>
|
||||
@@ -78,6 +80,32 @@ void SoFCColorBarBase::GLRenderBelowPath(SoGLRenderAction * action)
|
||||
SoSeparator::GLRenderBelowPath(action);
|
||||
}
|
||||
|
||||
float SoFCColorBarBase::getBoundingWidth(const SbVec2s& size)
|
||||
{
|
||||
// These are the same camera settings for front nodes as defined in the 3d view
|
||||
SoOrthographicCamera* cam = new SoOrthographicCamera;
|
||||
cam->position = SbVec3f(0, 0, 5);
|
||||
cam->height = 10;
|
||||
cam->nearDistance = 0;
|
||||
cam->farDistance = 10;
|
||||
|
||||
SoGroup* group = new SoGroup();
|
||||
group->ref();
|
||||
group->addChild(cam);
|
||||
group->addChild(this);
|
||||
|
||||
SbViewportRegion vpr(size);
|
||||
SoGetBoundingBoxAction bbact(vpr);
|
||||
bbact.apply(group);
|
||||
SbBox3f box = bbact.getBoundingBox();
|
||||
SbVec3f minPt, maxPt;
|
||||
box.getBounds(minPt, maxPt);
|
||||
group->unref();
|
||||
|
||||
float boxWidth = maxPt[0] - minPt[0];
|
||||
return boxWidth + 0.2f;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
namespace Gui {
|
||||
|
||||
@@ -112,6 +112,12 @@ public:
|
||||
virtual const char* getColorBarName() const = 0;
|
||||
|
||||
protected:
|
||||
/** Returns the width of the color bar and labels
|
||||
*
|
||||
* Computes the occupied width of the color bar and its labels.
|
||||
* It therefore determines the bounding box.
|
||||
*/
|
||||
float getBoundingWidth(const SbVec2s& size);
|
||||
/**
|
||||
* Sets the current viewer size to recalculate the new position.
|
||||
*
|
||||
|
||||
@@ -110,13 +110,12 @@ void SoFCColorGradient::setMarkerLabel(const SoMFString& label)
|
||||
|
||||
void SoFCColorGradient::setViewportSize(const SbVec2s& size)
|
||||
{
|
||||
// don't know why the parameter range isn't between [-1,+1]
|
||||
float fRatio = ((float)size[0]) / ((float)size[1]);
|
||||
float fRatio = static_cast<float>(size[0]) / static_cast<float>(size[1]);
|
||||
float fMinX = 4.0f, fMaxX = 4.5f;
|
||||
float fMinY = -4.0f, fMaxY = 4.0f;
|
||||
|
||||
if (fRatio > 1.0f) {
|
||||
fMinX = 4.0f * fRatio;
|
||||
fMinX = 5.0f * fRatio;
|
||||
fMaxX = fMinX + 0.5f;
|
||||
}
|
||||
else if (fRatio < 1.0f) {
|
||||
@@ -124,6 +123,11 @@ void SoFCColorGradient::setViewportSize(const SbVec2s& size)
|
||||
fMaxY = 4.0f / fRatio;
|
||||
}
|
||||
|
||||
float boxWidth = getBoundingWidth(size);
|
||||
if (fRatio < 1.0f) {
|
||||
boxWidth *= fRatio;
|
||||
}
|
||||
|
||||
// search for the labels
|
||||
int num = 0;
|
||||
for (int i = 0; i < labels->getNumChildren(); i++) {
|
||||
@@ -139,7 +143,7 @@ void SoFCColorGradient::setViewportSize(const SbVec2s& size)
|
||||
if (labels->getChild(j)->getTypeId() == SoTransform::getClassTypeId()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
static_cast<SoTransform*>(labels->getChild(j))->translation.setValue(fMaxX + 0.1f, fMaxY - 0.05f + fStep, 0.0f);
|
||||
static_cast<SoTransform*>(labels->getChild(j))->translation.setValue(fMaxX + 0.1f - boxWidth, fMaxY - 0.05f + fStep, 0.0f);
|
||||
}
|
||||
else {
|
||||
static_cast<SoTransform*>(labels->getChild(j))->translation.setValue(0, -fStep, 0.0f);
|
||||
@@ -148,7 +152,7 @@ void SoFCColorGradient::setViewportSize(const SbVec2s& size)
|
||||
}
|
||||
}
|
||||
|
||||
_bbox.setBounds(fMinX, fMinY, fMaxX, fMaxY);
|
||||
_bbox.setBounds(fMinX - boxWidth, fMinY, fMaxX - boxWidth, fMaxY);
|
||||
modifyPoints(_bbox);
|
||||
}
|
||||
|
||||
|
||||
@@ -190,13 +190,12 @@ void SoFCColorLegend::setMarkerValue(const SoMFString& value)
|
||||
|
||||
void SoFCColorLegend::setViewportSize(const SbVec2s& size)
|
||||
{
|
||||
// don't know why the parameter range isn't between [-1,+1]
|
||||
float fRatio = static_cast<float>(size[0]) / static_cast<float>(size[1]);
|
||||
float fMinX = 4.0f, fMaxX = 4.5f;
|
||||
float fMinY = -4.0f, fMaxY = 4.0f;
|
||||
|
||||
if (fRatio > 1.0f) {
|
||||
fMinX = 4.0f * fRatio;
|
||||
fMinX = 5.0f * fRatio;
|
||||
fMaxX = fMinX + 0.5f;
|
||||
}
|
||||
else if (fRatio < 1.0f) {
|
||||
@@ -204,7 +203,12 @@ void SoFCColorLegend::setViewportSize(const SbVec2s& size)
|
||||
fMaxY = 4.0f / fRatio;
|
||||
}
|
||||
|
||||
_bbox.setBounds(fMinX, fMinY, fMaxX, fMaxY);
|
||||
float boxWidth = getBoundingWidth(size);
|
||||
if (fRatio < 1.0f) {
|
||||
boxWidth *= fRatio;
|
||||
}
|
||||
|
||||
_bbox.setBounds(fMinX - boxWidth, fMinY, fMaxX - boxWidth, fMaxY);
|
||||
|
||||
arrangeLabels(_bbox);
|
||||
arrangeValues(_bbox);
|
||||
|
||||
Reference in New Issue
Block a user