35#include <nlohmann/json_fwd.hpp>
121 COLOR4D(
double aRed,
double aGreen,
double aBlue,
double aAlpha ) :
127 wxASSERT( r >= 0.0 && r <= 1.0 );
128 wxASSERT( g >= 0.0 && g <= 1.0 );
129 wxASSERT( b >= 0.0 && b <= 1.0 );
130 wxASSERT( a >= 0.0 && a <= 1.0 );
146 COLOR4D& FromCSSRGBA(
int aRed,
int aGreen,
int aBlue,
double aAlpha = 1.0 );
152 COLOR4D(
const wxString& aColorStr );
157 COLOR4D(
const wxColour& aColor );
165 bool SetFromWxString(
const wxString& aColorString );
167 wxString ToCSSString()
const;
169 bool SetFromHexString(
const wxString& aColorString );
170 wxString ToHexString()
const;
172 wxColour ToColour()
const;
192 void ToHSL(
double& aOutHue,
double& aOutSaturation,
double& aOutLightness )
const;
201 void FromHSL(
double aInHue,
double aInSaturation,
double aInLightness );
211 wxASSERT( aFactor >= 0.0 && aFactor <= 1.0 );
213 r = r * ( 1.0 - aFactor ) + aFactor;
214 g = g * ( 1.0 - aFactor ) + aFactor;
215 b = b * ( 1.0 - aFactor ) + aFactor;
228 wxASSERT( aFactor >= 0.0 && aFactor <= 1.0 );
230 r = r * ( 1.0 - aFactor );
231 g = g * ( 1.0 - aFactor );
232 b = b * ( 1.0 - aFactor );
254 COLOR4D& Saturate(
double aFactor );
270 wxASSERT( aFactor >= 0.0 && aFactor <= 1.0 );
272 return COLOR4D( r * ( 1.0 - aFactor ) + aFactor, g * ( 1.0 - aFactor ) + aFactor,
273 b * ( 1.0 - aFactor ) + aFactor, a );
284 wxASSERT( aFactor >= 0.0 && aFactor <= 1.0 );
286 return COLOR4D( r * ( 1.0 - aFactor ), g * ( 1.0 - aFactor ), b * ( 1.0 - aFactor ), a );
297 wxASSERT( aFactor >= 0.0 && aFactor <= 1.0 );
299 return COLOR4D( aColor.
r * ( 1.0 - aFactor ) + r * aFactor,
300 aColor.
g * ( 1.0 - aFactor ) + g * aFactor,
301 aColor.
b * ( 1.0 - aFactor ) + b * aFactor,
313 wxASSERT( aAlpha >= 0.0 && aAlpha <= 1.0 );
315 return COLOR4D( r, g, b, aAlpha );
325 return COLOR4D( 1.0 - r, 1.0 - g, 1.0 - b, a );
336 return r * 0.299 + g * 0.587 + b * 0.117;
351 void ToHSV(
double& aOutHue,
double& aOutSaturation,
double& aOutValue,
352 bool aAlwaysDefineHue =
false )
const;
361 void FromHSV(
double aInH,
double aInS,
double aInV );
366 double Distance(
const COLOR4D& other )
const;
368 int Compare(
const COLOR4D& aRhs )
const;
375 double RelativeLuminance()
const;
384 static double ContrastRatio(
const COLOR4D& aLeft,
const COLOR4D& aRight );
389 static EDA_COLOR_T FindNearestLegacyColor(
int aR,
int aG,
int aB );
430 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()[]
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
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)
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