JUCE
Public Member Functions | Static Public Member Functions | List of all members
Colour Class Referencefinal

Represents a colour, also including a transparency value. More...

Public Member Functions

 Colour ()=default
 Creates a transparent black colour. More...
 
 Colour (const Colour &)=default
 Creates a copy of another Colour object. More...
 
 Colour (uint32 argb) noexcept
 Creates a colour from a 32-bit ARGB value. More...
 
 Colour (uint8 red, uint8 green, uint8 blue) noexcept
 Creates an opaque colour using 8-bit red, green and blue values. More...
 
 Colour (uint8 red, uint8 green, uint8 blue, uint8 alpha) noexcept
 Creates a colour using 8-bit red, green, blue and alpha values. More...
 
 Colour (uint8 red, uint8 green, uint8 blue, float alpha) noexcept
 Creates a colour from 8-bit red, green, and blue values, and a floating-point alpha. More...
 
 Colour (float hue, float saturation, float brightness, uint8 alpha) noexcept
 Creates a colour using floating point hue, saturation and brightness values, and an 8-bit alpha. More...
 
 Colour (float hue, float saturation, float brightness, float alpha) noexcept
 Creates a colour using floating point hue, saturation, brightness and alpha values. More...
 
 Colour (PixelARGB argb) noexcept
 Creates a colour using a PixelARGB object. More...
 
 Colour (PixelRGB rgb) noexcept
 Creates a colour using a PixelRGB object. More...
 
 Colour (PixelAlpha alpha) noexcept
 Creates a colour using a PixelAlpha object. More...
 
 ~Colour ()=default
 Destructor. More...
 
Colouroperator= (const Colour &)=default
 Copies another Colour object. More...
 
bool operator== (const Colour &other) const noexcept
 Compares two colours. More...
 
bool operator!= (const Colour &other) const noexcept
 Compares two colours. More...
 
uint8 getRed () const noexcept
 Returns the red component of this colour. More...
 
uint8 getGreen () const noexcept
 Returns the green component of this colour. More...
 
uint8 getBlue () const noexcept
 Returns the blue component of this colour. More...
 
float getFloatRed () const noexcept
 Returns the red component of this colour as a floating point value. More...
 
float getFloatGreen () const noexcept
 Returns the green component of this colour as a floating point value. More...
 
float getFloatBlue () const noexcept
 Returns the blue component of this colour as a floating point value. More...
 
const PixelARGB getPixelARGB () const noexcept
 Returns a premultiplied ARGB pixel object that represents this colour. More...
 
uint32 getARGB () const noexcept
 Returns a 32-bit integer that represents this colour. More...
 
uint8 getAlpha () const noexcept
 Returns the colour's alpha (opacity). More...
 
float getFloatAlpha () const noexcept
 Returns the colour's alpha (opacity) as a floating point value. More...
 
bool isOpaque () const noexcept
 Returns true if this colour is completely opaque. More...
 
bool isTransparent () const noexcept
 Returns true if this colour is completely transparent. More...
 
Colour withAlpha (uint8 newAlpha) const noexcept
 Returns a colour that's the same colour as this one, but with a new alpha value. More...
 
Colour withAlpha (float newAlpha) const noexcept
 Returns a colour that's the same colour as this one, but with a new alpha value. More...
 
Colour withMultipliedAlpha (float alphaMultiplier) const noexcept
 Returns a colour that's the same colour as this one, but with a modified alpha value. More...
 
Colour overlaidWith (Colour foregroundColour) const noexcept
 Returns a colour that is the result of alpha-compositing a new colour over this one. More...
 
Colour interpolatedWith (Colour other, float proportionOfOther) const noexcept
 Returns a colour that lies somewhere between this one and another. More...
 
float getHue () const noexcept
 Returns the colour's hue component. More...
 
float getSaturation () const noexcept
 Returns the colour's saturation component. More...
 
float getSaturationHSL () const noexcept
 Returns the colour's saturation component as represented in the HSL colour space. More...
 
float getBrightness () const noexcept
 Returns the colour's brightness component. More...
 
float getLightness () const noexcept
 Returns the colour's lightness component. More...
 
float getPerceivedBrightness () const noexcept
 Returns a skewed brightness value, adjusted to better reflect the way the human eye responds to different colour channels. More...
 
void getHSB (float &hue, float &saturation, float &brightness) const noexcept
 Returns the colour's hue, saturation and brightness components all at once. More...
 
