0028888: Visualization - AIS_InteractiveContext should not hold V3d_View handle which...
[occt.git] / src / Quantity / Quantity_ColorRGBA.hxx
CommitLineData
b6472664 1// Copyright (c) 2016 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
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.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#ifndef _Quantity_ColorRGBA_HeaderFile
15#define _Quantity_ColorRGBA_HeaderFile
16
17#include <Quantity_Color.hxx>
18#include <Standard_Assert.hxx>
19
20//! The pair of Quantity_Color and Alpha component (1.0 opaque, 0.0 transparent).
21class Quantity_ColorRGBA
22{
23public:
24
25 //! Creates a color with the default value.
26 Quantity_ColorRGBA() : myAlpha (1.0f) {}
27
28 //! Creates the color with specified RGB value.
29 explicit Quantity_ColorRGBA (const Quantity_Color& theRgb) : myRgb (theRgb), myAlpha (1.0f) {}
30
31 //! Creates the color from RGBA vector.
32 explicit Quantity_ColorRGBA (const NCollection_Vec4<float>& theRgba) : myRgb (theRgba.rgb()), myAlpha (theRgba.a()) {}
33
34 //! Return RGB color value.
35 const Quantity_Color& GetRGB() const { return myRgb; }
36
37 //! Modify RGB color components without affecting alpha value.
38 Quantity_Color& ChangeRGB() { return myRgb; }
39
40 //! Assign RGB color components without affecting alpha value.
41 void SetRGB (const Quantity_Color& theRgb) { myRgb = theRgb; }
42
43 //! Return alpha value (1.0 means opaque, 0.0 means fully transparent).
44 Standard_ShortReal Alpha() const { return myAlpha; }
45
46 //! Assign the alpha value.
47 void SetAlpha (const Standard_ShortReal theAlpha) { myAlpha = theAlpha; }
48
49 //! Return the color as vector of 4 float elements.
50 operator const NCollection_Vec4<float>&() const { return *(const NCollection_Vec4<float>* )this; }
51
52 //! Returns true if the distance between colors is greater than Epsilon().
53 bool IsDifferent (const Quantity_ColorRGBA& theOther) const
54 {
55 return myRgb.IsDifferent (theOther.GetRGB())
56 || Abs(myAlpha - theOther.myAlpha) > (float )Quantity_Color::Epsilon();
57 }
58
59 //! Returns true if the distance between colors is greater than Epsilon().
60 bool operator!= (const Quantity_ColorRGBA& theOther) const { return IsDifferent (theOther); }
61
62 //! Two colors are considered to be equal if their distance is no greater than Epsilon().
63 bool IsEqual (const Quantity_ColorRGBA& theOther) const
64 {
65 return myRgb.IsEqual (theOther.GetRGB())
66 && Abs(myAlpha - theOther.myAlpha) <= (float )Quantity_Color::Epsilon();
67 }
68
69 //! Two colors are considered to be equal if their distance is no greater than Epsilon().
70 bool operator== (const Quantity_ColorRGBA& theOther) const { return IsEqual (theOther); }
71
72private:
73
74 static void __testSize3() { Standard_STATIC_ASSERT (sizeof(float) * 3 == sizeof(Quantity_Color)); }
75 static void __testSize4() { Standard_STATIC_ASSERT (sizeof(float) * 4 == sizeof(Quantity_ColorRGBA)); }
76
77private:
78
79 Quantity_Color myRgb;
80 Standard_ShortReal myAlpha;
81
82};
83
84#endif // _Quantity_ColorRGBA_HeaderFile