Public Member Functions | Public Attributes | Static Public Attributes | Related Functions | List of all members
cpp3ds::Color Class Reference

Utility class for manpulating RGBA colors. More...

#include <Color.hpp>

Public Member Functions

 Color ()
 Default constructor. More...
 
 Color (Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha=255)
 Construct the color from its 4 RGBA components. More...
 

Public Attributes

Uint8 r
 Red component. More...
 
Uint8 g
 Green component. More...
 
Uint8 b
 Blue component. More...
 
Uint8 a
 Alpha (opacity) component. More...
 

Static Public Attributes

static const Color Black
 Black predefined color. More...
 
static const Color White
 White predefined color. More...
 
static const Color Red
 Red predefined color. More...
 
static const Color Green
 Green predefined color. More...
 
static const Color Blue
 Blue predefined color. More...
 
static const Color Yellow
 Yellow predefined color. More...
 
static const Color Magenta
 Magenta predefined color. More...
 
static const Color Cyan
 Cyan predefined color. More...
 
static const Color Transparent
 Transparent (black) predefined color. More...
 

Related Functions

(Note that these are not member functions.)

bool operator== (const Color &left, const Color &right)
 Overload of the == operator. More...
 
bool operator!= (const Color &left, const Color &right)
 Overload of the != operator. More...
 
Color operator+ (const Color &left, const Color &right)
 Overload of the binary + operator. More...
 
Color operator- (const Color &left, const Color &right)
 Overload of the binary - operator. More...
 
Color operator* (const Color &left, const Color &right)
 Overload of the binary * operator. More...
 
Coloroperator+= (Color &left, const Color &right)
 Overload of the binary += operator. More...
 
Coloroperator-= (Color &left, const Color &right)
 Overload of the binary -= operator. More...
 
Coloroperator*= (Color &left, const Color &right)
 Overload of the binary *= operator. More...
 

Detailed Description

Utility class for manpulating RGBA colors.

cpp3ds::Color is a simple color class composed of 4 components:

Each component is a public member, an unsigned integer in the range [0, 255]. Thus, colors can be constructed and manipulated very easily:

cpp3ds::Color color(255, 0, 0); // red
color.r = 0; // make it black
color.b = 128; // make it dark blue

The fourth component of colors, named "alpha", represents the opacity of the color. A color with an alpha value of 255 will be fully opaque, while an alpha value of 0 will make a color fully transparent, whatever the value of the other components is.

The most common colors are already defined as static variables:

Colors can also be added and modulated (multiplied) using the overloaded operators + and *.

Definition at line 36 of file Color.hpp.

Constructor & Destructor Documentation

cpp3ds::Color::Color ( )

Default constructor.

Constructs an opaque black color. It is equivalent to cpp3ds::Color(0, 0, 0, 255).

cpp3ds::Color::Color ( Uint8  red,
Uint8  green,
Uint8  blue,
Uint8  alpha = 255 
)

Construct the color from its 4 RGBA components.

Parameters
redRed component (in the range [0, 255])
greenGreen component (in the range [0, 255])
blueBlue component (in the range [0, 255])
alphaAlpha (opacity) component (in the range [0, 255])

Friends And Related Function Documentation

bool operator!= ( const Color left,
const Color right 
)
related

Overload of the != operator.

This operator compares two colors and check if they are different.

Parameters
leftLeft operand
rightRight operand
Returns
True if colors are different, false if they are equal
Color operator* ( const Color left,
const Color right 
)
related

Overload of the binary * operator.

This operator returns the component-wise multiplication (also called "modulation") of two colors. Components are then divided by 255 so that the result is still in the range [0, 255].

Parameters
leftLeft operand
rightRight operand
Returns
Result of left * right
Color & operator*= ( Color left,
const Color right 
)
related

Overload of the binary *= operator.

This operator returns the component-wise multiplication (also called "modulation") of two colors, and assigns the result to the left operand. Components are then divided by 255 so that the result is still in the range [0, 255].

Parameters
leftLeft operand
rightRight operand
Returns
Reference to left
Color operator+ ( const Color left,
const Color right 
)
related

Overload of the binary + operator.

This operator returns the component-wise sum of two colors. Components that exceed 255 are clamped to 255.

Parameters
leftLeft operand
rightRight operand
Returns
Result of left + right
Color & operator+= ( Color left,
const Color right 
)
related

Overload of the binary += operator.

This operator computes the component-wise sum of two colors, and assigns the result to the left operand. Components that exceed 255 are clamped to 255.

Parameters
leftLeft operand
rightRight operand
Returns
Reference to left
Color operator- ( const Color left,
const Color right 
)
related

Overload of the binary - operator.

This operator returns the component-wise subtraction of two colors. Components below 0 are clamped to 0.

Parameters
leftLeft operand
rightRight operand
Returns
Result of left - right
Color & operator-= ( Color left,
const Color right 
)
related

Overload of the binary -= operator.

This operator computes the component-wise subtraction of two colors, and assigns the result to the left operand. Components below 0 are clamped to 0.

Parameters
leftLeft operand
rightRight operand
Returns
Reference to left
bool operator== ( const Color left,
const Color right 
)
related

Overload of the == operator.

This operator compares two colors and check if they are equal.

Parameters
leftLeft operand
rightRight operand
Returns
True if colors are equal, false if they are different

Member Data Documentation

Uint8 cpp3ds::Color::a

Alpha (opacity) component.

Definition at line 79 of file Color.hpp.

Uint8 cpp3ds::Color::b

Blue component.

Definition at line 78 of file Color.hpp.

const Color cpp3ds::Color::Black
static

Black predefined color.

Definition at line 63 of file Color.hpp.

const Color cpp3ds::Color::Blue
static

Blue predefined color.

Definition at line 67 of file Color.hpp.

const Color cpp3ds::Color::Cyan
static

Cyan predefined color.

Definition at line 70 of file Color.hpp.

Uint8 cpp3ds::Color::g

Green component.

Definition at line 77 of file Color.hpp.

const Color cpp3ds::Color::Green
static

Green predefined color.

Definition at line 66 of file Color.hpp.

const Color cpp3ds::Color::Magenta
static

Magenta predefined color.

Definition at line 69 of file Color.hpp.

Uint8 cpp3ds::Color::r

Red component.

Definition at line 76 of file Color.hpp.

const Color cpp3ds::Color::Red
static

Red predefined color.

Definition at line 65 of file Color.hpp.

const Color cpp3ds::Color::Transparent
static

Transparent (black) predefined color.

Definition at line 71 of file Color.hpp.

const Color cpp3ds::Color::White
static

White predefined color.

Definition at line 64 of file Color.hpp.

const Color cpp3ds::Color::Yellow
static

Yellow predefined color.

Definition at line 68 of file Color.hpp.


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