void getHSL (float &hue, float &saturation, float &lightness) const noexcept
 Returns the colour's hue, saturation and lightness components all at once. More...
 
Colour withHue (float newHue) const noexcept
 Returns a copy of this colour with a different hue. More...
 
Colour withSaturation (float newSaturation) const noexcept
 Returns a copy of this colour with a different saturation. More...
 
Colour withSaturationHSL (float newSaturation) const noexcept
 Returns a copy of this colour with a different saturation in the HSL colour space. More...
 
Colour withBrightness (float newBrightness) const noexcept
 Returns a copy of this colour with a different brightness. More...
 
Colour withLightness (float newLightness) const noexcept
 Returns a copy of this colour with a different lightness. More...
 
Colour withRotatedHue (float amountToRotate) const noexcept
 Returns a copy of this colour with its hue rotated. More...
 
Colour withMultipliedSaturation (float multiplier) const noexcept
 Returns a copy of this colour with its saturation multiplied by the given value. More...
 
Colour withMultipliedSaturationHSL (float multiplier) const noexcept
 Returns a copy of this colour with its saturation multiplied by the given value. More...
 
Colour withMultipliedBrightness (float amount) const noexcept
 Returns a copy of this colour with its brightness multiplied by the given value. More...
 
Colour withMultipliedLightness (float amount) const noexcept
 Returns a copy of this colour with its lightness multiplied by the given value. More...
 
Colour brighter (float amountBrighter=0.4f) const noexcept
 Returns a brighter version of this colour. More...
 
Colour darker (float amountDarker=0.4f) const noexcept
 Returns a darker version of this colour. More...
 
Colour contrasting (float amount=1.0f) const noexcept
 Returns a colour that will be clearly visible against this colour. More...
 
Colour contrasting (Colour targetColour, float minLuminosityDiff) const noexcept
 Returns a colour that is as close as possible to a target colour whilst still being in contrast to this one. More...
 
String toString () const
 Returns a stringified version of this colour. More...
 
String toDisplayString (bool includeAlphaValue) const
 Returns the colour as a hex string in the form RRGGBB or AARRGGBB. More...
 

Static Public Member Functions

static Colour fromRGB (uint8 red, uint8 green, uint8 blue) noexcept
 Creates an opaque colour using 8-bit red, green and blue values. More...
 
static Colour fromRGBA (uint8 red, uint8 green, uint8 blue, uint8 alpha) noexcept
 Creates a colour using 8-bit red, green, blue and alpha values. More...
 
static Colour fromFloatRGBA (float red, float green, float blue, float alpha) noexcept
 Creates a colour using floating point red, green, blue and alpha values. More...
 
static Colour fromHSV (float hue, float saturation, float brightness, float alpha) noexcept
 Creates a colour using floating point hue, saturation, brightness and alpha values. More...
 
static Colour fromHSL (float hue, float saturation, float lightness, float alpha) noexcept
 Creates a colour using floating point hue, saturation, lightness and alpha values. More...
 
static Colour contrasting (Colour colour1, Colour colour2) noexcept
 Returns a colour that contrasts against two colours. More...
 
static Colour greyLevel (float brightness) noexcept
 Returns an opaque shade of grey. More...
 
static Colour fromString (StringRef encodedColourString)
 Reads the colour from a string that was created with toString(). More...
 

Detailed Description

Represents a colour, also including a transparency value.

The colour is stored internally as unsigned 8-bit red, green, blue and alpha values.

Constructor & Destructor Documentation

◆ Colour() [1/11]

Colour::Colour ( )
default

Creates a transparent black colour.

◆ Colour() [2/11]

Colour::Colour ( const Colour )
default

Creates a copy of another Colour object.

◆ Colour() [3/11]

Colour::Colour ( uint32  argb)
explicitnoexcept

Creates a colour from a 32-bit ARGB value.

The format of this number is: ((alpha << 24) | (red << 16) | (green << 8) | blue).

All components in the range 0x00 to 0xff. An alpha of 0x00 is completely transparent, alpha of 0xff is opaque.

See also
getPixelARGB

◆ Colour() [4/11]

Colour::Colour ( uint8  red,
uint8  green,
uint8  blue 
)
noexcept

Creates an opaque colour using 8-bit red, green and blue values.

◆ Colour() [5/11]

