Gui: cache color bar width to avoid to compute it for every resize of the canvas
This commit is contained in:
@@ -45,7 +45,7 @@ SO_NODE_ABSTRACT_SOURCE(SoFCColorBarBase)
|
||||
/*!
|
||||
Constructor.
|
||||
*/
|
||||
SoFCColorBarBase::SoFCColorBarBase(): _windowSize(0,0)
|
||||
SoFCColorBarBase::SoFCColorBarBase() : _boxWidth(-1.0f), _windowSize(0,0)
|
||||
{
|
||||
SO_NODE_CONSTRUCTOR(SoFCColorBarBase);
|
||||
}
|
||||
@@ -80,8 +80,17 @@ void SoFCColorBarBase::GLRenderBelowPath(SoGLRenderAction * action)
|
||||
SoSeparator::GLRenderBelowPath(action);
|
||||
}
|
||||
|
||||
void SoFCColorBarBase::setModified()
|
||||
{
|
||||
_boxWidth = -1.0f;
|
||||
}
|
||||
|
||||
float SoFCColorBarBase::getBoundingWidth(const SbVec2s& size)
|
||||
{
|
||||
if (_boxWidth >= 0.0f) {
|
||||
return _boxWidth;
|
||||
}
|
||||
|
||||
// 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); // the 5 is just a value > 0
|
||||
@@ -103,6 +112,7 @@ float SoFCColorBarBase::getBoundingWidth(const SbVec2s& size)
|
||||
group->unref();
|
||||
|
||||
float boxWidth = maxPt[0] - minPt[0];
|
||||
_boxWidth = boxWidth;
|
||||
return boxWidth;
|
||||
}
|
||||
|
||||
|
||||
@@ -129,11 +129,16 @@ protected:
|
||||
* This method must be implemented in subclasses.
|
||||
*/
|
||||
virtual void setViewportSize( const SbVec2s& size ) = 0;
|
||||
/**
|
||||
* Mark the object as modified.
|
||||
*/
|
||||
void setModified();
|
||||
|
||||
SoFCColorBarBase ();
|
||||
virtual ~SoFCColorBarBase ();
|
||||
|
||||
private:
|
||||
float _boxWidth;
|
||||
SbVec2s _windowSize;
|
||||
};
|
||||
|
||||
|
||||
@@ -108,6 +108,8 @@ void SoFCColorGradient::setMarkerLabel(const SoMFString& label)
|
||||
labels->addChild(text2);
|
||||
}
|
||||
}
|
||||
|
||||
setModified();
|
||||
}
|
||||
|
||||
void SoFCColorGradient::setViewportSize(const SbVec2s& size)
|
||||
|
||||
@@ -245,6 +245,8 @@ void SoFCColorLegend::setLegendLabels(const App::ColorLegend& legend, int prec)
|
||||
|
||||
setMarkerLabel(labels);
|
||||
setMarkerValue(values);
|
||||
|
||||
setModified();
|
||||
}
|
||||
|
||||
void SoFCColorLegend::modifyPoints(const SbBox2f& box)
|
||||
|
||||
Reference in New Issue
Block a user