Merge pull request #9149 from xtemp09/gui-fix
[GUI] Radial gradient implementation
This commit is contained in:
@@ -64,6 +64,7 @@ void DlgSettingsViewColor::saveSettings()
|
||||
ui->backgroundColorMid->onSave();
|
||||
ui->radioButtonSimple->onSave();
|
||||
ui->radioButtonGradient->onSave();
|
||||
ui->rbRadialGradient->onSave();
|
||||
ui->checkMidColor->onSave();
|
||||
ui->checkBoxPreselection->onSave();
|
||||
ui->checkBoxSelection->onSave();
|
||||
@@ -81,6 +82,7 @@ void DlgSettingsViewColor::loadSettings()
|
||||
ui->backgroundColorMid->onRestore();
|
||||
ui->radioButtonSimple->onRestore();
|
||||
ui->radioButtonGradient->onRestore();
|
||||
ui->rbRadialGradient->onRestore();
|
||||
ui->checkMidColor->onRestore();
|
||||
ui->checkBoxPreselection->onRestore();
|
||||
ui->checkBoxSelection->onRestore();
|
||||
|
||||
@@ -267,7 +267,7 @@
|
||||
<string>Background will have selected color gradient</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Color gradient</string>
|
||||
<string>Linear gradient</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
@@ -314,17 +314,23 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<widget class="Gui::PrefRadioButton" name="rbRadialGradient">
|
||||
<property name="toolTip">
|
||||
<string>Background will have selected color gradient</string>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
<property name="text">
|
||||
<string>Radial gradient</string>
|
||||
</property>
|
||||
</spacer>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>RadialGradient</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>View</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="Gui::PrefColorButton" name="backgroundColorTo">
|
||||
@@ -586,6 +592,7 @@
|
||||
<tabstop>SelectionColor_Background</tabstop>
|
||||
<tabstop>radioButtonGradient</tabstop>
|
||||
<tabstop>backgroundColorFrom</tabstop>
|
||||
<tabstop>rbRadialGradient</tabstop>
|
||||
<tabstop>backgroundColorTo</tabstop>
|
||||
<tabstop>checkMidColor</tabstop>
|
||||
<tabstop>backgroundColorMid</tabstop>
|
||||
@@ -688,6 +695,38 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>rbRadialGradient</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>backgroundColorFrom</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>110</x>
|
||||
<y>309</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>310</x>
|
||||
<y>311</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>rbRadialGradient</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>backgroundColorTo</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>77</x>
|
||||
<y>309</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>310</x>
|
||||
<y>338</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>radioButtonSimple</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<FCInt Name="DefaultShapeTransparency" Value="0"/>
|
||||
<FCBool Name="EnableBacklight" Value="0"/>
|
||||
<FCBool Name="Gradient" Value="1"/>
|
||||
<FCBool Name="RadialGradient" Value="0"/>
|
||||
<FCUInt Name="HighlightColor" Value="4294907903"/>
|
||||
<FCBool Name="RandomColor" Value="0"/>
|
||||
<FCUInt Name="SelectionColor" Value="704588287"/>
|
||||
|
||||
@@ -119,6 +119,7 @@
|
||||
<FCUInt Name="CreateLineColor" Value="3435973887"/>
|
||||
<FCBool Name="Simple" Value="0"/>
|
||||
<FCBool Name="Gradient" Value="1"/>
|
||||
<FCBool Name="RadialGradient" Value="0"/>
|
||||
<FCBool Name="UseBackgroundColorMid" Value="0"/>
|
||||
<FCBool Name="RandomColor" Value="0"/>
|
||||
<FCUInt Name="BacklightColor" Value="4294967295"/>
|
||||
|
||||
@@ -23,6 +23,11 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
#include <array>
|
||||
#ifdef FC_OS_WIN32
|
||||
#define _USE_MATH_DEFINES
|
||||
#endif
|
||||
#include <cmath>
|
||||
#ifdef FC_OS_MACOSX
|
||||
#include <OpenGL/gl.h>
|
||||
#else
|
||||
@@ -32,6 +37,16 @@
|
||||
|
||||
#include "SoFCBackgroundGradient.h"
|
||||
|
||||
static const std::array <GLfloat[2], 32> big_circle = []{
|
||||
std::array <GLfloat[2], 32> result; int c = 0;
|
||||
for (GLfloat i = 0; i < 2*M_PI; i += 2*M_PI / 32, c++){
|
||||
result[c][0] = M_SQRT2*cosf(i); result[c][1] = M_SQRT2*sinf(i); }
|
||||
return result; }();
|
||||
static const std::array <GLfloat[2], 32> small_oval = []{
|
||||
std::array <GLfloat[2], 32> result; int c = 0;
|
||||
for (GLfloat i = 0; i < 2*M_PI; i += 2*M_PI / 32, c++){
|
||||
result[c][0] = 0.3*M_SQRT2*cosf(i); result[c][1] = M_SQRT1_2*sinf(i); }
|
||||
return result; }();
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
@@ -51,6 +66,7 @@ SoFCBackgroundGradient::SoFCBackgroundGradient()
|
||||
fCol.setValue(0.5f, 0.5f, 0.8f);
|
||||
tCol.setValue(0.7f, 0.7f, 0.9f);
|
||||
mCol.setValue(1.0f, 1.0f, 1.0f);
|
||||
radial = false;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -80,6 +96,7 @@ void SoFCBackgroundGradient::GLRender (SoGLRenderAction * /*action*/)
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
if(!radial){ // linear gradient
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
if (mCol[0] < 0) {
|
||||
glColor3f(fCol[0],fCol[1],fCol[2]); glVertex2f(-1, 1);
|
||||
@@ -99,6 +116,31 @@ void SoFCBackgroundGradient::GLRender (SoGLRenderAction * /*action*/)
|
||||
glColor3f(mCol[0],mCol[1],mCol[2]); glVertex2f( 1, 0);
|
||||
glColor3f(tCol[0],tCol[1],tCol[2]); glVertex2f( 1,-1);
|
||||
}
|
||||
} else { // radial gradient
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glColor3f(fCol[0], fCol[1], fCol[2]); glVertex2f(0.0f, 0.0f);
|
||||
|
||||
if (mCol[0] < 0) { // simple radial gradient
|
||||
glColor3f(tCol[0], tCol[1], tCol[2]);
|
||||
for (const GLfloat *vertex : big_circle)
|
||||
glVertex2fv( vertex );
|
||||
glVertex2fv( big_circle.front() );
|
||||
} else {
|
||||
glColor3f(mCol[0], mCol[1], mCol[2]);
|
||||
for (const GLfloat *vertex : small_oval)
|
||||
glVertex2fv( vertex );
|
||||
glVertex2fv( small_oval.front() );
|
||||
glEnd();
|
||||
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
for (std::size_t i = 0; i < small_oval.size(); i++){
|
||||
glColor3f(mCol[0], mCol[1], mCol[2]); glVertex2fv( small_oval[i] );
|
||||
glColor3f(tCol[0], tCol[1], tCol[2]); glVertex2fv( big_circle[i] ); }
|
||||
|
||||
glColor3f(mCol[0], mCol[1], mCol[2]); glVertex2fv( small_oval.front() );
|
||||
glColor3f(tCol[0], tCol[1], tCol[2]); glVertex2fv( big_circle.front() );
|
||||
}
|
||||
} // end of radial gradient
|
||||
glEnd();
|
||||
|
||||
glPopAttrib();
|
||||
@@ -109,18 +151,22 @@ void SoFCBackgroundGradient::GLRender (SoGLRenderAction * /*action*/)
|
||||
}
|
||||
|
||||
void SoFCBackgroundGradient::setColorGradient(const SbColor& fromColor,
|
||||
const SbColor& toColor)
|
||||
const SbColor& toColor,
|
||||
bool isRadial)
|
||||
{
|
||||
fCol = fromColor;
|
||||
tCol = toColor;
|
||||
mCol[0] = -1.0f;
|
||||
radial = isRadial;
|
||||
}
|
||||
|
||||
void SoFCBackgroundGradient::setColorGradient(const SbColor& fromColor,
|
||||
const SbColor& toColor,
|
||||
const SbColor& midColor)
|
||||
const SbColor& midColor,
|
||||
bool isRadial)
|
||||
{
|
||||
fCol = fromColor;
|
||||
tCol = toColor;
|
||||
mCol = midColor;
|
||||
radial = isRadial;
|
||||
}
|
||||
|
||||
@@ -44,8 +44,11 @@ public:
|
||||
SoFCBackgroundGradient();
|
||||
|
||||
void GLRender (SoGLRenderAction *action);
|
||||
void setColorGradient(const SbColor& fromColor, const SbColor& toColor);
|
||||
void setColorGradient(const SbColor& fromColor, const SbColor& toColor, const SbColor& midColor);
|
||||
void setColorGradient(const SbColor& fromColor, const SbColor& toColor, bool isRadial);
|
||||
void setColorGradient(const SbColor& fromColor, const SbColor& toColor, const SbColor& midColor, bool isRadial);
|
||||
|
||||
private:
|
||||
bool radial;
|
||||
|
||||
protected:
|
||||
virtual ~SoFCBackgroundGradient();
|
||||
|
||||
@@ -109,6 +109,7 @@ void AbstractSplitView::setupSettings()
|
||||
OnChange(*hGrp,"CornerCoordSystemSize");
|
||||
OnChange(*hGrp,"UseAutoRotation");
|
||||
OnChange(*hGrp,"Gradient");
|
||||
OnChange(*hGrp,"RadialGradient");
|
||||
OnChange(*hGrp,"BackgroundColor");
|
||||
OnChange(*hGrp,"BackgroundColor2");
|
||||
OnChange(*hGrp,"BackgroundColor3");
|
||||
@@ -263,9 +264,9 @@ void AbstractSplitView::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp
|
||||
for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
|
||||
(*it)->setAnimationEnabled(rGrp.GetBool("UseAutoRotation",false));
|
||||
}
|
||||
else if (strcmp(Reason,"Gradient") == 0) {
|
||||
else if ( strcmp(Reason,"Gradient") == 0 || strcmp(Reason, "RadialGradient") == 0 ) {
|
||||
for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
|
||||
(*it)->setGradientBackground((rGrp.GetBool("Gradient",true)));
|
||||
(*it)->setGradientBackground(rGrp.GetBool("Gradient", true) || rGrp.GetBool("RadialGradient", true));
|
||||
}
|
||||
else if (strcmp(Reason,"ShowFPS") == 0) {
|
||||
for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
|
||||
@@ -305,9 +306,11 @@ void AbstractSplitView::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp
|
||||
for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
|
||||
(*it)->setBackgroundColor(QColor::fromRgbF(r1, g1, b1));
|
||||
if (!rGrp.GetBool("UseBackgroundColorMid",false))
|
||||
(*it)->setGradientBackgroundColor(SbColor(r2, g2, b2), SbColor(r3, g3, b3));
|
||||
(*it)->setGradientBackgroundColor(SbColor(r2, g2, b2), SbColor(r3, g3, b3),
|
||||
rGrp.GetBool("RadialGradient", false) );
|
||||
else
|
||||
(*it)->setGradientBackgroundColor(SbColor(r2, g2, b2), SbColor(r3, g3, b3), SbColor(r4, g4, b4));
|
||||
(*it)->setGradientBackgroundColor(SbColor(r2, g2, b2), SbColor(r3, g3, b3), SbColor(r4, g4, b4),
|
||||
rGrp.GetBool("RadialGradient", false) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1084,16 +1084,18 @@ bool View3DInventorViewer::hasGradientBackground() const
|
||||
}
|
||||
|
||||
void View3DInventorViewer::setGradientBackgroundColor(const SbColor& fromColor,
|
||||
const SbColor& toColor)
|
||||
const SbColor& toColor,
|
||||
bool isRadial)
|
||||
{
|
||||
pcBackGround->setColorGradient(fromColor, toColor);
|
||||
pcBackGround->setColorGradient(fromColor, toColor, isRadial);
|
||||
}
|
||||
|
||||
void View3DInventorViewer::setGradientBackgroundColor(const SbColor& fromColor,
|
||||
const SbColor& toColor,
|
||||
const SbColor& midColor)
|
||||
const SbColor& midColor,
|
||||
bool isRadial)
|
||||
{
|
||||
pcBackGround->setColorGradient(fromColor, toColor, midColor);
|
||||
pcBackGround->setColorGradient(fromColor, toColor, midColor, isRadial);
|
||||
}
|
||||
|
||||
void View3DInventorViewer::setEnabledFPSCounter(bool on)
|
||||
|
||||
@@ -373,10 +373,12 @@ public:
|
||||
void setGradientBackground(bool b);
|
||||
bool hasGradientBackground() const;
|
||||
void setGradientBackgroundColor(const SbColor& fromColor,
|
||||
const SbColor& toColor);
|
||||
const SbColor& toColor,
|
||||
bool isRadial);
|
||||
void setGradientBackgroundColor(const SbColor& fromColor,
|
||||
const SbColor& toColor,
|
||||
const SbColor& midColor);
|
||||
const SbColor& midColor,
|
||||
bool isRadial);
|
||||
void setNavigationType(Base::Type);
|
||||
|
||||
void setAxisCross(bool b);
|
||||
|
||||
@@ -68,6 +68,7 @@ void View3DSettings::applySettings()
|
||||
OnChange(*hGrp,"ShowAxisCross");
|
||||
OnChange(*hGrp,"UseAutoRotation");
|
||||
OnChange(*hGrp,"Gradient");
|
||||
OnChange(*hGrp,"RadialGradient");
|
||||
OnChange(*hGrp,"BackgroundColor");
|
||||
OnChange(*hGrp,"BackgroundColor2");
|
||||
OnChange(*hGrp,"BackgroundColor3");
|
||||
@@ -233,8 +234,8 @@ void View3DSettings::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::M
|
||||
else if (strcmp(Reason,"UseAutoRotation") == 0) {
|
||||
_viewer->setAnimationEnabled(rGrp.GetBool("UseAutoRotation", false));
|
||||
}
|
||||
else if (strcmp(Reason,"Gradient") == 0) {
|
||||
_viewer->setGradientBackground((rGrp.GetBool("Gradient", true)));
|
||||
else if (strcmp(Reason,"Gradient") == 0 || strcmp(Reason,"RadialGradient") == 0) {
|
||||
_viewer->setGradientBackground(rGrp.GetBool("Gradient", true) || rGrp.GetBool("RadialGradient", true));
|
||||
}
|
||||
else if (strcmp(Reason,"ShowFPS") == 0) {
|
||||
_viewer->setEnabledFPSCounter(rGrp.GetBool("ShowFPS", false));
|
||||
@@ -299,9 +300,9 @@ void View3DSettings::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::M
|
||||
r4 = ((col4 >> 24) & 0xff) / 255.0; g4 = ((col4 >> 16) & 0xff) / 255.0; b4 = ((col4 >> 8) & 0xff) / 255.0;
|
||||
_viewer->setBackgroundColor(QColor::fromRgbF(r1, g1, b1));
|
||||
if (!rGrp.GetBool("UseBackgroundColorMid",false))
|
||||
_viewer->setGradientBackgroundColor(SbColor(r2, g2, b2), SbColor(r3, g3, b3));
|
||||
_viewer->setGradientBackgroundColor(SbColor(r2, g2, b2), SbColor(r3, g3, b3), rGrp.GetBool("RadialGradient", false));
|
||||
else
|
||||
_viewer->setGradientBackgroundColor(SbColor(r2, g2, b2), SbColor(r3, g3, b3), SbColor(r4, g4, b4));
|
||||
_viewer->setGradientBackgroundColor(SbColor(r2, g2, b2), SbColor(r3, g3, b3), SbColor(r4, g4, b4), rGrp.GetBool("RadialGradient", false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -437,7 +437,7 @@ Py::Object View3DInventorViewerPy::setBackgroundColor(const Py::Tuple& args)
|
||||
}
|
||||
try {
|
||||
SbColor col(r,g,b);
|
||||
_viewer->setGradientBackgroundColor(col,col);
|
||||
_viewer->setGradientBackgroundColor(col, col, false);
|
||||
return Py::None();
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
|
||||
Reference in New Issue
Block a user