Colour Class Reference

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

List of all members.

Public Member Functions

 Colour () throw ()
 Creates a transparent black colour.
 Colour (const Colour &other) throw ()
 Creates a copy of another Colour object.
 Colour (const uint32 argb) throw ()
 Creates a colour from a 32-bit ARGB value.
 Colour (const uint8 red, const uint8 green, const uint8 blue) throw ()
 Creates an opaque colour using 8-bit red, green and blue values.
 Colour (const uint8 red, const uint8 green, const uint8 blue, const uint8 alpha) throw ()
 Creates a colour using 8-bit red, green, blue and alpha values.
 Colour (const uint8 red, const uint8 green, const uint8 blue, const float alpha) throw ()
 Creates a colour from 8-bit red, green, and blue values, and a floating-point alpha.
 Colour (const float hue, const float saturation, const float brightness, const uint8 alpha) throw ()
 Creates a colour using floating point hue, saturation and brightness values, and an 8-bit alpha.
 Colour (const float hue, const float saturation, const float brightness, const float alpha) throw ()
 Creates a colour using floating point hue, saturation, brightness and alpha values.
 ~Colour () throw ()
 Destructor.
const Colouroperator= (const Colour &other) throw ()
 Copies another Colour object.
bool operator== (const Colour &other) const throw ()
 Compares two colours.
bool operator!= (const Colour &other) const throw ()
 Compares two colours.
uint8 getRed () const throw ()
 Returns the red component of this colour.
uint8 getGreen () const throw ()
 Returns the green component of this colour.
uint8 getBlue () const throw ()
 Returns the blue component of this colour.
float getFloatRed () const throw ()
 Returns the red component of this colour as a floating point value.
float getFloatGreen () const throw ()
 Returns the green component of this colour as a floating point value.
float getFloatBlue () const throw ()
 Returns the blue component of this colour as a floating point value.
const PixelARGB getPixelARGB () const throw ()
 Returns a premultiplied ARGB pixel object that represents this colour.
uint32 getARGB () const throw ()
 Returns a 32-bit integer that represents this colour.
uint8 getAlpha () const throw ()
 Returns the colour's alpha (opacity).
float getFloatAlpha () const throw ()
 Returns the colour's alpha (opacity) as a floating point value.
bool isOpaque () const throw ()
 Returns true if this colour is completely opaque.
bool isTransparent () const throw ()
 Returns true if this colour is completely transparent.
const Colour withAlpha (const uint8 newAlpha) const throw ()
 Returns a colour that's the same colour as this one, but with a new alpha value.
const Colour withAlpha (const float newAlpha) const throw ()
 Returns a colour that's the same colour as this one, but with a new alpha value.
const Colour withMultipliedAlpha (const float alphaMultiplier) const throw ()
 Returns a colour that's the same colour as this one, but with a modified alpha value.
const Colour overlaidWith (const Colour &foregroundColour) const throw ()
 Returns a colour that is the result of alpha-compositing a new colour over this one.
const Colour interpolatedWith (const Colour &other, float proportionOfOther) const throw ()
 Returns a colour that lies somewhere between this one and another.
float getHue () const throw ()
 Returns the colour's hue component.
float getSaturation () const throw ()
 Returns the colour's saturation component.
float getBrightness () const throw ()
 Returns the colour's brightness component.
void getHSB (float &hue, float &saturation, float &brightness) const throw ()
 Returns the colour's hue, saturation and brightness components all at once.
const Colour withHue (const float newHue) const throw ()
 Returns a copy of this colour with a different hue.
const Colour withSaturation (const float newSaturation) const throw ()
 Returns a copy of this colour with a different saturation.
const Colour withBrightness (const float newBrightness) const throw ()
 Returns a copy of this colour with a different brightness.
const Colour withRotatedHue (const float amountToRotate) const throw ()
 Returns a copy of this colour with it hue rotated.
const Colour withMultipliedSaturation (const float multiplier) const throw ()
 Returns a copy of this colour with its saturation multiplied by the given value.
const Colour withMultipliedBrightness (const float amount) const throw ()
 Returns a copy of this colour with its brightness multiplied by the given value.
const Colour brighter (float amountBrighter=0.4f) const throw ()
 Returns a brighter version of this colour.
const Colour darker (float amountDarker=0.4f) const throw ()
 Returns a darker version of this colour.
const Colour contrasting (const float amount=1.0f) const throw ()
 Returns a colour that will be clearly visible against this colour.
const String toString () const throw ()
 Returns a stringified version of this colour.

Static Public Member Functions

static const Colour fromRGB (const uint8 red, const uint8 green, const uint8 blue) throw ()
 Creates an opaque colour using 8-bit red, green and blue values.
static const Colour fromRGBA (const uint8 red, const uint8 green, const uint8 blue, const uint8 alpha) throw ()
 Creates a colour using 8-bit red, green, blue and alpha values.
static const Colour fromRGBAFloat (const uint8 red, const uint8 green, const uint8 blue, const float alpha) throw ()
 Creates a colour using 8-bit red, green, blue and float alpha values.
static const Colour fromHSV (const float hue, const float saturation, const float brightness, const float alpha) throw ()
 Creates a colour using floating point hue, saturation and brightness values, and an 8-bit alpha.
static const Colour contrasting (const Colour &colour1, const Colour &colour2) throw ()
 Returns a colour that contrasts against two colours.
static const Colour greyLevel (const float brightness) throw ()
 Returns an opaque shade of grey.
