1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-21 10:13:43 +03:00

0031039: Visualization - add elliptical gradient background style

Added new elliptical gradient fill method and updated vbackground command.
Renamed enum values of Aspect_GradientFillMethod and defined aliases for old ones.
Changed draw mode in OpenGl_BackgroundArray from triangle-strip to GL_TRIANGLES.
This commit is contained in:
achesnok 2021-09-21 18:42:21 +03:00 committed by kgv
parent 3be25c1170
commit 9af0d66b84
11 changed files with 182 additions and 101 deletions

View File

@ -22,7 +22,7 @@ Aspect_GradientBackground::Aspect_GradientBackground () {
SetColor( Black ); SetColor( Black );
MyColor2 = Black; MyColor2 = Black;
MyGradientMethod = Aspect_GFM_NONE; MyGradientMethod = Aspect_GradientFillMethod_None;
} }

View File

@ -16,38 +16,33 @@
#ifndef _Aspect_GradientBackground_HeaderFile #ifndef _Aspect_GradientBackground_HeaderFile
#define _Aspect_GradientBackground_HeaderFile #define _Aspect_GradientBackground_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Quantity_Color.hxx>
#include <Aspect_GradientFillMethod.hxx> #include <Aspect_GradientFillMethod.hxx>
#include <Aspect_Background.hxx> #include <Aspect_Background.hxx>
class Quantity_Color;
//! This class allows the definition of a window gradient background.
//! This class allows the definition of
//! a window gradient background.
class Aspect_GradientBackground : public Aspect_Background class Aspect_GradientBackground : public Aspect_Background
{ {
public: public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Creates a window gradient background. //! Creates a window gradient background.
//! Default colors : Quantity_NOC_BLACK. //! Default color is Quantity_NOC_BLACK.
//! Default fill method : Aspect_GFM_NONE //! Default fill method is Aspect_GradientFillMethod_None.
Standard_EXPORT Aspect_GradientBackground(); Standard_EXPORT Aspect_GradientBackground();
//! Creates a window gradient background with colours <AColor1, AColor2>. //! Creates a window gradient background with two colours.
Standard_EXPORT Aspect_GradientBackground(const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AMethod = Aspect_GFM_HOR); Standard_EXPORT Aspect_GradientBackground (const Quantity_Color& theColor1,
const Quantity_Color& theColor2,
const Aspect_GradientFillMethod theMethod = Aspect_GradientFillMethod_Horizontal);
//! Modifies the colours of the window gradient background <me>. //! Modifies the colours of the window gradient background.
Standard_EXPORT void SetColors (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AMethod = Aspect_GFM_HOR); Standard_EXPORT void SetColors (const Quantity_Color& theColor1,
const Quantity_Color& theColor2,
const Aspect_GradientFillMethod theMethod = Aspect_GradientFillMethod_Horizontal);
//! Returns colours of the window gradient background <me>. //! Returns colours of the window gradient background.
Standard_EXPORT void Colors (Quantity_Color& AColor1, Quantity_Color& AColor2) const; Standard_EXPORT void Colors (Quantity_Color& theColor1, Quantity_Color& theColor2) const;
//! Returns the current gradient background fill mode. //! Returns the current gradient background fill mode.
Standard_EXPORT Aspect_GradientFillMethod BgGradientFillMethod() const; Standard_EXPORT Aspect_GradientFillMethod BgGradientFillMethod() const;
@ -55,29 +50,11 @@ public:
//! Dumps the content of me into the stream //! Dumps the content of me into the stream
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
protected:
private: private:
Quantity_Color MyColor2; Quantity_Color MyColor2;
Aspect_GradientFillMethod MyGradientMethod; Aspect_GradientFillMethod MyGradientMethod;
}; };
#endif // _Aspect_GradientBackground_HeaderFile #endif // _Aspect_GradientBackground_HeaderFile

View File

