Gui: refactor SoFCColorGradient::setViewportSize and SoFCColorLegend::setViewportSize

This commit is contained in:
wmayer
2022-05-30 11:12:31 +02:00
parent 47125d8fda
commit 37d2492719
4 changed files with 36 additions and 38 deletions

View File

@@ -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;