GameKit  0.0.1a
C++ gamedev tools
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
gk::Color Class Reference

Utility class for manipulating RGBA colors. More...

#include <Color.hpp>

Public Member Functions

 Color ()=default
 Default constructor. More...
 
 Color (u8 _r, u8 _g, u8 _b, u8 _a=255)
 Construct the color from its 4 RGBA components. More...
 
void invert ()
 
Color operator+ (const Color &c)
 Overload of the binary + operator. More...
 
Color operator- (const Color &c)
 Overload of the binary - operator. More...
 
bool operator== (const Color &color) const
 Overload of binary operator ==. More...
 
bool operator!= (const Color &color) const
 Overload of binary operator !=. More...
 
u8 r255 () const
 
u8 g255 () const
 
u8 b255 () const
 
u8 a255 () const
 

Public Attributes

float r = 1.0f
 Red component. More...
 
float g = 1.0f
 Green component. More...
 
float b = 1.0f
 Blue component. More...
 
float a = 1.0f
 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...
 

Detailed Description

Utility class for manipulating RGBA colors.

This part of the documentation has been taken from SFML Once the migration to SFML 2.6 is done, this file will be removed

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

gk::Color color(255, 0, 0); // red
color.r = 0; // make it black
color.b = 0.5f; // 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 25 of file Color.hpp.

Constructor & Destructor Documentation

§ Color() [1/2]

gk::Color::Color ( )
default

Default constructor.

Constructs an opaque white color. It is equivalent to gk::Color(255, 255, 255, 255).

§ Color() [2/2]

gk::Color::Color ( u8  _r,
u8  _g,
u8  _b,
u8  _a = 255 
)

Construct the color from its 4 RGBA components.

Parameters
_rRed component (in the range [0, 255])
_gGreen component (in the range [0, 255])
_bBlue component (in the range [0, 255])
_aAlpha (opacity) component (in the range [0, 255])

Definition at line 28 of file Color.cpp.

Member Function Documentation

§ a255()

u8 gk::Color::a255 ( ) const
inline

Definition at line 108 of file Color.hpp.

§ b255()

u8 gk::Color::b255 ( ) const
inline

Definition at line 107 of file Color.hpp.

§ g255()

u8 gk::Color::g255 ( ) const
inline

Definition at line 106 of file Color.hpp.

§ invert()

void gk::Color::invert ( )
inline

Definition at line 48 of file Color.hpp.

§ operator!=()

bool gk::Color::operator!= ( const Color color) const
inline

Overload of binary operator !=.

This operator compares strict difference between two colors.

Parameters
colorColor to compare with
Returns
True if this color is not equal to color

Definition at line 100 of file Color.hpp.

§ operator+()

Color gk::Color::operator+ ( const Color c)
inline

Overload of the binary + operator.

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

Parameters
cRight operand
Returns
Result of left + right

Definition at line 61 of file Color.hpp.

§ operator-()

Color gk::Color::operator- ( const Color c)
inline

Overload of the binary - operator.

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

Parameters
cRight operand
Returns
Result of left - right

Definition at line 74 of file Color.hpp.

§ operator==()

bool gk::Color::operator== ( const Color color) const
inline

Overload of binary operator ==.

This operator compares strict equality between two colors.

Parameters
colorColor to compare with
Returns
True if this color is equal to color

Definition at line 86 of file Color.hpp.

§ r255()

u8 gk::Color::r255 ( ) const
inline

Definition at line 105 of file Color.hpp.

Member Data Documentation

§ a

float gk::Color::a = 1.0f

Alpha (opacity) component.

Definition at line 114 of file Color.hpp.

§ b

float gk::Color::b = 1.0f

Blue component.

Definition at line 113 of file Color.hpp.

§ Black

const Color gk::Color::Black
static

Black predefined color.

Definition at line 116 of file Color.hpp.

§ Blue

const Color gk::Color::Blue
static

Blue predefined color.

Definition at line 120 of file Color.hpp.

§ Cyan

const Color gk::Color::Cyan
static

Cyan predefined color.

Definition at line 123 of file Color.hpp.

§ g

float gk::Color::g = 1.0f

Green component.

Definition at line 112 of file Color.hpp.

§ Green

const Color gk::Color::Green
static

Green predefined color.

Definition at line 119 of file Color.hpp.

§ Magenta

const Color gk::Color::Magenta
static

Magenta predefined color.

Definition at line 122 of file Color.hpp.

§ r

float gk::Color::r = 1.0f

Red component.

Definition at line 111 of file Color.hpp.

§ Red

const Color gk::Color::Red
static

Red predefined color.

Definition at line 118 of file Color.hpp.

§ Transparent

const Color gk::Color::Transparent
static

Transparent (black) predefined color.

Definition at line 124 of file Color.hpp.

§ White

const Color gk::Color::White
static

White predefined color.

Definition at line 117 of file Color.hpp.

§ Yellow

const Color gk::Color::Yellow
static

Yellow predefined color.

Definition at line 121 of file Color.hpp.


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