JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
juce::Colour Class Referencefinal

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

#include "juce_Colour.h"

Public Member Functions

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

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

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.

@tags{Graphics}

Definition at line 37 of file juce_Colour.h.

Constructor & Destructor Documentation

◆ Colour() [1/9]

juce::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

Definition at line 215 of file juce_Colour.cpp.

◆ Colour() [2/9]

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

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

Definition at line 223 of file juce_Colour.cpp.

◆ Colour() [3/9]

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

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

Definition at line 233 of file juce_Colour.cpp.

◆ Colour() [4/9]

juce::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.

Definition at line 243 of file juce_Colour.cpp.

◆ Colour() [5/9]

juce::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.

Definition at line 273 of file juce_Colour.cpp.

◆ Colour() [6/9]

juce::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.

Definition at line 255 of file juce_Colour.cpp.

◆ Colour() [7/9]

juce::Colour::Colour ( PixelARGB  argb)
noexcept

Creates a colour using a PixelARGB object.

This function assumes that the argb pixel is not premultiplied.

Definition at line 278 of file juce_Colour.cpp.

◆ Colour() [8/9]

juce::Colour::Colour ( PixelRGB  rgb)
noexcept

Creates a colour using a PixelRGB object.

Definition at line 283 of file juce_Colour.cpp.

◆ Colour() [9/9]

juce::Colour::Colour ( PixelAlpha  alpha)
noexcept

Creates a colour using a PixelAlpha object.

Definition at line 288 of file juce_Colour.cpp.

Member Function Documentation

◆ brighter()

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

Returns a brighter version of this colour.

Parameters
amountBrighterhow much brighter to make it - a value greater than or equal to 0, where 0 is unchanged, and higher values make it brighter
See also
withMultipliedBrightness

Definition at line 466 of file juce_Colour.cpp.

◆ contrasting() [1/3]

Colour juce::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.

Definition at line 518 of file juce_Colour.cpp.

◆ contrasting() [2/3]

Colour juce::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.

Definition at line 503 of file juce_Colour.cpp.

◆ contrasting() [3/3]

Colour juce::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.

Definition at line 496 of file juce_Colour.cpp.

◆ darker()

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

Returns a darker version of this colour.

Parameters
amountDarkerhow much darker to make it - a value greater than or equal to 0, where 0 is unchanged, and higher values make it darker
See also
withMultipliedBrightness

Definition at line 477 of file juce_Colour.cpp.

◆ fromFloatRGBA()

Colour juce::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.

Definition at line 248 of file juce_Colour.cpp.

◆ fromHSL()

Colour juce::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.

Definition at line 265 of file juce_Colour.cpp.

◆ fromHSV()

Colour juce::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.

Definition at line 260 of file juce_Colour.cpp.

◆ fromRGB()

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

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

Definition at line 228 of file juce_Colour.cpp.

◆ fromRGBA()

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

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

Definition at line 238 of file juce_Colour.cpp.

◆ fromString()

Colour juce::Colour::fromString ( StringRef  encodedColourString)
static

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

Definition at line 548 of file juce_Colour.cpp.

◆ getAlpha()

uint8 juce::Colour::getAlpha ( ) const
noexcept

Returns the colour's alpha (opacity).

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

Definition at line 215 of file juce_Colour.h.

◆ getARGB()

uint32 juce::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).

Definition at line 306 of file juce_Colour.cpp.

◆ getBlue()

uint8 juce::Colour::getBlue ( ) const
noexcept

Returns the blue component of this colour.

Returns
a value between 0x00 and 0xff.

Definition at line 178 of file juce_Colour.h.

◆ getBrightness()

float juce::Colour::getBrightness ( ) const
noexcept

Returns the colour's brightness component.

The value returned is in the range 0.0 to 1.0

Definition at line 410 of file juce_Colour.cpp.

◆ getFloatAlpha()

float juce::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.

Definition at line 389 of file juce_Colour.cpp.

◆ getFloatBlue()

float juce::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

Definition at line 388 of file juce_Colour.cpp.

◆ getFloatGreen()

float juce::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

Definition at line 387 of file juce_Colour.cpp.

◆ getFloatRed()

float juce::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

Definition at line 386 of file juce_Colour.cpp.

◆ getGreen()

uint8 juce::Colour::getGreen ( ) const
noexcept

Returns the green component of this colour.

Returns
a value between 0x00 and 0xff.

Definition at line 173 of file juce_Colour.h.

◆ getHSB()

void juce::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

Definition at line 392 of file juce_Colour.cpp.

◆ getHSL()

void juce::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

Definition at line 400 of file juce_Colour.cpp.

◆ getHue()

float juce::Colour::getHue ( ) const
noexcept

Returns the colour's hue component.

The value returned is in the range 0.0 to 1.0

