class PColour: public PObject

A class representing a colour specification.

Inheritance:


Public Classes

[more]enum StandardColours
Codes for specification of standard, most common colours.

Public Methods

[more] PColour ( StandardColours col = Black )
Create a standard colour specification.
[more] PColour ( BYTE r, BYTE g, BYTE b, BYTE a = 0xff )
Create a colour of the specified RGB values and alpha channel.
[more] PColour ( const PString & description )
Create a colour from a description string.
[more]virtual PObject* Clone () const
Create a copy of the colour.
[more]virtual Comparison Compare ( const PObject & obj ) const
Determine if the two colours are the same, ie have the save values for all of the components.
[more]virtual PINDEX HashFunction () const
Default hash function for putting colours into dictionaries.
[more]PString GetDescription () const
Get the colour description string.
[more]virtual void SetRed ( BYTE r )
Set the red component of the colour specification.
[more]BYTE GetRed () const
Get the red component of the colour specification.
[more]virtual void SetGreen ( BYTE g )
Set the green component of the colour specification.
[more]BYTE GetGreen () const
Get the greeen component of the colour specification.
[more]virtual void SetBlue ( BYTE b )
Set the blue component of the colour specification.
[more]BYTE GetBlue () const
Get the blue component of the colour specification.
[more]virtual void SetAlpha ( BYTE a )
Set the alpha (opacity) component of the colour specification.
[more]BYTE GetAlpha () const
Get the opaqueness component of the colour specification.
[more]BYTE operator[] ( PINDEX component ) const
Get the component specified by the index.
[more]long GetDistance ( const PColour & other ) const
Calculate a distance metric between the two colours in RGB colour space.

Public

[more] Overrides from class PObject
[more] New functions for class
[more] Component indexes for \Ref{operator[]} access method.

Protected Fields

[more]BYTE component [NumComponents]
Components of the colour


Inherited from PObject:

Public

Run Time Type functions

Comparison functions

I/O functions

Miscellaneous functions


Documentation

A class representing a colour specification. This class provides encapsulation for a 4 component colour. These are the amount of Red, Green, Blue and transparency (Alpha).

This class allows for the representation of an arbitrary colour which may not be able to be realised on the particular drawing canvas. A descendent from this class called a PRealColour always represents a colour that actually can be displayed. For example, for a typical printer canvas the only two colours possible are Black and White.

It is up the application and its colour needs to determine if simply using the PColour or translating it to a PRealColour first is required.

Note that for target drawing systems that do not support the opaqueness to transparency as a continuous value, zero indicates transparent and non-zero indicates full opaque, ie solid colour with no background.

oenum StandardColours
Codes for specification of standard, most common colours. These are the primaries plus some greys and the Clear or transparent colour.

o Black
Red=0, Green=0, Blue=0, Alpha=255

o Red
Red=255, Green=0, Blue=0, Alpha=255

o Green
Red=0, Green=255, Blue=0, Alpha=255

o Yellow
Red=255, Green=255, Blue=0, Alpha=255

o Blue
Red=0, Green=0, Blue=255, Alpha=255

o Magenta
Red=255, Green=0, Blue=255, Alpha=255

o Cyan
Red=0, Green=255, Blue=255, Alpha=255

o White
Red=255, Green=255, Blue=255, Alpha=255

o LightGrey
Red=64, Green=64, Blue=64, Alpha=255

o Grey
Red=128, Green=128, Blue=128, Alpha=255

o DarkGrey
Red=192, Green=192, Blue=192, Alpha=255

o Clear
Red=0, Green=0, Blue=0, Alpha=0

o PColour( StandardColours col = Black )
Create a standard colour specification.
Parameters:
col - Standard colour code

o PColour( BYTE r, BYTE g, BYTE b, BYTE a = 0xff )
Create a colour of the specified RGB values and alpha channel.
Parameters:
r - Red component
g - Green component
b - Blue component
a - Opaqueness, 0=fully transparent, 255=fully opaque

o PColour( const PString & description )
Create a colour from a description string. The description string simply contains the four colour components separated by commas or spaces. The order of the components is red, green, blue and opacity.
Parameters:
description - Standard colour description string.

o Overrides from class PObject

ovirtual PObject* Clone() const
Create a copy of the colour. It is the callers responsibility to delete an object created using this funtion.

Returns:
a new PColour object with the same value.

ovirtual Comparison Compare( const PObject & obj ) const
Determine if the two colours are the same, ie have the save values for all of the components.

Returns:
EqualTo if all componets equal, GreaterThan otherwise.
Parameters:
obj - PColour object to compare against

ovirtual PINDEX HashFunction() const
Default hash function for putting colours into dictionaries.

Returns:
number from 0 to 50 based on the following expression:
((Red ^ 0x55) + (Green ^ 0xaa) + (Blue ^ 0xc3))%51

o New functions for class

oPString GetDescription() const
Get the colour description string. This string defines the colour as a string for use in configuration files etc.

Returns:
description string for colour.

ovirtual void SetRed( BYTE r )
Set the red component of the colour specification.
Parameters:
r - New value for the red component

oBYTE GetRed() const
Get the red component of the colour specification.

Returns:
value from 0 to 255 for the red component.

ovirtual void SetGreen( BYTE g )
Set the green component of the colour specification.
Parameters:
g - New value for the green component

oBYTE GetGreen() const
Get the greeen component of the colour specification.

Returns:
value from 0 to 255 for the green component.

ovirtual void SetBlue( BYTE b )
Set the blue component of the colour specification.
Parameters:
b - New value for the blue component

oBYTE GetBlue() const
Get the blue component of the colour specification.

Returns:
value from 0 to 255 for the blue component.

ovirtual void SetAlpha( BYTE a )
Set the alpha (opacity) component of the colour specification.
Parameters:
a - New value for the opaqueness component

oBYTE GetAlpha() const
Get the opaqueness component of the colour specification.

Returns:
value from 0 to 255 for the opaqueness component.

o Component indexes for \Ref{operator[]} access method.
Component indexes for \Ref{operator[]} access method.

o RedComponent
Red

o GreenComponent
Green

o BlueComponent
Blue

o AlphaComponent
Transparency

oBYTE operator[]( PINDEX component ) const
Get the component specified by the index. The index may be of the following values: 0 for Red, 1 for Green, 2 for Blue, 3 for Alpha.

Returns:
value from 0 to 255 for the component specified.
Parameters:
component - Component index.

olong GetDistance( const PColour & other ) const
Calculate a distance metric between the two colours in RGB colour space.

Returns:
distance metric between the colours.
Parameters:
other - Colour to measure distance from.

oBYTE component[NumComponents]
Components of the colour


Direct child classes:
PRealColour

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.