@ -16,19 +16,30 @@
#ifndef _Aspect_GradientFillMethod_HeaderFile #ifndef _Aspect_GradientFillMethod_HeaderFile
#define _Aspect_GradientFillMethod_HeaderFile #define _Aspect_GradientFillMethod_HeaderFile
//! Defines the fill methods to //! Defines the fill methods to write gradient background in a window.
//! write gradient background in a window.
enum Aspect_GradientFillMethod enum Aspect_GradientFillMethod
{ {
Aspect_GFM_NONE, Aspect_GradientFillMethod_None, //!< fill method not specified
Aspect_GFM_HOR, Aspect_GradientFillMethod_Horizontal, //!< gradient directed from left (Color1) to right (Color2)
Aspect_GFM_VER, Aspect_GradientFillMethod_Vertical, //!< gradient directed from top (Color1) to bottom (Color2)
Aspect_GFM_DIAG1, Aspect_GradientFillMethod_Diagonal1, //!< gradient directed from upper left corner (Color1) to lower right (Color2)
Aspect_GFM_DIAG2, Aspect_GradientFillMethod_Diagonal2, //!< gradient directed from upper right corner (Color1) to lower left (Color2)
Aspect_GFM_CORNER1, Aspect_GradientFillMethod_Corner1, //!< highlights upper left corner with Color1
Aspect_GFM_CORNER2, Aspect_GradientFillMethod_Corner2, //!< highlights upper right corner with Color1
Aspect_GFM_CORNER3, Aspect_GradientFillMethod_Corner3, //!< highlights lower right corner with Color1
Aspect_GFM_CORNER4 Aspect_GradientFillMethod_Corner4, //!< highlights lower left corner with Color1
Aspect_GradientFillMethod_Elliptical, //!< gradient directed from center (Color1) in all directions forming an elliptic shape (Color2)
// obsolete aliases
Aspect_GFM_NONE = Aspect_GradientFillMethod_None,
Aspect_GFM_HOR = Aspect_GradientFillMethod_Horizontal,
Aspect_GFM_VER = Aspect_GradientFillMethod_Vertical,
Aspect_GFM_DIAG1 = Aspect_GradientFillMethod_Diagonal1,
Aspect_GFM_DIAG2 = Aspect_GradientFillMethod_Diagonal2,
Aspect_GFM_CORNER1 = Aspect_GradientFillMethod_Corner1,
Aspect_GFM_CORNER2 = Aspect_GradientFillMethod_Corner2,
Aspect_GFM_CORNER3 = Aspect_GradientFillMethod_Corner3,
Aspect_GFM_CORNER4 = Aspect_GradientFillMethod_Corner4
}; };
#endif // _Aspect_GradientFillMethod_HeaderFile #endif // _Aspect_GradientFillMethod_HeaderFile

View File

