iPlug 2: IColor Struct Reference

Used to manage color data, independent of draw class/platform. More...

#include <IGraphicsStructs.h>

Public Member Functions

 IColor (int a=255, int r=0, int g=0, int b=0)
 Create an IColor from ARGB values. More...
 
bool operator== (const IColor &rhs)
 
bool operator!= (const IColor &rhs)
 
void Set (int a=255, int r=0, int g=0, int b=0)
 Set the color parts. More...
 
bool Empty () const
 
void Clamp ()
 Keep the member int variables within the range 0-255. More...
 
void Randomise (int alpha=255)
 Randomise the color parts, with optional alpha. More...
 
void SetOpacity (float alpha)
 Set the color's opacity/alpha component with a float. More...
 
IColor WithOpacity (float alpha) const
 Returns a new IColor with a different opacity. More...
 
void Contrast (float c)
 Contrast the color. More...
 
IColor WithContrast (float c) const
 Returns a new contrasted IColor based on this one. More...
 
void GetRGBf (float *rgbf) const
 Get the color as a 3 float array. More...
 
void GetRGBAf (float *rgbaf) const
 Get the color as a 4 float array. More...
 
void GetHSLA (float &h, float &s, float &l, float &a) const
 Get the Hue, Saturation and Luminance of the color. More...
 
int GetLuminosity () const
 Gets the lightness of the color (HSL lightness component) More...
 
int ToColorCode () const
 Convert the IColor to a single int (no alpha) More...
 
void ToColorCodeStr (WDL_String &str, bool withAlpha=true) const
 Convert the IColor to a hex string e.g. More...
 

Static Public Member Functions

static IColor GetRandomColor (bool randomAlpha=false)
 Get a random IColor. More...
 
static IColor FromRGBf (float *rgbf)
 Create an IColor from a 3 float RGB array. More...
 
static IColor FromRGBAf (float *rgbaf)
 Create an IColor from a 4 float RGBA array. More...
 
static IColor FromColorCode (int colorCode, int A=0xFF)
 Create an IColor from a color code. More...
 
static IColor FromColorCodeStr (const char *hexStr)
 Create an IColor from a color code in a CString. More...
 
static IColor FromHSLA (float h, float s, float l, float a=1.f)
 Create an IColor from Hue Saturation and Luminance values. More...
 
static IColor LinearInterpolateBetween (const IColor &start, const IColor &dest, float progress)
 Helper function to linear interpolate between two IColors. More...
 

Public Attributes

int A
 
int R
 
int G
 
int B
 

Used to manage color data, independent of draw class/platform.

Definition at line 222 of file IGraphicsStructs.h.

IColor::IColor ( int  a = 255,
int  r = 0,
int  g = 0,
int  b = 0 
)
inline

Create an IColor from ARGB values.

Parameters
aAlpha value (valid range 0-255)
rRed value (valid range 0-255)
gGreen value (valid range 0-255)
bBlue value (valid range 0-255)

Definition at line 231 of file IGraphicsStructs.h.

◆ Clamp()

void IColor::Clamp ( )
inline

◆ Contrast()

void IColor::Contrast ( float  c)
inline

◆ Empty()

bool IColor::Empty ( ) const
inline

◆ FromColorCode()

static IColor IColor::FromColorCode ( int  colorCode,
int  A = 0xFF 
)
inlinestatic

Create an IColor from a color code.

Can be used to convert a hex code into an IColor object.

Used to manage color data, independent of draw class/platform.

static IColor FromColorCode(int colorCode, int A=0xFF)

Create an IColor from a color code.

Parameters
colorCodeInteger representation of the color. Use with hexadecimal numbers, e.g. 0xff38a2
AInteger representation of the alpha channel
Returns
IColor A new IColor based on the color code provided

Definition at line 400 of file IGraphicsStructs.h.

Referenced by FromColorCodeStr().

◆ FromColorCodeStr()

