iPlug2 - C++ Audio Plug-in Framework
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. 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.
 
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)
 
void ToColorCodeStr (WDL_String &str) 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 227 of file IGraphicsStructs.h.

Constructor & Destructor Documentation

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

Create an IColor.

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 236 of file IGraphicsStructs.h.

Member Function Documentation

void IColor::Contrast ( float  c)
inline

Contrast the color.

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

Definition at line 277 of file IGraphicsStructs.h.

References Clip().

Referenced by WithContrast().

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

Definition at line 249 of file IGraphicsStructs.h.

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
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 405 of file IGraphicsStructs.h.

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 417 of file IGraphicsStructs.h.

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 452 of file IGraphicsStructs.h.

References Clip().

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

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 386 of file IGraphicsStructs.h.

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 373 of file IGraphicsStructs.h.

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 319 of file IGraphicsStructs.h.

int IColor::GetLuminosity ( ) const
inline
Todo:
Returns
int
Todo:

Definition at line 350 of file IGraphicsStructs.h.

Referenced by IVKeyboardControl::Draw().

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 360 of file IGraphicsStructs.h.

Referenced by TestTextControl::OnMouseDblClick(), TestAnimationControl::OnMouseDown(), and TestGradientControl::OnResize().

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 306 of file IGraphicsStructs.h.

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 297 of file IGraphicsStructs.h.

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 484 of file IGraphicsStructs.h.

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 256 of file IGraphicsStructs.h.

Referenced by IGraphics::BeginFrame().

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 246 of file IGraphicsStructs.h.

Referenced by IVectorBase::GetColor().

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 260 of file IGraphicsStructs.h.

References Clip().

Referenced by WithOpacity().

void IColor::ToColorCodeStr ( WDL_String &  str) const
inline

Convert the IColor to a hex string e.g.

"#ffffffff"

Definition at line 441 of file IGraphicsStructs.h.

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 288 of file IGraphicsStructs.h.

References Contrast().

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

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 268 of file IGraphicsStructs.h.

References SetOpacity().

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


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