static const Colour fromString (const String &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.


Constructor & Destructor Documentation

Colour::Colour (  )  throw ()

Creates a transparent black colour.

Colour::Colour ( const Colour other  )  throw ()

Creates a copy of another Colour object.

Colour::Colour ( const uint32  argb  )  throw () [explicit]

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::Colour ( const uint8  red,
const uint8  green,
const uint8  blue 
) throw ()

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

Colour::Colour ( const uint8  red,
const uint8  green,
const uint8  blue,
const uint8  alpha 
) throw ()

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

Colour::Colour ( const uint8  red,
const uint8  green,
const uint8  blue,
const float  alpha 
) throw ()

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::Colour ( const float  hue,
const float  saturation,
const float  brightness,
const uint8  alpha 
) throw ()

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::Colour ( const float  hue,
const float  saturation,
const float  brightness,
const float  alpha 
) throw ()

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::~Colour (  )  throw ()

Destructor.


Member Function Documentation

static const Colour Colour::fromRGB ( const uint8  red,
const uint8  green,
const uint8  blue 
) throw () [static]

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

static const Colour Colour::fromRGBA ( const uint8  red,
const uint8  green,
const uint8  blue,
const uint8  alpha 
) throw () [static]

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

static const Colour Colour::fromRGBAFloat ( const uint8  red,
const uint8  green,
const uint8  blue,
const float  alpha 
) throw () [static]

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

static const Colour Colour::fromHSV ( const float  hue,
const float  saturation,
const float  brightness,
const float  alpha 
) throw () [static]

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.

const Colour& Colour::operator= ( const Colour other  )  throw ()

Copies another Colour object.

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

Compares two colours.

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

Compares two colours.

uint8 Colour::getRed (  )  const throw ()

Returns the red component of this colour.

Returns:
a value between 0x00 and 0xff.

uint8 Colour::getGreen (  )  const throw ()

Returns the green component of this colour.

Returns:
a value between 0x00 and 0xff.

uint8 Colour::getBlue (  )  const throw ()

Returns the blue component of this colour.

Returns:
a value between 0x00 and 0xff.

float Colour::getFloatRed (  )  const throw ()

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

Returns:
a value between 0.0 and 1.0

float Colour::getFloatGreen (  )  const throw ()

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

Returns:
a value between 0.0 and 1.0

float Colour::getFloatBlue (  )  const throw ()

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

Returns:
a value between 0.0 and 1.0

const PixelARGB Colour::getPixelARGB (  )  const throw ()

Returns a premultiplied ARGB pixel object that represents this colour.

uint32 Colour::getARGB (  )  const throw ()

Returns a 32-bit integer that represents this colour.

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

uint8 Colour::getAlpha (  )  const throw ()

Returns the colour's alpha (opacity).

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

float Colour::getFloatAlpha (  )  const throw ()

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

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

bool Colour::isOpaque (  )  const throw ()

Returns true if this colour is completely opaque.

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

bool Colour::isTransparent (  )  const throw ()

Returns true if this colour is completely transparent.

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

const Colour Colour::withAlpha ( const uint8  newAlpha  )  const throw ()

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

const Colour Colour::withAlpha ( const float  newAlpha  )  const throw ()

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

const Colour Colour::withMultipliedAlpha ( const float  alphaMultiplier  )  const throw ()

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.

const Colour Colour::overlaidWith ( const Colour foregroundColour  )  const throw ()

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.

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

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.

float Colour::getHue (  )  const throw ()

Returns the colour's hue component.

The value returned is in the range 0.0 to 1.0

float Colour::getSaturation (  )  const throw ()

Returns the colour's saturation component.

The value returned is in the range 0.0 to 1.0

float Colour::getBrightness (  )  const throw ()

Returns the colour's brightness component.

The value returned is in the range 0.0 to 1.0

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

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

The values returned are in the range 0.0 to 1.0

const Colour Colour::withHue ( const float  newHue  )  const throw ()

Returns a copy of this colour with a different hue.

const Colour Colour::withSaturation ( const float  newSaturation  )  const throw ()

Returns a copy of this colour with a different saturation.

const Colour Colour::withBrightness ( const float  newBrightness  )  const throw ()

Returns a copy of this colour with a different brightness.

See also:
brighter, darker, withMultipliedBrightness

const Colour Colour::withRotatedHue ( const float  amountToRotate  )  const throw ()

Returns a copy of this colour with it hue rotated.

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

See also:
brighter, darker, withMultipliedBrightness

const Colour Colour::withMultipliedSaturation ( const float  multiplier  )  const throw ()

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

const Colour Colour::withMultipliedBrightness ( const float  amount  )  const throw ()

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

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

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

Returns a brighter version of this colour.

Parameters:
amountBrighter how 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

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

Returns a darker version of this colour.

Parameters:
amountDarker how 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

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

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.

static const Colour Colour::contrasting ( const Colour colour1,
const Colour colour2 
) throw () [static]

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.

static const Colour Colour::greyLevel ( const float  brightness  )  throw () [static]

Returns an opaque shade of grey.

Parameters:
brightness the level of grey to return - 0 is black, 1.0 is white

const String Colour::toString (  )  const throw ()

Returns a stringified version of this colour.

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

static const Colour Colour::fromString ( const String encodedColourString  )  [static]

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


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

Generated on Fri Nov 20 12:00:41 2009 for JUCE by  doxygen 1.5.9