static IColor IColor::FromColorCodeStr ( const char *  hexStr)
inlinestatic

Create an IColor from a color code in a CString.

Can be used to convert a hex code into an IColor object.

Parameters
hexStrCString representation of the color code (no alpha). Use with hex numbers, e.g. "#ff38a2". WARNING: This does very little error checking
Returns
IColor A new IColor based on the color code provided

Definition at line 412 of file IGraphicsStructs.h.

References FromColorCode().

◆ FromHSLA()

static IColor IColor::FromHSLA ( float  h,
float  s,
float  l,
float  a = 1.f 
)
inlinestatic

◆ FromRGBAf()

static IColor IColor::FromRGBAf ( float *  rgbaf)
inlinestatic

◆ FromRGBf()

static IColor IColor::FromRGBf ( float *  rgbf)
inlinestatic

◆ GetHSLA()

void IColor::GetHSLA ( float &  h,
float &  s,
float &  l,
float &  a 
) const
inline

Get the Hue, Saturation and Luminance of the color.

Parameters
hhue value to set, output in the range 0. to 1.
ssaturation value to set, output in the range 0. to 1.
lluminance value to set, output in the range 0. to 1.
aalpha value to set, output in the range 0. to 1.

Definition at line 314 of file IGraphicsStructs.h.

◆ GetLuminosity()

int IColor::GetLuminosity ( ) const
inline

Gets the lightness of the color (HSL lightness component)

Returns
The lightness value (0-255), calculated as (min(R,G,B) + max(R,G,B)) / 2

Definition at line 345 of file IGraphicsStructs.h.

◆ GetRandomColor()

static IColor IColor::GetRandomColor ( bool  randomAlpha = false)
inlinestatic

◆ GetRGBAf()

void IColor::GetRGBAf ( float *  rgbaf) const
inline

Get the color as a 4 float array.

Parameters
rgbafptr to array of 4 floats

Definition at line 301 of file IGraphicsStructs.h.

◆ GetRGBf()

void IColor::GetRGBf ( float *  rgbf) const
inline

Get the color as a 3 float array.

Parameters
rgbfptr to array of 3 floats

Definition at line 292 of file IGraphicsStructs.h.

◆ LinearInterpolateBetween()

static IColor IColor::LinearInterpolateBetween ( const IColor start,
const IColor dest,
float  progress 
)
inlinestatic

Helper function to linear interpolate between two IColors.

Parameters
startStart IColor
destEnd IColor
progressThe normalized interpolation point

Definition at line 482 of file IGraphicsStructs.h.

◆ operator!=()

bool IColor::operator!= ( const IColor rhs)
inline

◆ operator==()

bool IColor::operator== ( const IColor rhs)
inline

◆ Randomise()

void IColor::Randomise ( int  alpha = 255)
inline

Randomise the color parts, with optional alpha.

Parameters
alphaSet the alpha of the new random color

Definition at line 251 of file IGraphicsStructs.h.

◆ Set()

void IColor::Set ( int  a = 255,
int  r = 0,
int  g = 0,
int  b = 0 
)
inline

Set the color parts.

Parameters
aAlpha value (valid range 0-255)
rRed value (valid range 0-255)
gGreen value (valid range 0-255)
bBlue value (valid range 0-255)

Definition at line 241 of file IGraphicsStructs.h.

◆ SetOpacity()

void IColor::SetOpacity ( float  alpha)
inline

◆ ToColorCode()

int IColor::ToColorCode ( ) const
inline

◆ ToColorCodeStr()

void IColor::ToColorCodeStr ( WDL_String &  str,
bool  withAlpha = true 
) const
inline

◆ WithContrast()

IColor IColor::WithContrast ( float  c) const
inline

◆ WithOpacity()

IColor IColor::WithOpacity ( float  alpha) const
inline

◆ A

◆ B

◆ G

◆ R


The documentation for this struct was generated from the following file: