31 #include <nlohmann/json_fwd.hpp> 33 #ifdef WX_COMPATIBILITY 34 #include <wx/colour.h> 35 #include <wx/string.h> 103 r( 0 ),
g( 0 ),
b( 0 ),
a( 1.0 )
113 constexpr
COLOR4D(
double aRed,
double aGreen,
double aBlue,
double aAlpha ) :
114 r( aRed ),
g( aGreen ),
b( aBlue ),
a( aAlpha )
116 assert(
r >= 0.0 &&
r <= 1.0 );
117 assert(
g >= 0.0 &&
g <= 1.0 );
118 assert(
b >= 0.0 &&
b <= 1.0 );
119 assert(
a >= 0.0 &&
a <= 1.0 );
137 #ifdef WX_COMPATIBILITY 141 COLOR4D(
const wxColour& aColor );
149 bool SetFromWxString(
const wxString& aColorString );
151 wxString ToWxString(
long flags )
const;
153 wxColour ToColour()
const;
170 unsigned int ToU32()
const;
175 void FromU32(
unsigned int aPackedColor );
187 void ToHSL(
double& aOutHue,
double& aOutSaturation,
double& aOutValue )
const;
196 void FromHSL(
double aInHue,
double aInSaturation,
double aInLightness );
206 assert( aFactor >= 0.0 && aFactor <= 1.0 );
208 r =
r * ( 1.0 - aFactor ) + aFactor;
209 g =
g * ( 1.0 - aFactor ) + aFactor;
210 b =
b * ( 1.0 - aFactor ) + aFactor;
223 assert( aFactor >= 0.0 && aFactor <= 1.0 );
225 r =
r * ( 1.0 - aFactor );
226 g =
g * ( 1.0 - aFactor );
227 b =
b * ( 1.0 - aFactor );
259 assert( aFactor >= 0.0 && aFactor <= 1.0 );
261 return COLOR4D(
r * ( 1.0 - aFactor ) + aFactor,
g * ( 1.0 - aFactor ) + aFactor,
262 b * ( 1.0 - aFactor ) + aFactor,
a );
273 assert( aFactor >= 0.0 && aFactor <= 1.0 );
275 return COLOR4D(
r * ( 1.0 - aFactor ),
g * ( 1.0 - aFactor ),
b * ( 1.0 - aFactor ),
a );
286 assert( aFactor >= 0.0 && aFactor <= 1.0 );
288 return COLOR4D( aColor.
r * ( 1.0 - aFactor ) +
r * aFactor,
289 aColor.
g * ( 1.0 - aFactor ) +
g * aFactor,
290 aColor.
b * ( 1.0 - aFactor ) +
b * aFactor,
302 assert( aAlpha >= 0.0 && aAlpha <= 1.0 );
325 return r * 0.299 +
g * 0.587 +
b * 0.117;
340 void ToHSV(
double& aOutHue,
double& aOutSaturation,
double& aOutValue,
341 bool aAlwaysDefineHue =
false )
const;
350 void FromHSV(
double aInH,
double aInS,
double aInV );
COLOR4D & Invert()
Makes the color inverted, alpha remains the same.
void ToHSV(double &aOutHue, double &aOutSaturation, double &aOutValue, bool aAlwaysDefineHue=false) const
Convert current color (stored in RGB) to HSV format.
double GetBrightness() const
Returns the brightness value of the color ranged from 0.0 to 1.0.
COLOR4D & FromCSSRGBA(int aRed, int aGreen, int aBlue, double aAlpha=1.0)
Initialize the color from a RGBA value with 0-255 red/green/blue and 0-1 alpha.
COLOR4D Inverted() const
Returns an inverted color, alpha remains the same.
The Cairo implementation of the graphics abstraction layer.
COLOR4D & Brighten(double aFactor)
Makes the color brighter by a given factor.
COLOR4D & Saturate(double aFactor)
Saturates the color to a given factor (in HSV model)
mask for color index into colorRefs()[]
static const COLOR4D BLACK
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
COLOR4D Darkened(double aFactor) const
Return a color that is darker by a given factor, without modifying object.
void from_json(const nlohmann::json &aJson, COLOR4D &aColor)
const bool operator<(const COLOR4D &lhs, const COLOR4D &rhs)
COLOR4D Brightened(double aFactor) const
Return a color that is brighter by a given factor, without modifying object.
const StructColors * colorRefs()
Global list of legacy color names, still used all over the place for constructing COLOR4D's.
static const COLOR4D CLEAR
constexpr COLOR4D(double aRed, double aGreen, double aBlue, double aAlpha)
static const COLOR4D WHITE
void ToHSL(double &aOutHue, double &aOutSaturation, double &aOutValue) const
Converts current color (stored in RGB) to HSL format.
std::ostream & operator<<(std::ostream &aStream, COLOR4D const &aColor)
Syntactic sugar for outputting colors to strings.
void FromHSV(double aInH, double aInS, double aInV)
Changes currently used color to the one given by hue, saturation and value parameters.
EDA_COLOR_T
Legacy color enumeration.
void to_json(nlohmann::json &aJson, const COLOR4D &aColor)
const bool operator==(const COLOR4D &lhs, const COLOR4D &rhs)
Equality operator, are two colors equal.
COLOR4D & Darken(double aFactor)
Makes the color darker by a given factor.
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
static EDA_COLOR_T FindNearestLegacyColor(int aR, int aG, int aB)
Returns a legacy color ID that is closest to the given 8-bit RGB values.
const bool operator!=(const COLOR4D &lhs, const COLOR4D &rhs)
Not equality operator, are two colors not equal.
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
void FromHSL(double aInHue, double aInSaturation, double aInLightness)
Change currently used color to the one given by hue, saturation and lightness parameters.
A color representation with 4 components: red, green, blue, alpha.