[Gui] describe gradient code better

- to make it easier to see what is happening (not yet perfect since the start numbers 4.0 and 5.0 are not clear yet)
- avoid a jump of the gradient bar when decreasing window size
- return for now only the direct bar width 8will be tested thoroughly now on several PCs if this will work)
This commit is contained in:
Uwe
2022-05-30 04:08:19 +02:00
parent e8850a36ea
commit 08ab216a13
3 changed files with 26 additions and 19 deletions

View File

@@ -103,7 +103,7 @@ float SoFCColorBarBase::getBoundingWidth(const SbVec2s& size)
group->unref();
float boxWidth = maxPt[0] - minPt[0];
return boxWidth + 0.2f;
return boxWidth;
}
// --------------------------------------------------------------------------

View File

@@ -110,19 +110,21 @@ 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 fMinX = 4.0f, fMaxX = 4.5f;
float fMinY = -4.0f, fMaxY = 4.0f;
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) {
fMinX = 5.0f * fRatio;
fMaxX = fMinX + 0.5f;
}
else if (fRatio < 1.0f) {
fMinY = -4.0f / fRatio;
fMaxY = 4.0f / fRatio;
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;
@@ -143,6 +145,7 @@ void SoFCColorGradient::setViewportSize(const SbVec2s& size)
if (labels->getChild(j)->getTypeId() == SoTransform::getClassTypeId()) {
if (first) {
first = false;
// set the labels with a small space of 0.1f besides the bar
static_cast<SoTransform*>(labels->getChild(j))->translation.setValue(fMaxX + 0.1f - boxWidth, fMaxY - 0.05f + fStep, 0.0f);
}
else {
@@ -152,6 +155,7 @@ void SoFCColorGradient::setViewportSize(const SbVec2s& size)
}
}
// gradient 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);
modifyPoints(_bbox);
}

View File

@@ -190,24 +190,27 @@ 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 fMinX = 4.0f, fMaxX = 4.5f;
float fMinY = -4.0f, fMaxY = 4.0f;
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) {
fMinX = 5.0f * fRatio;
fMaxX = fMinX + 0.5f;
}
else if (fRatio < 1.0f) {
fMinY = -4.0f / fRatio;
fMaxY = 4.0f / fRatio;
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;
}
// 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);
arrangeLabels(_bbox);