Public Member Functions | Public Attributes | Static Public Attributes | Related Functions | List of all members
ime::Colour Class Reference

RGBA colour. More...

#include <Colour.h>

Public Member Functions

 Colour ()
 Default constructor. More...
 
 Colour (unsigned int r, unsigned int g, unsigned int b, unsigned alpha=255)
 Construct the color from its 4 RGBA components. More...
 
 Colour (const std::string &colour)
 Construct colour from hex code. More...
 
bool operator== (const Colour &rhs) const
 Check if a colour is the same as this colour. More...
 
bool operator!= (const Colour &rhs) const
 Check if a colour is not the same as this colour. More...
 

Public Attributes

unsigned int red = 0
 Red component. More...
 
unsigned int green = 0
 Green component. More...
 
unsigned int blue = 0
 Blue component. More...
 
unsigned int opacity = 255
 Opacity. More...
 

Static Public Attributes

static const Colour Black
 Black colour. More...
 
static const Colour White
 White colour. More...
 
static const Colour Red
 Red colour. More...
 
static const Colour Green
 Green colour. More...
 
static const Colour Blue
 Blue colour. More...
 
static const Colour Yellow
 Yellow colour. More...
 
static const Colour Orange
 Orange colour. More...
 
static const Colour Brown
 Brown colour. More...
 
static const Colour Maroon
 Maroon colour. More...
 
static const Colour Indigo
 Indigo colour. More...
 
static const Colour Cyan
 Cyan colour. More...
 
static const Colour Magenta
 Magenta colour. More...
 
static const Colour Purple
 Purple colour. More...
 
static const Colour Pink
 Pink colour. More...
 
static const Colour Grey
 Grey colour. More...
 
static const Colour Violet
 Violet colour. More...
 
static const Colour Turquoise
 Turquoise colour. More...
 
static const Colour Gold
 Gold colour. More...
 
static const Colour Silver
 Silver colour. More...
 
static const Colour Transparent
 Transparent colour. More...
 

Related Functions

(Note that these are not member functions.)

IME_API Colour operator+ (const Colour &left, const Colour &right)
 Add two colours together. More...
 
IME_API Colour operator- (const Colour &left, const Colour &right)
 Subtract two colours. More...
 
IME_API Colour operator* (const Colour &left, const Colour &right)
 Multiply/Modulate two colours together. More...
 
IME_API Colouroperator+= (Colour &left, const Colour &right)
 Add two colours together and assign the result to the left operand. More...
 
IME_API Colouroperator-= (Colour &left, const Colour &right)
 Subtract two colours and assign the result to the left operand. More...
 
IME_API Colouroperator*= (Colour &left, const Colour &right)
 Multiply/Modulate two colours together and assign the result to the left operand. More...
 

Detailed Description

RGBA colour.

Definition at line 35 of file Colour.h.

Constructor & Destructor Documentation

◆ Colour() [1/3]

ime::Colour::Colour ( )

Default constructor.

Constructs an opaque black color

◆ Colour() [2/3]

ime::Colour::Colour ( unsigned int  r,
unsigned int  g,
unsigned int  b,
unsigned  alpha = 255 
)

Construct the color from its 4 RGBA components.

Parameters
rRed component
gGreen component
bBlue component
alphaAlpha component

All components must be in the range [0, 255]

◆ Colour() [3/3]

ime::Colour::Colour ( const std::string &  colour)
explicit

Construct colour from hex code.

Parameters
colourThe colour in hex code

The format of the hex code is "#rrggbb" or "#rrggbbaa" where:

  1. rr is the red component
  2. gg is the green component
  3. bb is the blue component
  4. aa is the alpha component

For the "#rrggbb" format, the alpha component is implicitly set to FF. Note that the hex colour code must begin with a '#' symbol

auto colour = Colour("#ff0000")
auto colour = Colour("#ff000b4")
Colour()
Default constructor.

Member Function Documentation

◆ operator!=()

bool ime::Colour::operator!= ( const Colour rhs) const

Check if a colour is not the same as this colour.

Parameters
rhsRight operand
Returns
True if the colours are not the same, otherwise false

◆ operator==()

bool ime::Colour::operator== ( const Colour rhs) const

Check if a colour is the same as this colour.

Parameters
rhsRight operand
Returns
True if the colours are the same, otherwise false

Friends And Related Function Documentation

◆ operator*()

IME_API Colour operator* ( const Colour left,
const Colour right 
)
related

Multiply/Modulate two colours together.

Parameters
leftLeft operand
rightRight operand
Returns
The colour that results from the component-wise multiplication of left and right colours