Colour::Colour ( uint8  red,
uint8  green,
uint8  blue,
uint8  alpha 
)
noexcept

Creates a colour using 8-bit red, green, blue and alpha values.

◆ Colour() [6/11]

Colour::Colour ( uint8  red,
uint8  green,
uint8  blue,
float  alpha 
)
noexcept

Creates a colour from 8-bit red, green, and blue values, and a floating-point alpha.

Alpha of 0.0 is transparent, alpha of 1.0f is opaque. Values outside the valid range will be clipped.

◆ Colour() [7/11]

Colour::Colour ( float  hue,
float  saturation,
float  brightness,
uint8  alpha 
)
noexcept

Creates a colour using floating point hue, saturation and brightness values, and an 8-bit alpha.

The floating point values must be between 0.0 and 1.0. An alpha of 0x00 is completely transparent, alpha of 0xff is opaque. Values outside the valid range will be clipped.

◆ Colour() [8/11]

Colour::Colour ( float  hue,
float  saturation,
float  brightness,
float  alpha 
)
noexcept

Creates a colour using floating point hue, saturation, brightness and alpha values.

All values must be between 0.0 and 1.0. Numbers outside the valid range will be clipped.

◆ Colour() [9/11]

Colour::Colour ( PixelARGB  argb)
noexcept

Creates a colour using a PixelARGB object.

This function assumes that the argb pixel is not premultiplied.

◆ Colour() [10/11]

Colour::Colour ( PixelRGB  rgb)
noexcept

Creates a colour using a PixelRGB object.

◆ Colour() [11/11]

Colour::Colour ( PixelAlpha  alpha)
noexcept

Creates a colour using a PixelAlpha object.

◆ ~Colour()

Colour::~Colour ( )
default

Destructor.

Member Function Documentation

◆ fromRGB()

static Colour Colour::fromRGB ( uint8  red,
uint8  green,
uint8  blue 
)
staticnoexcept

Creates an opaque colour using 8-bit red, green and blue values.

◆ fromRGBA()

static Colour Colour::fromRGBA ( uint8  red,
uint8  green,
uint8  blue,
uint8  alpha 
)
staticnoexcept

Creates a colour using 8-bit red, green, blue and alpha values.

◆ fromFloatRGBA()

static Colour Colour::fromFloatRGBA ( float  red,
float  green,
float  blue,
float  alpha 
)
staticnoexcept

Creates a colour using floating point red, green, blue and alpha values.

Numbers outside the range 0..1 will be clipped.

◆ fromHSV()

static Colour Colour::fromHSV ( float  hue,
float  saturation,
float  brightness,
float  alpha 
)
staticnoexcept

Creates a colour using floating point hue, saturation, brightness and alpha values.

All values must be between 0.0 and 1.0. Numbers outside the valid range will be clipped.

◆ fromHSL()

static Colour Colour::fromHSL ( float  hue,
float  saturation,
float  lightness,
float  alpha 
)
staticnoexcept

Creates a colour using floating point hue, saturation, lightness and alpha values.

All values must be between 0.0 and 1.0. Numbers outside the valid range will be clipped.

◆ operator=()

Colour& Colour::operator= ( const Colour )
default

Copies another Colour object.

◆ operator==()

bool Colour::operator== ( const Colour other) const
noexcept

Compares two colours.

◆ operator!=()

bool Colour::operator!= ( const Colour other) const
noexcept

Compares two colours.

◆ getRed()

uint8 Colour::getRed ( ) const
noexcept

Returns the red component of this colour.

Returns
a value between 0x00 and 0xff.

References PixelARGB::getRed().

◆ getGreen()

uint8 Colour::getGreen ( ) const
noexcept

Returns the green component of this colour.

Returns
a value between 0x00 and 0xff.

References PixelARGB::getGreen().

◆ getBlue()

uint8 Colour::getBlue ( ) const
noexcept

Returns the blue component of this colour.

Returns
a value between 0x00 and 0xff.

References PixelARGB::getBlue().

◆ getFloatRed()

float Colour::getFloatRed ( ) const
noexcept

Returns the red component of this colour as a floating point value.

Returns
a value between 0.0 and 1.0

◆ getFloatGreen()

float Colour::getFloatGreen ( ) const
noexcept

Returns the green component of this colour as a floating point value.

Returns
a value between 0.0 and 1.0

◆ getFloatBlue()