@ -25,19 +25,19 @@
// purpose : // purpose :
// ======================================================================= // =======================================================================
OpenGl_BackgroundArray::OpenGl_BackgroundArray (const Graphic3d_TypeOfBackground theType) OpenGl_BackgroundArray::OpenGl_BackgroundArray (const Graphic3d_TypeOfBackground theType)
: OpenGl_PrimitiveArray (NULL, Graphic3d_TOPA_TRIANGLESTRIPS, NULL, NULL, NULL), : OpenGl_PrimitiveArray (NULL, Graphic3d_TOPA_TRIANGLES, NULL, NULL, NULL),
myType (theType), myType (theType),
myFillMethod (Aspect_FM_NONE), myFillMethod (Aspect_FM_NONE),
myViewWidth (0), myViewWidth (0),
myViewHeight (0), myViewHeight (0),
myToUpdate (Standard_False) myToUpdate (Standard_False)
{ {
myDrawMode = GL_TRIANGLE_STRIP; myDrawMode = GL_TRIANGLES;
myIsFillType = true; myIsFillType = true;
myGradientParams.color1 = OpenGl_Vec4 (0.0f, 0.0f, 0.0f, 1.0f); myGradientParams.color1 = OpenGl_Vec4 (0.0f, 0.0f, 0.0f, 1.0f);
myGradientParams.color2 = OpenGl_Vec4 (0.0f, 0.0f, 0.0f, 1.0f); myGradientParams.color2 = OpenGl_Vec4 (0.0f, 0.0f, 0.0f, 1.0f);
myGradientParams.type = Aspect_GFM_NONE; myGradientParams.type = Aspect_GradientFillMethod_None;
} }
// ======================================================================= // =======================================================================
@ -112,7 +112,7 @@ bool OpenGl_BackgroundArray::IsDefined() const
{ {
switch (myType) switch (myType)
{ {
case Graphic3d_TOB_GRADIENT: return myGradientParams.type != Aspect_GFM_NONE; case Graphic3d_TOB_GRADIENT: return myGradientParams.type != Aspect_GradientFillMethod_None;
case Graphic3d_TOB_TEXTURE: return myFillMethod != Aspect_FM_NONE; case Graphic3d_TOB_TEXTURE: return myFillMethod != Aspect_FM_NONE;
case Graphic3d_TOB_CUBEMAP: return Standard_True; case Graphic3d_TOB_CUBEMAP: return Standard_True;
case Graphic3d_TOB_NONE: return Standard_False; case Graphic3d_TOB_NONE: return Standard_False;
@ -136,6 +136,16 @@ void OpenGl_BackgroundArray::invalidateData()
Standard_Boolean OpenGl_BackgroundArray::init (const Handle(OpenGl_Workspace)& theWorkspace) const Standard_Boolean OpenGl_BackgroundArray::init (const Handle(OpenGl_Workspace)& theWorkspace) const
{ {
const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
if (myIndices.IsNull())
{
myIndices = new Graphic3d_IndexBuffer (Graphic3d_Buffer::DefaultAllocator());
}
if (myAttribs.IsNull())
{
myAttribs = new Graphic3d_Buffer (Graphic3d_Buffer::DefaultAllocator());
}
switch (myType) switch (myType)
{ {
case Graphic3d_TOB_GRADIENT: case Graphic3d_TOB_GRADIENT:
@ -195,10 +205,6 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG
{ Graphic3d_TOA_COLOR, Graphic3d_TOD_VEC3 } { Graphic3d_TOA_COLOR, Graphic3d_TOD_VEC3 }
}; };
if (myAttribs.IsNull())
{
myAttribs = new Graphic3d_Buffer (Graphic3d_Buffer::DefaultAllocator());
}
if (!myAttribs->Init (4, aGragientAttribInfo, 2)) if (!myAttribs->Init (4, aGragientAttribInfo, 2))
{ {
return Standard_False; return Standard_False;
@ -218,7 +224,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG
switch (myGradientParams.type) switch (myGradientParams.type)
{ {
case Aspect_GFM_HOR: case Aspect_GradientFillMethod_Horizontal:
{ {
aCorners[0] = myGradientParams.color2.ChangeData(); aCorners[0] = myGradientParams.color2.ChangeData();
aCorners[1] = myGradientParams.color2.ChangeData(); aCorners[1] = myGradientParams.color2.ChangeData();
@ -226,7 +232,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG
aCorners[3] = myGradientParams.color1.ChangeData(); aCorners[3] = myGradientParams.color1.ChangeData();
break; break;
} }
case Aspect_GFM_VER: case Aspect_GradientFillMethod_Vertical:
{ {
aCorners[0] = myGradientParams.color2.ChangeData(); aCorners[0] = myGradientParams.color2.ChangeData();
aCorners[1] = myGradientParams.color1.ChangeData(); aCorners[1] = myGradientParams.color1.ChangeData();
@ -234,7 +240,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG
aCorners[3] = myGradientParams.color1.ChangeData(); aCorners[3] = myGradientParams.color1.ChangeData();
break; break;
} }
case Aspect_GFM_DIAG1: case Aspect_GradientFillMethod_Diagonal1:
{ {
aCorners[0] = myGradientParams.color2.ChangeData(); aCorners[0] = myGradientParams.color2.ChangeData();
aCorners[3] = myGradientParams.color1.ChangeData(); aCorners[3] = myGradientParams.color1.ChangeData();
@ -245,7 +251,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG
aCorners[2] = aDiagCorner2; aCorners[2] = aDiagCorner2;
break; break;
} }
case Aspect_GFM_DIAG2: case Aspect_GradientFillMethod_Diagonal2:
{ {
aCorners[1] = myGradientParams.color1.ChangeData(); aCorners[1] = myGradientParams.color1.ChangeData();
aCorners[2] = myGradientParams.color2.ChangeData(); aCorners[2] = myGradientParams.color2.ChangeData();
@ -256,7 +262,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG
aCorners[3] = aDiagCorner2; aCorners[3] = aDiagCorner2;
break; break;
} }
case Aspect_GFM_CORNER1: case Aspect_GradientFillMethod_Corner1:
{ {
aVertices[0] = OpenGl_Vec2(float(myViewWidth), float(myViewHeight)); aVertices[0] = OpenGl_Vec2(float(myViewWidth), float(myViewHeight));
aVertices[1] = OpenGl_Vec2(0.0f, float(myViewHeight)); aVertices[1] = OpenGl_Vec2(0.0f, float(myViewHeight));
@ -269,7 +275,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG
aCorners[3] = myGradientParams.color2.ChangeData(); aCorners[3] = myGradientParams.color2.ChangeData();
break; break;
} }
case Aspect_GFM_CORNER2: case Aspect_GradientFillMethod_Corner2:
{ {
aCorners[0] = myGradientParams.color2.ChangeData(); aCorners[0] = myGradientParams.color2.ChangeData();
aCorners[1] = myGradientParams.color1.ChangeData(); aCorners[1] = myGradientParams.color1.ChangeData();
@ -277,7 +283,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG
aCorners[3] = myGradientParams.color2.ChangeData(); aCorners[3] = myGradientParams.color2.ChangeData();
break; break;
} }
case Aspect_GFM_CORNER3: case Aspect_GradientFillMethod_Corner3:
{ {
aVertices[0] = OpenGl_Vec2(float(myViewWidth), float(myViewHeight)); aVertices[0] = OpenGl_Vec2(float(myViewWidth), float(myViewHeight));
aVertices[1] = OpenGl_Vec2(0.0f, float(myViewHeight)); aVertices[1] = OpenGl_Vec2(0.0f, float(myViewHeight));
@ -290,7 +296,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG
aCorners[3] = myGradientParams.color2.ChangeData(); aCorners[3] = myGradientParams.color2.ChangeData();
break; break;
} }
case Aspect_GFM_CORNER4: case Aspect_GradientFillMethod_Corner4:
{ {
aCorners[0] = myGradientParams.color2.ChangeData(); aCorners[0] = myGradientParams.color2.ChangeData();
aCorners[1] = myGradientParams.color2.ChangeData(); aCorners[1] = myGradientParams.color2.ChangeData();
@ -298,7 +304,53 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG
aCorners[3] = myGradientParams.color2.ChangeData(); aCorners[3] = myGradientParams.color2.ChangeData();
break; break;
} }
case Aspect_GFM_NONE: case Aspect_GradientFillMethod_Elliptical:
{
// construction of a circle circumscribed about a view rectangle
// using parametric equation (scaled by aspect ratio and centered)
const Standard_Integer aSubdiv = 64;
if (!myAttribs->Init (aSubdiv + 2, aGragientAttribInfo, 2))
{
return Standard_False;
}
OpenGl_Vec2 anEllipVerts[aSubdiv + 2];
anEllipVerts[0] = OpenGl_Vec2 (float (myViewWidth) / 2.0f, float (myViewHeight) / 2.0f);
Standard_Real aTetta = (M_PI * 2.0) / aSubdiv;
Standard_Real aParam = 0.0;
for (Standard_Integer anIt = 1; anIt < aSubdiv + 2; ++anIt)
{
anEllipVerts[anIt] = OpenGl_Vec2 (float (Cos (aParam) * Sqrt (2.0) * myViewWidth / 2.0 + myViewWidth / 2.0f),
float (Sin (aParam) * Sqrt (2.0) * myViewHeight / 2.0 + myViewHeight / 2.0f));
aParam += aTetta;
}
for (Standard_Integer anIt = 0; anIt < aSubdiv + 2; ++anIt)
{
OpenGl_Vec2* aVertData = reinterpret_cast<OpenGl_Vec2*>(myAttribs->changeValue (anIt));
*aVertData = anEllipVerts[anIt];
OpenGl_Vec3* aColorData = reinterpret_cast<OpenGl_Vec3*>(myAttribs->changeValue (anIt) + myAttribs->AttributeOffset (1));
*aColorData = myGradientParams.color2.rgb();
}
// the central vertex is colored in different way
OpenGl_Vec3* aColorData = reinterpret_cast<OpenGl_Vec3*>(myAttribs->changeValue (0) + myAttribs->AttributeOffset (1));
*aColorData = myGradientParams.color1.rgb();
if (!myIndices->Init<unsigned short> (3 * aSubdiv))
{
return Standard_False;
}
for (Standard_Integer aCurTri = 0; aCurTri < aSubdiv; aCurTri++)
{
myIndices->SetIndex (aCurTri * 3 + 0, 0);
myIndices->SetIndex (aCurTri * 3 + 1, aCurTri + 1);
myIndices->SetIndex (aCurTri * 3 + 2, aCurTri + 2);
}
return Standard_True;
}
case Aspect_GradientFillMethod_None:
{ {
break; break;
} }
@ -313,6 +365,15 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG
*aColorData = theCtx->Vec4FromQuantityColor (OpenGl_Vec4(aCorners[anIt][0], aCorners[anIt][1], aCorners[anIt][2], 1.0f)).rgb(); *aColorData = theCtx->Vec4FromQuantityColor (OpenGl_Vec4(aCorners[anIt][0], aCorners[anIt][1], aCorners[anIt][2], 1.0f)).rgb();
} }
if (!myIndices->Init<unsigned short>(6))
{
return Standard_False;
}
const unsigned short THE_FS_QUAD_TRIS[6] = {0, 1, 2, 1, 3, 2};
for (unsigned int aVertIter = 0; aVertIter < 6; ++aVertIter)
{
myIndices->SetIndex (aVertIter, THE_FS_QUAD_TRIS[aVertIter]);
}
return Standard_True; return Standard_True;
} }
@ -328,10 +389,6 @@ Standard_Boolean OpenGl_BackgroundArray::createTextureArray (const Handle(OpenGl
{ Graphic3d_TOA_UV, Graphic3d_TOD_VEC2 } { Graphic3d_TOA_UV, Graphic3d_TOD_VEC2 }
}; };
if (myAttribs.IsNull())
{
myAttribs = new Graphic3d_Buffer (Graphic3d_Buffer::DefaultAllocator());
}
if (!myAttribs->Init (4, aTextureAttribInfo, 2)) if (!myAttribs->Init (4, aTextureAttribInfo, 2))
{ {
return Standard_False; return Standard_False;
@ -386,6 +443,16 @@ Standard_Boolean OpenGl_BackgroundArray::createTextureArray (const Handle(OpenGl
aData[0] = OpenGl_Vec2 (-anOffsetX, aCoef * anOffsetY); aData[0] = OpenGl_Vec2 (-anOffsetX, aCoef * anOffsetY);
aData[1] = OpenGl_Vec2 (0.0f, aCoef * aTexRangeY); aData[1] = OpenGl_Vec2 (0.0f, aCoef * aTexRangeY);
if (!myIndices->Init<unsigned short>(6))
{
return Standard_False;
}
const unsigned short THE_FS_QUAD_TRIS[6] = {0, 1, 2, 1, 3, 2};
for (unsigned int aVertIter = 0; aVertIter < 6; ++aVertIter)
{
myIndices->SetIndex (aVertIter, THE_FS_QUAD_TRIS[aVertIter]);
}
return Standard_True; return Standard_True;
} }
@ -406,7 +473,7 @@ Standard_Boolean OpenGl_BackgroundArray::createCubeMapArray() const
myIndices = new Graphic3d_IndexBuffer (Graphic3d_Buffer::DefaultAllocator()); myIndices = new Graphic3d_IndexBuffer (Graphic3d_Buffer::DefaultAllocator());
} }
if (!myAttribs->Init (8, aCubeMapAttribInfo, 1) if (!myAttribs->Init (8, aCubeMapAttribInfo, 1)
|| !myIndices->Init<unsigned short> (14)) || !myIndices->Init<unsigned short> (6 * 3 * 2))
{ {
return Standard_False; return Standard_False;
} }
@ -423,10 +490,18 @@ Standard_Boolean OpenGl_BackgroundArray::createCubeMapArray() const
aData[7].SetValues ( 1.0, 1.0, -1.0); aData[7].SetValues ( 1.0, 1.0, -1.0);
} }
{ {
const unsigned short THE_BOX_TRISTRIP[14] = { 0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1 }; const unsigned short THE_BOX_TRIS[] =
for (unsigned int aVertIter = 0; aVertIter < 14; ++aVertIter)
{ {
myIndices->SetIndex (aVertIter, THE_BOX_TRISTRIP[aVertIter]); 0, 1, 2, 2, 1, 3, // top face
1, 5, 7, 1, 7, 3, // right face
0, 6, 4, 0, 2, 6, // left face
4, 6, 5, 6, 7, 5, // bottom face
0, 5, 1, 0, 4, 5, // front face
2, 7, 6, 2, 3, 7 // back face
};
for (unsigned int aVertIter = 0; aVertIter < 6 * 3 * 2; ++aVertIter)
{
myIndices->SetIndex (aVertIter, THE_BOX_TRIS[aVertIter]);
} }
} }

View File

@ -967,7 +967,7 @@ void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace,
|| myBackgroundType == Graphic3d_TOB_TEXTURE) || myBackgroundType == Graphic3d_TOB_TEXTURE)
{ {
// Drawing background gradient if: // Drawing background gradient if:
// - gradient fill type is not Aspect_GFM_NONE and // - gradient fill type is not Aspect_GradientFillMethod_None and
// - either background texture is no specified or it is drawn in Aspect_FM_CENTERED mode // - either background texture is no specified or it is drawn in Aspect_FM_CENTERED mode
if (myBackgrounds[Graphic3d_TOB_GRADIENT]->IsDefined() if (myBackgrounds[Graphic3d_TOB_GRADIENT]->IsDefined()
&& (!myTextureParams->Aspect()->ToMapTexture() && (!myTextureParams->Aspect()->ToMapTexture()

View File

@ -188,11 +188,11 @@ public:
//! and the fill method (horizontal by default). //! and the fill method (horizontal by default).
Standard_EXPORT void SetBgGradientColors (const Quantity_Color& theColor1, Standard_EXPORT void SetBgGradientColors (const Quantity_Color& theColor1,
const Quantity_Color& theColor2, const Quantity_Color& theColor2,
const Aspect_GradientFillMethod theFillStyle = Aspect_GFM_HOR, const Aspect_GradientFillMethod theFillStyle = Aspect_GradientFillMethod_Horizontal,
const Standard_Boolean theToUpdate = Standard_False); const Standard_Boolean theToUpdate = Standard_False);
//! Defines the gradient background fill method of the view. //! Defines the gradient background fill method of the view.
Standard_EXPORT void SetBgGradientStyle (const Aspect_GradientFillMethod theMethod = Aspect_GFM_HOR, Standard_EXPORT void SetBgGradientStyle (const Aspect_GradientFillMethod theMethod = Aspect_GradientFillMethod_Horizontal,
const Standard_Boolean theToUpdate = Standard_False); const Standard_Boolean theToUpdate = Standard_False);
//! Defines the background texture of the view by supplying the texture image file name //! Defines the background texture of the view by supplying the texture image file name

View File

@ -130,7 +130,7 @@ public:
//! attached to the viewer by supplying the colour objects //! attached to the viewer by supplying the colour objects
void SetDefaultBgGradientColors (const Quantity_Color& theColor1, void SetDefaultBgGradientColors (const Quantity_Color& theColor1,
const Quantity_Color& theColor2, const Quantity_Color& theColor2,
const Aspect_GradientFillMethod theFillStyle = Aspect_GFM_HOR) const Aspect_GradientFillMethod theFillStyle = Aspect_GradientFillMethod_Horizontal)
{ {
myGradientBackground.SetColors (theColor1, theColor2, theFillStyle); myGradientBackground.SetColors (theColor1, theColor2, theFillStyle);
} }

View File

@ -926,7 +926,7 @@ static Standard_Integer VListColors (Draw_Interpretor& theDI,
ViewerTest::ViewerInit (0, 0, anImgParams.Width, anImgParams.Height, "TmpDriver/TmpViewer/TmpView"); ViewerTest::ViewerInit (0, 0, anImgParams.Width, anImgParams.Height, "TmpDriver/TmpViewer/TmpView");
aView = ViewerTest::CurrentView(); aView = ViewerTest::CurrentView();
aView->SetImmediateUpdate (false); aView->SetImmediateUpdate (false);
aView->SetBgGradientStyle (Aspect_GFM_NONE, false); aView->SetBgGradientStyle (Aspect_GradientFillMethod_None, false);
} }
if (!aDumpFile.IsEmpty()) if (!aDumpFile.IsEmpty())

View File

@ -214,7 +214,7 @@ static struct
} }
} }
} ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE }; } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GradientFillMethod_None };
//============================================================================== //==============================================================================
// EVENT GLOBAL VARIABLES // EVENT GLOBAL VARIABLES
@ -2613,46 +2613,51 @@ static bool parseGradientMode (const TCollection_AsciiString& theName,
aName.LowerCase(); aName.LowerCase();
if (aName == "none") if (aName == "none")
{ {
theMode = Aspect_GFM_NONE; theMode = Aspect_GradientFillMethod_None;
} }
else if (aName == "hor" else if (aName == "hor"
|| aName == "horizontal") || aName == "horizontal")
{ {
theMode = Aspect_GFM_HOR; theMode = Aspect_GradientFillMethod_Horizontal;
} }
else if (aName == "ver" else if (aName == "ver"
|| aName == "vert" || aName == "vert"
|| aName == "vertical") || aName == "vertical")
{ {
theMode = Aspect_GFM_VER; theMode = Aspect_GradientFillMethod_Vertical;
} }
else if (aName == "diag" else if (aName == "diag"
|| aName == "diagonal" || aName == "diagonal"
|| aName == "diag1" || aName == "diag1"
|| aName == "diagonal1") || aName == "diagonal1")
{ {
theMode = Aspect_GFM_DIAG1; theMode = Aspect_GradientFillMethod_Diagonal1;
} }
else if (aName == "diag2" else if (aName == "diag2"
|| aName == "diagonal2") || aName == "diagonal2")
{ {
theMode = Aspect_GFM_DIAG2; theMode = Aspect_GradientFillMethod_Diagonal2;
} }
else if (aName == "corner1") else if (aName == "corner1")
{ {
theMode = Aspect_GFM_CORNER1; theMode = Aspect_GradientFillMethod_Corner1;
} }
else if (aName == "corner2") else if (aName == "corner2")
{ {
theMode = Aspect_GFM_CORNER2; theMode = Aspect_GradientFillMethod_Corner2;
} }
else if (aName == "corner3") else if (aName == "corner3")
{ {
theMode = Aspect_GFM_CORNER3; theMode = Aspect_GradientFillMethod_Corner3;
} }
else if (aName == "corner4") else if (aName == "corner4")
{ {
theMode = Aspect_GFM_CORNER4; theMode = Aspect_GradientFillMethod_Corner4;
}
else if (aName == "ellip"
|| aName == "elliptical")
{
theMode = Aspect_GradientFillMethod_Elliptical;
} }
else else
{ {
@ -2680,7 +2685,7 @@ static int VBackground (Draw_Interpretor& theDI,
Standard_Integer aNbColors = 0; Standard_Integer aNbColors = 0;
Quantity_ColorRGBA aColors[2]; Quantity_ColorRGBA aColors[2];
Aspect_GradientFillMethod aGradientMode = Aspect_GFM_NONE; Aspect_GradientFillMethod aGradientMode = Aspect_GradientFillMethod_None;
bool hasGradientMode = false; bool hasGradientMode = false;
TCollection_AsciiString anImagePath; TCollection_AsciiString anImagePath;
@ -2891,14 +2896,14 @@ static int VBackground (Draw_Interpretor& theDI,
{ {
ViewerTest_DefaultBackground.GradientColor1 = Quantity_Color(); ViewerTest_DefaultBackground.GradientColor1 = Quantity_Color();
ViewerTest_DefaultBackground.GradientColor2 = Quantity_Color(); ViewerTest_DefaultBackground.GradientColor2 = Quantity_Color();
ViewerTest_DefaultBackground.FillMethod = Aspect_GFM_NONE; ViewerTest_DefaultBackground.FillMethod = Aspect_GradientFillMethod_None;
ViewerTest_DefaultBackground.FlatColor = aColors[0].GetRGB(); ViewerTest_DefaultBackground.FlatColor = aColors[0].GetRGB();
ViewerTest_DefaultBackground.SetDefaultGradient(); ViewerTest_DefaultBackground.SetDefaultGradient();
ViewerTest_DefaultBackground.SetDefaultColor(); ViewerTest_DefaultBackground.SetDefaultColor();
} }
else else
{ {
aView->SetBgGradientStyle (hasGradientMode ? aGradientMode : Aspect_GFM_NONE); aView->SetBgGradientStyle (hasGradientMode ? aGradientMode : Aspect_GradientFillMethod_None);
aView->SetBackgroundColor (aColors[0].GetRGB()); aView->SetBackgroundColor (aColors[0].GetRGB());
} }
} }
@ -2912,9 +2917,9 @@ static int VBackground (Draw_Interpretor& theDI,
{ {
ViewerTest_DefaultBackground.FillMethod = aGradientMode; ViewerTest_DefaultBackground.FillMethod = aGradientMode;
} }
else if (ViewerTest_DefaultBackground.FillMethod == Aspect_GFM_NONE) else if (ViewerTest_DefaultBackground.FillMethod == Aspect_GradientFillMethod_None)
{ {
ViewerTest_DefaultBackground.FillMethod = Aspect_GFM_VER; ViewerTest_DefaultBackground.FillMethod = Aspect_GradientFillMethod_Vertical;
} }
ViewerTest_DefaultBackground.SetDefaultGradient(); ViewerTest_DefaultBackground.SetDefaultGradient();
} }
@ -2923,9 +2928,9 @@ static int VBackground (Draw_Interpretor& theDI,
if (!hasGradientMode) if (!hasGradientMode)
{ {
aGradientMode = aView->GradientBackground().BgGradientFillMethod(); aGradientMode = aView->GradientBackground().BgGradientFillMethod();
if (aGradientMode == Aspect_GFM_NONE) if (aGradientMode == Aspect_GradientFillMethod_None)
{ {
aGradientMode = Aspect_GFM_VER; aGradientMode = Aspect_GradientFillMethod_Vertical;
} }
} }
aView->SetBgGradientColors (aColors[0].GetRGB(), aColors[1].GetRGB(), aGradientMode); aView->SetBgGradientColors (aColors[0].GetRGB(), aColors[1].GetRGB(), aGradientMode);
@ -13654,7 +13659,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
theCommands.Add ("vbackground", theCommands.Add ("vbackground",
"vbackground [-color Color [-default]]" "vbackground [-color Color [-default]]"
"\n\t\t: [-gradient Color1 Color2 [-default]" "\n\t\t: [-gradient Color1 Color2 [-default]"
"\n\t\t: [-gradientMode {NONE|HORIZONTAL|VERTICAL|DIAG1|DIAG2|CORNER1|CORNER2|CORNER3}]=VERT]" "\n\t\t: [-gradientMode {NONE|HORIZONTAL|VERTICAL|DIAG1|DIAG2|CORNER1|CORNER2|CORNER3|ELLIPTICAL}]=VERT]"
"\n\t\t: [-imageFile ImageFile [-imageMode {CENTERED|TILED|STRETCH|NONE}]=CENTERED [-srgb {0|1}]=1]" "\n\t\t: [-imageFile ImageFile [-imageMode {CENTERED|TILED|STRETCH|NONE}]=CENTERED [-srgb {0|1}]=1]"
"\n\t\t: [-cubemap CubemapFile1 [CubeMapFiles2-5] [-order TilesIndexes1-6] [-invertedz]=0 [-pbrEnv {0|1}]=1]" "\n\t\t: [-cubemap CubemapFile1 [CubeMapFiles2-5] [-order TilesIndexes1-6] [-invertedz]=0 [-pbrEnv {0|1}]=1]"
"\n\t\t: Changes background or some background settings." "\n\t\t: Changes background or some background settings."

View File

@ -7,10 +7,13 @@ pload VISUALIZATION
vbackground -default -gradient BLACK GRAY25 -gradientMode HORIZONTAL vbackground -default -gradient BLACK GRAY25 -gradientMode HORIZONTAL
vinit View1 w=400 h=400 vinit View1 w=400 h=400
if { [vreadpixel 399 100 -rgb -name] != "GRAY25" } { puts "Error: bug with default gradient color is reproduced." } if { [vreadpixel 399 100 -rgb -name] != "GRAY25" } { puts "Error: bug with default gradient color is reproduced." }
vdump $imagedir/${casename}_v1.png
vinit View2 w=400 h=400 vinit View2 w=400 h=400
if { [vreadpixel 399 100 -rgb -name] != "GRAY25" } { puts "Error: bug with default gradient color is reproduced." } if { [vreadpixel 399 100 -rgb -name] != "GRAY25" } { puts "Error: bug with default gradient color is reproduced." }
vdump $imagedir/${casename}_v2.png
vbackground -default -color GRAY50 vbackground -default -color GRAY50
vinit View3 vinit View3
if { [vreadpixel 100 100 -rgb -name] != "GRAY50" } { puts "Error: bug with default background color is reproduced." } if { [vreadpixel 100 100 -rgb -name] != "GRAY50" } { puts "Error: bug with default background color is reproduced." }
vdump $imagedir/${casename}_v3.png

View File

@ -0,0 +1,10 @@
puts "============"
puts "0031039: Visualization - add elliptical gradient background style"
puts "============"
puts ""
pload VISUALIZATION
vinit View1
vbackground -gradient WHITE BLACK -gradientMode ELLIPTICAL
vdump $imagedir/${casename}.png