Note that after the multiplication, components are then divided by 255 to ensure they remain in the range [0, 255]

◆ operator*=()

IME_API Colour & operator*= ( Colour left,
const Colour right 
)
related

Multiply/Modulate two colours together and assign the result to the left operand.

Parameters
leftLeft operand
rightRight operand
Returns
A reference to left

Note that the colours are multiplied component-wise and after the multiplication, components are then divided by 255 to ensure they remain in the range [0, 255]

◆ operator+()

IME_API Colour operator+ ( const Colour left,
const Colour right 
)
related

Add two colours together.

Parameters
leftLeft operand
rightRight operand
Returns
The colour that results from the component-wise sum of left and right colours

Note that the component-wise sum that exceeds 255 will be clamped to 255

◆ operator+=()

IME_API Colour & operator+= ( Colour left,
const Colour right 
)
related

Add two colours together and assign the result to the left operand.

Parameters
leftLeft operand
rightRight operand
Returns
Reference to left

Note that the colours are added together component-wise and the component-wise sum that exceeds 255 will be clamped to 255

◆ operator-()

IME_API Colour operator- ( const Colour left,
const Colour right 
)
related

Subtract two colours.

Parameters
leftLeft operand
rightRight operand
Returns
The colour that results from the component-wise subtraction of left and right colours

Note that the component-wise subtraction that results in a negative value will be clamped to 0

◆ operator-=()

IME_API Colour & operator-= ( Colour left,
const Colour right 
)
related

Subtract two colours and assign the result to the left operand.

Parameters
leftLeft operand
rightRight operand
Returns
A reference to left

Note that the colours are subtracted component-wise and the component-wise subtraction that results in a negative value will be clamped to 0

Member Data Documentation

◆ Black

const Colour ime::Colour::Black
static

Black colour.

Definition at line 38 of file Colour.h.

◆ Blue

const Colour ime::Colour::Blue
static

Blue colour.

Definition at line 42 of file Colour.h.

◆ blue

unsigned int ime::Colour::blue = 0

Blue component.

Definition at line 115 of file Colour.h.

◆ Brown

const Colour ime::Colour::Brown
static

Brown colour.

Definition at line 45 of file Colour.h.

◆ Cyan

const Colour ime::Colour::Cyan
static

Cyan colour.

Definition at line 48 of file Colour.h.

◆ Gold

const Colour ime::Colour::Gold
static

Gold colour.

Definition at line 55 of file Colour.h.

◆ Green

const Colour ime::Colour::Green
static

Green colour.

Definition at line 41 of file Colour.h.

◆ green

unsigned int ime::Colour::green = 0

Green component.

Definition at line 114 of file Colour.h.

◆ Grey

const Colour ime::Colour::Grey
static

Grey colour.

Definition at line 52 of file Colour.h.

◆ Indigo

const Colour ime::Colour::Indigo
static

Indigo colour.

Definition at line 47 of file Colour.h.

◆ Magenta

const Colour ime::Colour::Magenta
static

Magenta colour.

Definition at line 49 of file Colour.h.

◆ Maroon

const Colour ime::Colour::Maroon
static

Maroon colour.

Definition at line 46 of file Colour.h.

◆ opacity

unsigned int ime::Colour::opacity = 255

Opacity.

Definition at line 116 of file Colour.h.

◆ Orange

const Colour ime::Colour::Orange
static

Orange colour.

Definition at line 44 of file Colour.h.

◆ Pink

const Colour ime::Colour::Pink
static

Pink colour.

Definition at line 51 of file Colour.h.

◆ Purple

const Colour ime::Colour::Purple
static

Purple colour.

Definition at line 50 of file Colour.h.

◆ Red

const Colour ime::Colour::Red
static

Red colour.

Definition at line 40 of file Colour.h.

◆ red

unsigned int ime::Colour::red = 0

Red component.

Definition at line 113 of file Colour.h.

◆ Silver

const Colour ime::Colour::Silver
static

Silver colour.

Definition at line 56 of file Colour.h.

◆ Transparent

const Colour ime::Colour::Transparent
static

Transparent colour.

Definition at line 57 of file Colour.h.

◆ Turquoise

const Colour ime::Colour::Turquoise
static

Turquoise colour.

Definition at line 54 of file Colour.h.

◆ Violet

const Colour ime::Colour::Violet
static

Violet colour.

Definition at line 53 of file Colour.h.

◆ White

const Colour ime::Colour::White
static

White colour.

Definition at line 39 of file Colour.h.

◆ Yellow

const Colour ime::Colour::Yellow
static

Yellow colour.

Definition at line 43 of file Colour.h.


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