float Colour::getFloatBlue ( ) const
noexcept

Returns the blue component of this colour as a floating point value.

Returns
a value between 0.0 and 1.0

◆ getPixelARGB()

const PixelARGB Colour::getPixelARGB ( ) const
noexcept

Returns a premultiplied ARGB pixel object that represents this colour.

◆ getARGB()

uint32 Colour::getARGB ( ) const
noexcept

Returns a 32-bit integer that represents this colour.

The format of this number is: ((alpha << 24) | (red << 16) | (green << 8) | blue).

◆ getAlpha()

uint8 Colour::getAlpha ( ) const
noexcept

Returns the colour's alpha (opacity).

Alpha of 0x00 is completely transparent, 0xff is completely opaque.

References PixelARGB::getAlpha().

◆ getFloatAlpha()

float Colour::getFloatAlpha ( ) const
noexcept

Returns the colour's alpha (opacity) as a floating point value.

Alpha of 0.0 is completely transparent, 1.0 is completely opaque.

Referenced by FillType::getOpacity().

◆ isOpaque()

bool Colour::isOpaque ( ) const
noexcept

Returns true if this colour is completely opaque.

Equivalent to (getAlpha() == 0xff).

◆ isTransparent()

bool Colour::isTransparent ( ) const
noexcept

Returns true if this colour is completely transparent.

Equivalent to (getAlpha() == 0x00).

◆ withAlpha() [1/2]

Colour Colour::withAlpha ( uint8  newAlpha) const
noexcept

Returns a colour that's the same colour as this one, but with a new alpha value.

◆ withAlpha() [2/2]

Colour Colour::withAlpha ( float  newAlpha) const
noexcept

Returns a colour that's the same colour as this one, but with a new alpha value.

◆ withMultipliedAlpha()

Colour Colour::withMultipliedAlpha ( float  alphaMultiplier) const
noexcept

Returns a colour that's the same colour as this one, but with a modified alpha value.

The new colour's alpha will be this object's alpha multiplied by the value passed-in.

◆ overlaidWith()

Colour Colour::overlaidWith ( Colour  foregroundColour) const
noexcept

Returns a colour that is the result of alpha-compositing a new colour over this one.

If the foreground colour is semi-transparent, it is blended onto this colour accordingly.

◆ interpolatedWith()

Colour Colour::interpolatedWith ( Colour  other,
float  proportionOfOther 
) const
noexcept

Returns a colour that lies somewhere between this one and another.

If amountOfOther is zero, the result is 100% this colour, if amountOfOther is 1.0, the result is 100% of the other colour.

◆ getHue()

float Colour::getHue ( ) const
noexcept

Returns the colour's hue component.

The value returned is in the range 0.0 to 1.0

◆ getSaturation()

float Colour::getSaturation ( ) const
noexcept

Returns the colour's saturation component.

The value returned is in the range 0.0 to 1.0

◆ getSaturationHSL()

float Colour::getSaturationHSL ( ) const
noexcept

Returns the colour's saturation component as represented in the HSL colour space.

The value returned is in the range 0.0 to 1.0

◆ getBrightness()

float Colour::getBrightness ( ) const
noexcept

Returns the colour's brightness component.

The value returned is in the range 0.0 to 1.0

◆ getLightness()

float Colour::getLightness ( ) const
noexcept

Returns the colour's lightness component.

The value returned is in the range 0.0 to 1.0

◆ getPerceivedBrightness()

float Colour::getPerceivedBrightness ( ) const
noexcept

Returns a skewed brightness value, adjusted to better reflect the way the human eye responds to different colour channels.

This makes it better than getBrightness() for comparing differences in brightness.

◆ getHSB()

void Colour::getHSB ( float &  hue,
float &  saturation,
float &  brightness 
) const
noexcept

Returns the colour's hue, saturation and brightness components all at once.

The values returned are in the range 0.0 to 1.0

◆ getHSL()

void Colour::getHSL ( float &  hue,
float &  saturation,
float &  lightness 
) const
noexcept

Returns the colour's hue, saturation and lightness components all at once.

The values returned are in the range 0.0 to 1.0

◆ withHue()

Colour Colour::withHue ( float  newHue) const
noexcept

Returns a copy of this colour with a different hue.

◆ withSaturation()

Colour Colour::withSaturation ( float  newSaturation) const
noexcept

Returns a copy of this colour with a different saturation.

