Gui: add enum types to handle background gradients

This fixes some API flaws where booleans were used to distinguish between three different types
This commit is contained in:
wmayer
2023-04-04 17:12:14 +02:00
committed by wwmayer
parent 2845cd55a0
commit d6190cb79c
6 changed files with 97 additions and 52 deletions

View File

@@ -467,7 +467,7 @@ void View3DInventorViewer::init()
setViewing(false);
setBackgroundColor(QColor(25, 25, 25));
setGradientBackground(true);
setGradientBackground(Background::LinearGradient);
// set some callback functions for user interaction
addStartCallback(interactionStartCB);
@@ -1070,32 +1070,53 @@ void View3DInventorViewer::handleEventCB(void* ud, SoEventCallback* n)
SoGLWidgetElement::set(action->getState(), qobject_cast<QtGLWidget*>(that->getGLWidget()));
}
void View3DInventorViewer::setGradientBackground(bool on)
void View3DInventorViewer::setGradientBackground(View3DInventorViewer::Background grad)
{
if (on && backgroundroot->findChild(pcBackGround) == -1)
backgroundroot->addChild(pcBackGround);
else if (!on && backgroundroot->findChild(pcBackGround) != -1)
backgroundroot->removeChild(pcBackGround);
switch (grad) {
case Background::NoGradient:
if (backgroundroot->findChild(pcBackGround) != -1) {
backgroundroot->removeChild(pcBackGround);
}
break;
case Background::LinearGradient:
pcBackGround->setGradient(SoFCBackgroundGradient::LINEAR);
if (backgroundroot->findChild(pcBackGround) == -1) {
backgroundroot->addChild(pcBackGround);
}
break;
case Background::RadialGradient:
pcBackGround->setGradient(SoFCBackgroundGradient::RADIAL);
if (backgroundroot->findChild(pcBackGround) == -1) {
backgroundroot->addChild(pcBackGround);
}
break;
}
}
bool View3DInventorViewer::hasGradientBackground() const
View3DInventorViewer::Background View3DInventorViewer::getGradientBackground() const
{
return (backgroundroot->findChild(pcBackGround) != -1);
if (backgroundroot->findChild(pcBackGround) == -1) {
return Background::NoGradient;
}
if (pcBackGround->getGradient() == SoFCBackgroundGradient::LINEAR) {
return Background::LinearGradient;
}
return Background::RadialGradient;
}
void View3DInventorViewer::setGradientBackgroundColor(const SbColor& fromColor,
const SbColor& toColor)
{
pcBackGround->setColorGradient(fromColor, toColor);
}
void View3DInventorViewer::setGradientBackgroundColor(const SbColor& fromColor,
const SbColor& toColor,
bool isRadial)
const SbColor& midColor)
{
pcBackGround->setColorGradient(fromColor, toColor, isRadial);
}
void View3DInventorViewer::setGradientBackgroundColor(const SbColor& fromColor,
const SbColor& toColor,
const SbColor& midColor,
bool isRadial)
{
pcBackGround->setColorGradient(fromColor, toColor, midColor, isRadial);
pcBackGround->setColorGradient(fromColor, toColor, midColor);
}
void View3DInventorViewer::setEnabledFPSCounter(bool on)
@@ -1880,7 +1901,7 @@ void View3DInventorViewer::imageFromFramebuffer(int width, int height, int sampl
QtGLFramebufferObject fbo(width, height, fboFormat);
const QColor col = backgroundColor();
bool on = hasGradientBackground();
auto grad = getGradientBackground();
int alpha = 255;
QColor bgopaque = bgcolor;
@@ -1890,12 +1911,12 @@ void View3DInventorViewer::imageFromFramebuffer(int width, int height, int sampl
if (alpha < 255)
bgopaque.setRgb(255,255,255);
setBackgroundColor(bgopaque);
setGradientBackground(false);
setGradientBackground(Background::NoGradient);
}
renderToFramebuffer(&fbo);
setBackgroundColor(col);
setGradientBackground(on);
setGradientBackground(grad);
img = fbo.toImage();
// if background color isn't opaque manipulate the image