iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
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
 
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
 

Detailed Description

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

Definition at line 222 of file IGraphicsStructs.h.

Constructor & Destructor Documentation

◆ IColor()

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.

Member Function Documentation

◆ Clamp()

void IColor::Clamp ( )
inline

Keep the member int variables within the range 0-255.

Definition at line 247 of file IGraphicsStructs.h.

References Clip().

◆ Contrast()

void IColor::Contrast ( float  c)
inline

Contrast the color.

Parameters
cContrast value in the range -1.f to 1.f

Definition at line 272 of file IGraphicsStructs.h.

References Clip().

Referenced by WithContrast().

◆ Empty()

bool IColor::Empty ( ) const
inline
Returns
true if all color parts are zero

Definition at line 244 of file IGraphicsStructs.h.

◆ 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.

IColor color = IColor::FromColorCode(0x55a6ff);
IColor colorWithAlpha = IColor::FromColorCode(0x55a6ff, 0x88); // alpha is 0x88
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

Create an IColor from Hue Saturation and Luminance values.

Parameters
hhue value in the range 0.f-1.f
ssaturation value in the range 0.f-1.f
lluminance value in the range 0.f-1.f
aalpha value in the range 0.f-1.f
Returns
The new IColor

Definition at line 450 of file IGraphicsStructs.h.

References Clip().

Referenced by ILEDControl::Draw(), and TestColorControl::OnResize().

◆ FromRGBAf()

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

Create an IColor from a 4 float RGBA array.

Parameters
rgbafptr to array of 3 floats
Returns
IColor A new IColor based on the input array

Definition at line 381 of file IGraphicsStructs.h.

◆ FromRGBf()

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

Create an IColor from a 3 float RGB array.

Parameters
rgbfptr to array of 3 floats
Returns
IColor A new IColor based on the input array

Definition at line 368 of file IGraphicsStructs.h.

◆ 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
Todo:
Returns
int
Todo:

Definition at line 345 of file IGraphicsStructs.h.

◆ GetRandomColor()

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

Get a random IColor.

Parameters
randomAlphaSet true if you want a random alpha value too
Returns
IColor A new IColor with a random combination of ARGB values

Definition at line 355 of file IGraphicsStructs.h.

Referenced by TestAnimationControl::OnMouseDown().

◆ 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

Definition at line 234 of file IGraphicsStructs.h.

◆ operator==()

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

Definition at line 233 of file IGraphicsStructs.h.

◆ 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

Set the color's opacity/alpha component with a float.

Parameters
alphafloat in the range 0. to 1.

Definition at line 255 of file IGraphicsStructs.h.

References Clip().

Referenced by WithOpacity().

◆ ToColorCode()

int IColor::ToColorCode ( ) const
inline

Convert the IColor to a single int (no alpha)

Definition at line 430 of file IGraphicsStructs.h.

◆ ToColorCodeStr()

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

Convert the IColor to a hex string e.g.

"#ffffffff"

Definition at line 436 of file IGraphicsStructs.h.

◆ WithContrast()

IColor IColor::WithContrast ( float  c) const
inline

Returns a new contrasted IColor based on this one.

Parameters
cContrast value in the range -1. to 1.
Returns
IColor new Color

Definition at line 283 of file IGraphicsStructs.h.

References Contrast().

Referenced by IVKeyboardControl::Draw(), and IWheelControl::Draw().

◆ WithOpacity()

IColor IColor::WithOpacity ( float  alpha) const
inline

Returns a new IColor with a different opacity.

Parameters
alphafloat in the range 0. to 1.
Returns
IColor new Color

Definition at line 263 of file IGraphicsStructs.h.

References SetOpacity().

Referenced by IWheelControl::Draw(), and TestFlexBoxControl::Draw().

Member Data Documentation

◆ A

int IColor::A

Definition at line 224 of file IGraphicsStructs.h.

◆ B

int IColor::B

Definition at line 224 of file IGraphicsStructs.h.

◆ G

int IColor::G

Definition at line 224 of file IGraphicsStructs.h.

◆ R

int IColor::R

Definition at line 224 of file IGraphicsStructs.h.


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