1 // Copyright (c) 2016 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _Quantity_ColorRGBA_HeaderFile
15 #define _Quantity_ColorRGBA_HeaderFile
17 #include <Quantity_Color.hxx>
18 #include <Standard_Assert.hxx>
20 //! The pair of Quantity_Color and Alpha component (1.0 opaque, 0.0 transparent).
21 class Quantity_ColorRGBA
25 //! Creates a color with the default value.
26 Quantity_ColorRGBA() : myAlpha (1.0f) {}
28 //! Creates the color with specified RGB value.
29 explicit Quantity_ColorRGBA (const Quantity_Color& theRgb)
30 : myRgb (theRgb), myAlpha (1.0f)
33 //! Creates the color with specified RGBA values.
34 Quantity_ColorRGBA (const Quantity_Color& theRgb, float theAlpha)
35 : myRgb (theRgb), myAlpha (theAlpha)
38 //! Creates the color from RGBA vector.
39 explicit Quantity_ColorRGBA (const NCollection_Vec4<float>& theRgba)
40 : myRgb (theRgba.rgb()), myAlpha (theRgba.a())
43 //! Creates the color from RGBA values.
44 Quantity_ColorRGBA (float theRed, float theGreen, float theBlue, float theAlpha)
45 : myRgb (theRed, theGreen, theBlue, Quantity_TOC_RGB),
49 //! Assign new values to the color.
50 void SetValues (float theRed, float theGreen, float theBlue, float theAlpha)
52 myRgb.SetValues (theRed, theGreen, theBlue, Quantity_TOC_RGB);
56 //! Return RGB color value.
57 const Quantity_Color& GetRGB() const { return myRgb; }
59 //! Modify RGB color components without affecting alpha value.
60 Quantity_Color& ChangeRGB() { return myRgb; }
62 //! Assign RGB color components without affecting alpha value.
63 void SetRGB (const Quantity_Color& theRgb) { myRgb = theRgb; }
65 //! Return alpha value (1.0 means opaque, 0.0 means fully transparent).
66 Standard_ShortReal Alpha() const { return myAlpha; }
68 //! Assign the alpha value.
69 void SetAlpha (const Standard_ShortReal theAlpha) { myAlpha = theAlpha; }
71 //! Return the color as vector of 4 float elements.
72 operator const NCollection_Vec4<float>&() const { return *(const NCollection_Vec4<float>* )this; }
74 //! Returns true if the distance between colors is greater than Epsilon().
75 bool IsDifferent (const Quantity_ColorRGBA& theOther) const
77 return myRgb.IsDifferent (theOther.GetRGB())
78 || Abs(myAlpha - theOther.myAlpha) > (float )Quantity_Color::Epsilon();
81 //! Returns true if the distance between colors is greater than Epsilon().
82 bool operator!= (const Quantity_ColorRGBA& theOther) const { return IsDifferent (theOther); }
84 //! Two colors are considered to be equal if their distance is no greater than Epsilon().
85 bool IsEqual (const Quantity_ColorRGBA& theOther) const
87 return myRgb.IsEqual (theOther.GetRGB())
88 && Abs(myAlpha - theOther.myAlpha) <= (float )Quantity_Color::Epsilon();
91 //! Two colors are considered to be equal if their distance is no greater than Epsilon().
92 bool operator== (const Quantity_ColorRGBA& theOther) const { return IsEqual (theOther); }
96 static void myTestSize3() { Standard_STATIC_ASSERT (sizeof(float) * 3 == sizeof(Quantity_Color)); }
97 static void myTestSize4() { Standard_STATIC_ASSERT (sizeof(float) * 4 == sizeof(Quantity_ColorRGBA)); }
101 Quantity_Color myRgb;
102 Standard_ShortReal myAlpha;
106 #endif // _Quantity_ColorRGBA_HeaderFile