From c5296fbb9254aa40e6aa23e81977a264993ecd73 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 30 May 2022 14:08:33 +0200 Subject: [PATCH] Gui: initialize _bbox with correct default values and fix incorrect label postions if ratio of width/height is less than 1 --- src/Gui/SoFCColorGradient.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Gui/SoFCColorGradient.cpp b/src/Gui/SoFCColorGradient.cpp index 4897aea7c2..8c75f30e65 100644 --- a/src/Gui/SoFCColorGradient.cpp +++ b/src/Gui/SoFCColorGradient.cpp @@ -48,7 +48,7 @@ SO_NODE_SOURCE(SoFCColorGradient) /*! Constructor. */ -SoFCColorGradient::SoFCColorGradient() : _bbox(4.0f, -4.0f, 4.5f, 4.0f), _precision(3) +SoFCColorGradient::SoFCColorGradient() : _bbox(5.0f, -4.0f, 5.5f, 4.0f), _precision(3) { SO_NODE_CONSTRUCTOR(SoFCColorGradient); coords = new SoCoordinate3; @@ -88,9 +88,11 @@ void SoFCColorGradient::setMarkerLabel(const SoMFString& label) int num = label.getNum(); if (num > 1) { - float fStep = 8.0f / ((float)num - 1); + SbVec2f maxPt = _bbox.getMax(); + SbVec2f minPt = _bbox.getMin(); + float fStep = (maxPt[1] - minPt[1]) / ((float)num - 1); SoTransform* trans = new SoTransform; - trans->translation.setValue(_bbox.getMax()[0] + 0.1f, _bbox.getMax()[1] - 0.05f + fStep, 0.0f); + trans->translation.setValue(maxPt[0] + 0.1f, maxPt[1] - 0.05f + fStep, 0.0f); labels->addChild(trans); for (int i = 0; i < num; i++) {