Gui: refactor SoFCColorGradient::setViewportSize and SoFCColorLegend::setViewportSize
This commit is contained in:
@@ -106,6 +106,33 @@ float SoFCColorBarBase::getBoundingWidth(const SbVec2s& size)
|
||||
return boxWidth;
|
||||
}
|
||||
|
||||
float SoFCColorBarBase::getBounds(const SbVec2s& size, float& fMinX, float&fMinY, float& fMaxX, float& fMaxY)
|
||||
{
|
||||
// ratio of window width / height
|
||||
float fRatio = static_cast<float>(size[0]) / static_cast<float>(size[1]);
|
||||
float baseYValue = 4.0f;
|
||||
float barWidth = 0.5f;
|
||||
|
||||
fMinX = 5.0f * fRatio; // must be scaled with the ratio to assure it stays at the right
|
||||
fMaxX = fMinX + barWidth;
|
||||
fMinY = -baseYValue;
|
||||
fMaxY = baseYValue; // bar has the height of almost whole window height
|
||||
|
||||
if (fRatio < 1.0f) {
|
||||
// must be adjusted to assure that the height of the bar doesn't shrink
|
||||
fMinY = -baseYValue / fRatio;
|
||||
fMaxY = baseYValue / fRatio;
|
||||
}
|
||||
|
||||
// get the bounding box width of the color bar and labels
|
||||
float boxWidth = getBoundingWidth(size);
|
||||
if (fRatio < 1.0f) {
|
||||
boxWidth *= fRatio;
|
||||
}
|
||||
|
||||
return boxWidth;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
namespace Gui {
|
||||
|
||||
@@ -112,6 +112,11 @@ public:
|
||||
virtual const char* getColorBarName() const = 0;
|
||||
|
||||
protected:
|
||||
/** Computes the dimensions of the color bar and labels in coordinates with
|
||||
* respect to the defined height of the camera.
|
||||
* Returns the width of the bounding box
|
||||
*/
|
||||
float getBounds(const SbVec2s& size, float& fMinX, float&fMinY, float& fMaxX, float& fMaxY);
|
||||
/** Returns the width of the color bar and labels
|
||||
*
|
||||
* Computes the occupied width of the color bar and its labels.
|
||||
|
||||
@@ -110,25 +110,8 @@ void SoFCColorGradient::setMarkerLabel(const SoMFString& label)
|
||||
|
||||
void SoFCColorGradient::setViewportSize(const SbVec2s& size)
|
||||
{
|
||||
// ratio of window height / width
|
||||
float fRatio = static_cast<float>(size[0]) / static_cast<float>(size[1]);
|
||||
float baseYValue = 4.0f;
|
||||
float barWidth = 0.5f;
|
||||
float fMinX = 5.0f * fRatio; // must be scaled with the ratio to assure it stays at the right
|
||||
float fMaxX = fMinX + barWidth;
|
||||
float fMinY = -baseYValue, fMaxY = baseYValue; // bar has the height of almost whole window height
|
||||
|
||||
if (fRatio < 1.0f) {
|
||||
// height must be adjusted to assure bar stays smaller than window height
|
||||
fMinY = -baseYValue / fRatio;
|
||||
fMaxY = baseYValue / fRatio;
|
||||
}
|
||||
|
||||
// get the bounding box width of the labels
|
||||
float boxWidth = getBoundingWidth(size);
|
||||
if (fRatio < 1.0f) {
|
||||
boxWidth *= fRatio;
|
||||
}
|
||||
float fMinX, fMinY, fMaxX, fMaxY;
|
||||
float boxWidth = getBounds(size, fMinX, fMinY, fMaxX, fMaxY);
|
||||
|
||||
// search for the labels
|
||||
int num = 0;
|
||||
|
||||
@@ -190,25 +190,8 @@ void SoFCColorLegend::setMarkerValue(const SoMFString& value)
|
||||
|
||||
void SoFCColorLegend::setViewportSize(const SbVec2s& size)
|
||||
{
|
||||
// ratio of window height / width
|
||||
float fRatio = static_cast<float>(size[0]) / static_cast<float>(size[1]);
|
||||
float baseYValue = 4.0f;
|
||||
float barWidth = 0.5f;
|
||||
float fMinX = 5.0f * fRatio; // must be scaled with the ratio to assure it stays at the right
|
||||
float fMaxX = fMinX + barWidth;
|
||||
float fMinY = -baseYValue, fMaxY = baseYValue; // bar has the height of almost whole window height
|
||||
|
||||
if (fRatio < 1.0f) {
|
||||
// height must be adjusted to assure bar stays smaller than window height
|
||||
fMinY = -baseYValue / fRatio;
|
||||
fMaxY = baseYValue / fRatio;
|
||||
}
|
||||
|
||||
// get the bounding box width of the labels
|
||||
float boxWidth = getBoundingWidth(size);
|
||||
if (fRatio < 1.0f) {
|
||||
boxWidth *= fRatio;
|
||||
}
|
||||
float fMinX, fMinY, fMaxX, fMaxY;
|
||||
float boxWidth = getBounds(size, fMinX, fMinY, fMaxX, fMaxY);
|
||||
|
||||
// legend bar is shifted to the left by width of the labels to assure that labels are fully visible
|
||||
_bbox.setBounds(fMinX - boxWidth, fMinY, fMaxX - boxWidth, fMaxY);
|
||||
|
||||
Reference in New Issue
Block a user