33#include <nlohmann/json_fwd.hpp>
119 COLOR4D(
double aRed,
double aGreen,
double aBlue,
double aAlpha ) :
125 wxASSERT(
r >= 0.0 &&
r <= 1.0 );
126 wxASSERT(
g >= 0.0 &&
g <= 1.0 );
127 wxASSERT(
b >= 0.0 &&
b <= 1.0 );
128 wxASSERT(
a >= 0.0 &&
a <= 1.0 );
150 COLOR4D(
const wxString& aColorStr );
155 COLOR4D(
const wxColour& aColor );
190 void ToHSL(
double& aOutHue,
double& aOutSaturation,
double& aOutValue )
const;
199 void FromHSL(
double aInHue,
double aInSaturation,
double aInLightness );
209 wxASSERT( aFactor >= 0.0 && aFactor <= 1.0 );
211 r =
r * ( 1.0 - aFactor ) + aFactor;
212 g =
g * ( 1.0 - aFactor ) + aFactor;
213 b =
b * ( 1.0 - aFactor ) + aFactor;
226 wxASSERT( aFactor >= 0.0 && aFactor <= 1.0 );
228 r =
r * ( 1.0 - aFactor );
229 g =
g * ( 1.0 - aFactor );
230 b =
b * ( 1.0 - aFactor );
268 wxASSERT( aFactor >= 0.0 && aFactor <= 1.0 );
270 return COLOR4D(
r * ( 1.0 - aFactor ) + aFactor,
g * ( 1.0 - aFactor ) + aFactor,
271 b * ( 1.0 - aFactor ) + aFactor,
a );
282 wxASSERT( aFactor >= 0.0 && aFactor <= 1.0 );
284 return COLOR4D(
r * ( 1.0 - aFactor ),
g * ( 1.0 - aFactor ),
b * ( 1.0 - aFactor ),
a );
295 wxASSERT( aFactor >= 0.0 && aFactor <= 1.0 );
297 return COLOR4D( aColor.
r * ( 1.0 - aFactor ) +
r * aFactor,
298 aColor.
g * ( 1.0 - aFactor ) +
g * aFactor,
299 aColor.
b * ( 1.0 - aFactor ) +
b * aFactor,
311 wxASSERT( aAlpha >= 0.0 && aAlpha <= 1.0 );
334 return r * 0.299 +
g * 0.587 +
b * 0.117;
349 void ToHSV(
double& aOutHue,
double& aOutSaturation,
double& aOutValue,
350 bool aAlwaysDefineHue =
false )
const;
359 void FromHSV(
double aInH,
double aInS,
double aInV );
A color representation with 4 components: red, green, blue, alpha.
void ToHSL(double &aOutHue, double &aOutSaturation, double &aOutValue) const
Converts current color (stored in RGB) to HSL format.
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.
void ToHSV(double &aOutHue, double &aOutSaturation, double &aOutValue, bool aAlwaysDefineHue=false) const
Convert current color (stored in RGB) to HSV format.
bool SetFromWxString(const wxString &aColorString)
Set color values by parsing a string using wxColour::Set().
bool SetFromHexString(const wxString &aColorString)
COLOR4D LegacyMix(const COLOR4D &aColor) const
Mix this COLOR4D with an input COLOR4D using the OR-mixing of legacy canvas.
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.
void FromHSV(double aInH, double aInS, double aInV)
Changes currently used color to the one given by hue, saturation and value parameters.
COLOR4D & Darken(double aFactor)
Makes the color darker by a given factor.
wxString ToHexString() const
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.
wxString ToCSSString() const
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.
wxColour ToColour() const
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
COLOR4D & Desaturate()
Removes color (in HSL model)
COLOR4D(double aRed, double aGreen, double aBlue, double aAlpha)
double Distance(const COLOR4D &other) const
Returns the distance (in RGB space) between two colors.
void FromHSL(double aInHue, double aInSaturation, double aInLightness)
Change currently used color to the one given by hue, saturation and lightness parameters.
static const COLOR4D BLACK
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
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 & Saturate(double aFactor)
Saturates the color to a given factor (in HSV model)
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()[]
The Cairo implementation of the graphics abstraction layer.
void from_json(const nlohmann::json &aJson, COLOR4D &aColor)
std::ostream & operator<<(std::ostream &aStream, COLOR4D const &aColor)
Syntactic sugar for outputting colors to strings.
const bool operator<(const COLOR4D &lhs, const COLOR4D &rhs)
const bool operator==(const COLOR4D &lhs, const COLOR4D &rhs)
Equality operator, are two colors equal.
const bool operator!=(const COLOR4D &lhs, const COLOR4D &rhs)
Not equality operator, are two colors not equal.
void to_json(nlohmann::json &aJson, const COLOR4D &aColor)