Definition at line 408 of file juce_Colour.cpp.

◆ getLightness()

float juce::Colour::getLightness ( ) const
noexcept

Returns the colour's lightness component.

The value returned is in the range 0.0 to 1.0

Definition at line 413 of file juce_Colour.cpp.

◆ getNonPremultipliedPixelARGB()

PixelARGB juce::Colour::getNonPremultipliedPixelARGB ( ) const
noexcept

Returns an ARGB pixel object that represents this colour.

Definition at line 301 of file juce_Colour.cpp.

◆ getPerceivedBrightness()

float juce::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.

Definition at line 422 of file juce_Colour.cpp.

◆ getPixelARGB()

PixelARGB juce::Colour::getPixelARGB ( ) const
noexcept

Returns a premultiplied ARGB pixel object that represents this colour.

Definition at line 294 of file juce_Colour.cpp.

◆ getRed()

uint8 juce::Colour::getRed ( ) const
noexcept

Returns the red component of this colour.

Returns
a value between 0x00 and 0xff.

Definition at line 168 of file juce_Colour.h.

◆ getSaturation()

float juce::Colour::getSaturation ( ) const
noexcept

Returns the colour's saturation component.

The value returned is in the range 0.0 to 1.0

Definition at line 409 of file juce_Colour.cpp.

◆ getSaturationHSL()

float juce::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

Definition at line 412 of file juce_Colour.cpp.

◆ greyLevel()

Colour juce::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

Definition at line 489 of file juce_Colour.cpp.

◆ interpolatedWith()

Colour juce::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.

Definition at line 369 of file juce_Colour.cpp.

◆ isOpaque()

bool juce::Colour::isOpaque ( ) const
noexcept

Returns true if this colour is completely opaque.

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

Definition at line 317 of file juce_Colour.cpp.

◆ isTransparent()

bool juce::Colour::isTransparent ( ) const
noexcept

Returns true if this colour is completely transparent.

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

Definition at line 312 of file juce_Colour.cpp.

◆ operator!=()

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

Compares two colours.

Definition at line 212 of file juce_Colour.cpp.

◆ operator==()

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

Compares two colours.

Definition at line 211 of file juce_Colour.cpp.

◆ overlaidWith()

Colour juce::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.

Definition at line 348 of file juce_Colour.cpp.

◆ toDisplayString()

String juce::Colour::toDisplayString ( bool  includeAlphaValue) const

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

Definition at line 553 of file juce_Colour.cpp.

◆ toString()

String juce::Colour::toString ( ) const

Returns a stringified version of this colour.

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

Definition at line 543 of file juce_Colour.cpp.

◆ withAlpha() [1/2]

Colour juce::Colour::withAlpha ( float  newAlpha) const
noexcept

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

Definition at line 329 of file juce_Colour.cpp.

◆ withAlpha() [2/2]

Colour juce::Colour::withAlpha ( uint8  newAlpha) const
noexcept

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

Definition at line 322 of file juce_Colour.cpp.

◆ withBrightness()

Colour juce::Colour::withBrightness ( float  newBrightness) const
noexcept

Returns a copy of this colour with a different brightness.

See also
brighter, darker, withMultipliedBrightness

Definition at line 417 of file juce_Colour.cpp.

◆ withHue()

Colour juce::Colour::withHue ( float  newHue) const
noexcept

Returns a copy of this colour with a different hue.

Definition at line 415 of file juce_Colour.cpp.

◆ withLightness()

Colour juce::Colour::withLightness ( float  newLightness) const
noexcept

Returns a copy of this colour with a different lightness.

See also
lighter, darker, withMultipliedLightness

Definition at line 420 of file juce_Colour.cpp.

◆ withMultipliedAlpha()

Colour juce::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.

Definition at line 338 of file juce_Colour.cpp.

◆ withMultipliedBrightness()

Colour juce::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).

Definition at line 451 of file juce_Colour.cpp.

◆ withMultipliedLightness()

Colour juce::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).

Definition at line 458 of file juce_Colour.cpp.

◆ withMultipliedSaturation()

Colour juce::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).

Definition at line 437 of file juce_Colour.cpp.

◆ withMultipliedSaturationHSL()

Colour juce::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.

Definition at line 444 of file juce_Colour.cpp.

◆ withRotatedHue()

Colour juce::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

Definition at line 430 of file juce_Colour.cpp.

◆ withSaturation()

Colour juce::Colour::withSaturation ( float  newSaturation) const
noexcept

Returns a copy of this colour with a different saturation.

Definition at line 416 of file juce_Colour.cpp.

◆ withSaturationHSL()

Colour juce::Colour::withSaturationHSL ( float  newSaturation) const
noexcept

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

Definition at line 419 of file juce_Colour.cpp.


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