◆ withSaturationHSL()

Colour Colour::withSaturationHSL ( float  newSaturation) const
noexcept

Returns a copy of this colour with a different saturation in the HSL colour space.

◆ withBrightness()

Colour Colour::withBrightness ( float  newBrightness) const
noexcept

Returns a copy of this colour with a different brightness.

See also
brighter, darker, withMultipliedBrightness

◆ withLightness()

Colour Colour::withLightness ( float  newLightness) const
noexcept

Returns a copy of this colour with a different lightness.

See also
lighter, darker, withMultipliedLightness

◆ withRotatedHue()

Colour Colour::withRotatedHue ( float  amountToRotate) const
noexcept

Returns a copy of this colour with its hue rotated.

The new colour's hue is ((this->getHue() + amountToRotate) % 1.0)

See also
brighter, darker, withMultipliedBrightness

◆ withMultipliedSaturation()

Colour Colour::withMultipliedSaturation ( float  multiplier) const
noexcept

Returns a copy of this colour with its saturation multiplied by the given value.

The new colour's saturation is (this->getSaturation() * multiplier) (the result is clipped to legal limits).

◆ withMultipliedSaturationHSL()

Colour Colour::withMultipliedSaturationHSL ( float  multiplier) const
noexcept

Returns a copy of this colour with its saturation multiplied by the given value.

The new colour's saturation is (this->getSaturation() * multiplier) (the result is clipped to legal limits).

This will be in the HSL colour space.

◆ withMultipliedBrightness()

Colour Colour::withMultipliedBrightness ( float  amount) const
noexcept

Returns a copy of this colour with its brightness multiplied by the given value.

The new colour's brightness is (this->getBrightness() * multiplier) (the result is clipped to legal limits).

◆ withMultipliedLightness()

Colour Colour::withMultipliedLightness ( float  amount) const
noexcept

Returns a copy of this colour with its lightness multiplied by the given value.

The new colour's lightness is (this->lightness() * multiplier) (the result is clipped to legal limits).

◆ brighter()

Colour Colour::brighter ( float  amountBrighter = 0.4f) const
noexcept

Returns a brighter version of this colour.

Parameters
amountBrighterhow much brighter to make it - a value from 0 to 1.0 where 0 is unchanged, and higher values make it brighter
See also
withMultipliedBrightness

◆ darker()

Colour Colour::darker ( float  amountDarker = 0.4f) const
noexcept

Returns a darker version of this colour.

Parameters
amountDarkerhow much darker to make it - a value from 0 to 1.0 where 0 is unchanged, and higher values make it darker
See also
withMultipliedBrightness

◆ contrasting() [1/3]

Colour Colour::contrasting ( float  amount = 1.0f) const
noexcept

Returns a colour that will be clearly visible against this colour.

The amount parameter indicates how contrasting the new colour should be, so e.g. Colours::black.contrasting (0.1f) will return a colour that's just a little bit lighter; Colours::black.contrasting (1.0f) will return white; Colours::white.contrasting (1.0f) will return black, etc.

◆ contrasting() [2/3]

Colour Colour::contrasting ( Colour  targetColour,
float  minLuminosityDiff 
) const
noexcept

Returns a colour that is as close as possible to a target colour whilst still being in contrast to this one.

The colour that is returned will be the targetColour, but with its luminosity nudged up or down so that it differs from the luminosity of this colour by at least the amount specified by minLuminosityDiff.

◆ contrasting() [3/3]

static Colour Colour::contrasting ( Colour  colour1,
Colour  colour2 
)
staticnoexcept

Returns a colour that contrasts against two colours.

Looks for a colour that contrasts with both of the colours passed-in. Handy for things like choosing a highlight colour in text editors, etc.

◆ greyLevel()

static Colour Colour::greyLevel ( float  brightness)
staticnoexcept

Returns an opaque shade of grey.

Parameters
brightnessthe level of grey to return - 0 is black, 1.0 is white

◆ toString()

String Colour::toString ( ) const

Returns a stringified version of this colour.

The string can be turned back into a colour using the fromString() method.

◆ fromString()

static Colour Colour::fromString ( StringRef  encodedColourString)
static

Reads the colour from a string that was created with toString().

◆ toDisplayString()

String Colour::toDisplayString ( bool  includeAlphaValue) const

Returns the colour as a hex string in the form RRGGBB or AARRGGBB.


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