35#include <nlohmann/json_fwd.hpp>
122 COLOR4D(
double aRed,
double aGreen,
double aBlue,
double aAlpha ) :
128 wxASSERT(
r >= 0.0 &&
r <= 1.0 );
129 wxASSERT(
g >= 0.0 &&
g <= 1.0 );
130 wxASSERT(
b >= 0.0 &&
b <= 1.0 );
131 wxASSERT(
a >= 0.0 &&
a <= 1.0 );
147 COLOR4D& FromCSSRGBA(
int aRed,
int aGreen,
int aBlue,
double aAlpha = 1.0 );
153 COLOR4D(
const wxString& aColorStr );
158 COLOR4D(
const wxColour& aColor );
166 bool SetFromWxString(
const wxString& aColorString );
168 wxString ToCSSString()
const;
170 bool SetFromHexString(
const wxString& aColorString );
171 wxString ToHexString()
const;
173 wxColour ToColour()
const;
193 void ToHSL(
double& aOutHue,
double& aOutSaturation,
double& aOutLightness )
const;
202 void FromHSL(
double aInHue,
double aInSaturation,
double aInLightness );
212 wxASSERT( aFactor >= 0.0 && aFactor <= 1.0 );
214 r =
r * ( 1.0 - aFactor ) + aFactor;
215 g =
g * ( 1.0 - aFactor ) + aFactor;
216 b =
b * ( 1.0 - aFactor ) + aFactor;
229 wxASSERT( aFactor >= 0.0 && aFactor <= 1.0 );
231 r =
r * ( 1.0 - aFactor );
232 g =
g * ( 1.0 - aFactor );
233 b =
b * ( 1.0 - aFactor );
255 COLOR4D& Saturate(
double aFactor );
271 wxASSERT( aFactor >= 0.0 && aFactor <= 1.0 );
273 return COLOR4D(
r * ( 1.0 - aFactor ) + aFactor,
g * ( 1.0 - aFactor ) + aFactor,
274 b * ( 1.0 - aFactor ) + aFactor,
a );
285 wxASSERT( aFactor >= 0.0 && aFactor <= 1.0 );
287 return COLOR4D(
r * ( 1.0 - aFactor ),
g * ( 1.0 - aFactor ),
b * ( 1.0 - aFactor ),
a );
298 wxASSERT( aFactor >= 0.0 && aFactor <= 1.0 );
300 return COLOR4D( aColor.
r * ( 1.0 - aFactor ) +
r * aFactor,
301 aColor.
g * ( 1.0 - aFactor ) +
g * aFactor,
302 aColor.
b * ( 1.0 - aFactor ) +
b * aFactor,
314 wxASSERT( aAlpha >= 0.0 && aAlpha <= 1.0 );
337 return r * 0.299 +
g * 0.587 +
b * 0.117;
352 void ToHSV(
double& aOutHue,
double& aOutSaturation,
double& aOutValue,
353 bool aAlwaysDefineHue =
false )
const;
362 void FromHSV(
double aInH,
double aInS,
double aInV );
367 double Distance(
const COLOR4D& other )
const;
369 int Compare(
const COLOR4D& aRhs )
const;
376 double RelativeLuminance()
const;
385 static double ContrastRatio(
const COLOR4D& aLeft,
const COLOR4D& aRight );
390 static EDA_COLOR_T FindNearestLegacyColor(
int aR,
int aG,
int aB );
431 return hash_val( aColor.
r, aColor.
b, aColor.
g, aColor.
a );
A color representation with 4 components: red, green, blue, alpha.
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
static const COLOR4D CLEAR
COLOR4D & Invert()
Makes the color inverted, alpha remains the same.
COLOR4D & Darken(double aFactor)
Makes the color darker by a given factor.
COLOR4D Darkened(double aFactor) const
Return a color that is darker by a given factor, without modifying object.
COLOR4D Inverted() const
Returns an inverted color, alpha remains the same.
COLOR4D & Brighten(double aFactor)
Makes the color brighter by a given factor.
double GetBrightness() const
Returns the brightness value of the color ranged from 0.0 to 1.0.
static const COLOR4D WHITE
COLOR4D Brightened(double aFactor) const
Return a color that is brighter by a given factor, without modifying object.
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
COLOR4D(double aRed, double aGreen, double aBlue, double aAlpha)
static const COLOR4D BLACK
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
KICOMMON_API const StructColors * colorRefs()
Global list of legacy color names, still used all over the place for constructing COLOR4D's.
EDA_COLOR_T
Legacy color enumeration.
@ NBCOLORS
Number of colors.
@ MASKCOLOR
mask for color index into colorRefs()[]
static constexpr std::size_t hash_val(const Types &... args)
The Cairo implementation of the graphics abstraction layer.
void from_json(const nlohmann::json &aJson, COLOR4D &aColor)
bool operator==(const COLOR4D &lhs, const COLOR4D &rhs)
Equality operator, are two colors equal.
void to_json(nlohmann::json &aJson, const COLOR4D &aColor)
bool operator<(const COLOR4D &lhs, const COLOR4D &rhs)
std::ostream & operator<<(std::ostream &aStream, COLOR4D const &aColor)
Syntactic sugar for outputting colors to strings.
bool operator!=(const COLOR4D &lhs, const COLOR4D &rhs)
Not equality operator, are two colors not equal.
std::size_t operator()(const KIGFX::COLOR4D &aColor) const