class MASKING_DLL_DECLSPEC Color

Represents an Allegro color.

Public Fields

[more]static Color white
[more]static Color black
[more]static Color red
[more]static Color green
[more]static Color blue
[more]static Color cyan
[more]static Color magenta
[more]static Color yellow
[more]static Color darkgray
[more]static Color gray
[more]static Color lightgray
[more]static Color orange
[more]static Color purple
[more]static Color brown
[more]static Color maroon
[more]static Color darkgreen
[more]static Color darkblue
The most commonly used basic colours.

Public Methods

[more] Color(int c=-1)
The default constructor.
[more] Color(int r, int g, int b)
The constructor for making a color from RGB components.
[more] Color(float h, float s, float v)
The constructors for making a color from HSV components.
[more] Color(int r, int g, int b, int a)
The constructor for making a color from RGBA components.
[more] Color(const char* str)
The constructor for making a color from a string description.
[more]void Make(int r, int g, int b)
Makes the color from RGB components
[more]void Make(int r, int g, int b, int a)
Makes the color from RGBA components
[more]void Make(const char* str)
Read the color from a string
[more] operator int() const
Casts the color to an integer value.
[more]void operator=(int c)
Assignment operator for creating a color from an Allegro color value
[more] operator bool() const
Casts a color to a bool value.
[more]bool operator==(const Color c)
[more]bool operator!=(const Color c)
[more]bool operator==(int c)
[more]bool operator!=(int c)
Operators for determining the equality of two colours
[more]int r() const
Returns the colour's R component
[more]int g() const
Returns the colour's G component
[more]int b() const
Returns the colour's B component
[more]int a() const
Returns the colour's A component (alpha)
[more]void r(int _r)
Sets the colour's R component
[more]void g(int _g)
Sets the colour's G component
[more]void b(int _b)
Sets the colour's B component
[more]void a(int _a)
Sets the colour's B component
[more]void ToHSV(float &h, float &s, float &v) const
Breaks the colour down to HSV component
[more]void ToRGB(int &r, int &g, int &b) const
Breaks the colour down to RGB component
[more]static void RGBToHSV(int r, int g, int b, float &h, float &s, float &v)
Converts an RGB representation of a colour to HSV
[more]static void HSVToRGB(float h, float s, float v, int &r, int &g, int &b)
Converts an HSV representation of a colour to RGB
[more]void Colorize(const Color &c, int alpha)
Colorizes the color with the given second color and alpha intensity.
[more]static void OnColorDepthChange()
Recreates the common colors.

Protected Fields

[more]int col
The underlying Allegro color value


Documentation

Represents an Allegro color. It has methods for building colors out of RGB and HSV components and braking them down in those components again. There are unctions for converting between the RGB and HSV color spaces and for reading a color from a string. Also some of the most comonly used colors are available as static data members.
oint col
The underlying Allegro color value

o Color(int c=-1)
The default constructor. The constructor for making a color from an actual Allegro color value.

o Color(int r, int g, int b)
The constructor for making a color from RGB components. All three colours are integers in the range between 0 and 255.

o Color(float h, float s, float v)
The constructors for making a color from HSV components. Hue is a value between 0 and 360, while saturation and value are between 0 and 1.

o Color(int r, int g, int b, int a)
The constructor for making a color from RGBA components. A is the alpha component and must be in the range between 0 and 255.

o Color(const char* str)
The constructor for making a color from a string description. The string must contain RGB components separated with commas or semicolons or it can be "-1".

Examples of constructing a color:

      Color c1(makecol(120, 240, 180));
      Color c2(120, 240, 180);
      Color c3(300.0, 140.0, 45.0));
      Color c4(120, 240, 180, 200);
      Color c5("120,240,180");

ovoid Make(int r, int g, int b)
Makes the color from RGB components

ovoid Make(int r, int g, int b, int a)
Makes the color from RGBA components

ovoid Make(const char* str)
Read the color from a string

o operator int() const
Casts the color to an integer value. This allows you to use a Color as if it was an int. That means you can use objects of type Color in all Allegro functions that normally take int as a color parameter.

Examples:

      clear_to_color(screen, Color::white);
      rectfill(screen, 20, 30, 200, 150, Color(123, 234, 100));

ovoid operator=(int c)
Assignment operator for creating a color from an Allegro color value

o operator bool() const
Casts a color to a bool value. True if it's a valid color, false if it isn't (i.e. less than 0).

Note: this doesn't work with 32 bit RGBA colors.

obool operator==(const Color c)

obool operator!=(const Color c)

obool operator==(int c)

obool operator!=(int c)
Operators for determining the equality of two colours

oint r() const
Returns the colour's R component

oint g() const
Returns the colour's G component

oint b() const
Returns the colour's B component

oint a() const
Returns the colour's A component (alpha)

ovoid r(int _r)
Sets the colour's R component

ovoid g(int _g)
Sets the colour's G component

ovoid b(int _b)
Sets the colour's B component

ovoid a(int _a)
Sets the colour's B component

ovoid ToHSV(float &h, float &s, float &v) const
Breaks the colour down to HSV component

ovoid ToRGB(int &r, int &g, int &b) const
Breaks the colour down to RGB component

ostatic void RGBToHSV(int r, int g, int b, float &h, float &s, float &v)
Converts an RGB representation of a colour to HSV

ostatic void HSVToRGB(float h, float s, float v, int &r, int &g, int &b)
Converts an HSV representation of a colour to RGB

ovoid Colorize(const Color &c, int alpha)
Colorizes the color with the given second color and alpha intensity. Colorizing means that you take one color and shift its hue to the hue of a second color while leaving the saturation and lightness the same. Alpha intensity in this function is the balance between the source and the target colors and is a value between 0 and 255. At 0 the original color is not modified at all while at 255 the source color's hue is completely changed to the target color's hue.

ostatic Color white

ostatic Color black

ostatic Color red

ostatic Color green

ostatic Color blue

ostatic Color cyan

ostatic Color magenta

ostatic Color yellow

ostatic Color darkgray

ostatic Color gray

ostatic Color lightgray

ostatic Color orange

ostatic Color purple

ostatic Color brown

ostatic Color maroon

ostatic Color darkgreen

ostatic Color darkblue
The most commonly used basic colours. Available as public static data members.

ostatic void OnColorDepthChange()
Recreates the common colors. When the color depth has changed the static colours need to be recreated because the actual color values are dependant on the current color depth. This function is automatically called when a color depth change occurs.


This class has no child classes.

Alphabetic index Hierarchy of classes


Back to front page   |   page generated with DOC++