Angel 3.2
A 2D Game Prototyping Engine
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Color Class Reference

A class to encapsulate color information. More...

#include <Color.h>

Public Member Functions

 Color ()
 
 Color (float r, float g, float b, float a=1.0f, bool clamp=true)
 
bool operator== (const Color &c) const
 
bool operator!= (const Color &c) const
 
Color operator- (const Color &c) const
 
Color operator+ (const Color &c) const
 
Color operator/ (float divider) const
 
Color operator* (float scaleFactor) const
 

Static Public Member Functions

static Color FromInts (int r, int g, int b, int a=255, bool clamp=true)
 
static Color FromHexString (String hexString)
 

Public Attributes

float R
 
float G
 
float B
 
float A
 

Detailed Description

This class consolidates all color information into a single unit that can be easily passed around functions, manipulated, and lerped.

The four color components are public members since they are frequently accessed and there is no real reason to hide them behind accessors. They are always stored as floats and range from 0.0f to 1.0f.

Note that the common arithmetical and comparison operators are defined for this class, to make it easy to mathematically manipulate the color of your Actors.

Definition at line 47 of file Color.h.

Constructor & Destructor Documentation

Color::Color ( )

The default constructor creates an opaque, pure white (all components are 1.0f).

Definition at line 36 of file Color.cpp.

Color::Color ( float  r,
float  g,
float  b,
float  a = 1.0f,
bool  clamp = true 
)

A constructor to specify component values right from the start.

Parameters
rThe Red component
gThe Green component
bThe Blue component
aThe Alpha component
clampWhether or not to clamp the components to the range 0.0 to 1.0. Usually you want to do this (and the default reflects this case), unless you're doing some kind of nutty color math, in which case you should set this to false.

Definition at line 42 of file Color.cpp.

Member Function Documentation

Color Color::FromInts ( int  r,
int  g,
int  b,
int  a = 255,
bool  clamp = true 
)
static

A function to specify colors as integers from 0 to 255. Useful if you've got a color picker you like that gives you values in this range.

Note that internally the numbers are converted to floats from 0 to 1.

Parameters
rThe Red component
gThe Green component
bThe Blue component
aThe Alpha component
clampWhether or not to clamp the components to the range 0.0 to 1.0. Usually you want to do this (and the default reflects this case), unless you're doing some kind of nutty color math, in which case you should set this to false.

Definition at line 55 of file Color.cpp.

Color Color::FromHexString ( String  hexString)
static

A function to specify a color as a hex string, like in CSS. For those used to specifying colors for web pages, you have an option here.

Parameters
hexStringThe string identifying the color ("0xfff", "#fa6244", etc.)

Definition at line 71 of file Color.cpp.

Member Data Documentation

float Color::R

The Red component

Definition at line 53 of file Color.h.

float Color::G

The Green component

Definition at line 57 of file Color.h.

float Color::B

The Blue component

Definition at line 61 of file Color.h.

float Color::A

The Alpha component (1.0 == opaque, 0.0 == invisible)

Definition at line 65 of file Color.h.


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