Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

Ars::RGBColor Class Reference

#include <arsrgbcolor.h>


Public Member Functions

 RGBColor (const unsigned char r, const unsigned char g, const unsigned char b, const unsigned char a=0xFF)
 RGBColor (const Uint32 *pColorValue, const SDL_PixelFormat *pFormat)
unsigned long int SDLColor (SDL_PixelFormat *pFormat) const
bool operator== (const RGBColor &c) const
bool operator!= (const RGBColor &c) const
RGBColoroperator= (const RGBColor &c)
 Assignment operator.

RGBColor operator+ (const RGBColor &c) const
 Does standard color mixing.

RGBColor operator| (const RGBColor &c) const
 Does OR color mixing.

RGBColor operator & (const RGBColor &c) const
 Does AND color mixing.

RGBColor operator^ (const RGBColor &c) const
 Does XOR color mixing.

RGBColor FadeColor (const int factor) const

Data Fields

unsigned char red
 Red component of the color.

unsigned char green
 Green component of the color.

unsigned char blue
 Blue component of the color.

unsigned char alpha
 Alpha component (or opacity) of the color.


Constructor & Destructor Documentation

Ars::RGBColor::RGBColor const unsigned char  r,
const unsigned char  g,
const unsigned char  b,
const unsigned char  a = 0xFF
[inline]
 

Construct a new color object

Parameters:
r Red component value
b Blue component value
g Green component value
a Alpha value, default value of 0xFF (fully opaque)

Definition at line 18 of file arsrgbcolor.h.

References alpha, blue, green, and red.

Referenced by FadeColor(), operator &(), operator+(), operator^(), and operator|().

00019                 : red(r), green(g), blue(b), alpha(a) { }

Ars::RGBColor::RGBColor const Uint32 *  pColorValue,
const SDL_PixelFormat *  pFormat
 

Construct a CRGBColor object from an SDL Color

Parameters:
pColorValue A pointer to the SDL Color
pFormat A pointer to the SDL Pixel Format

Definition at line 5 of file arsrgbcolor.cpp.

References alpha, blue, green, and red.

00006 {
00007         red = static_cast<unsigned char>((pFormat->Rmask & *pColorValue) >> pFormat->Rshift);
00008         green = static_cast<unsigned char>((pFormat->Gmask & *pColorValue) >> pFormat->Gshift);
00009         blue = static_cast<unsigned char>((pFormat->Bmask & *pColorValue) >> pFormat->Bshift);
00010         alpha = static_cast<unsigned char>((pFormat->Amask & *pColorValue) >> pFormat->Ashift);
00011 }


Member Function Documentation

RGBColor Ars::RGBColor::FadeColor const int  factor  )  const
 

Definition at line 52 of file arsrgbcolor.cpp.

References blue, green, red, and RGBColor().

Referenced by Ars::XEditBox::Draw(), Ars::XCheckBox::Draw(), Ars::XBox::Draw(), Ars::XBox::DrawRaised(), and Ars::XBox::DrawSunken().

00053 {
00054         return RGBColor( max( 0 , min( 0xff , red + factor ) ) , max( 0 , min( 0xff , green + factor ) ) , max( 0 , min( 0xff , blue + factor ) ) );
00055 }

RGBColor Ars::RGBColor::operator & const RGBColor c  )  const
 

Does AND color mixing.

Definition at line 41 of file arsrgbcolor.cpp.

References alpha, blue, green, red, and RGBColor().

00042 {
00043         return RGBColor(red & c.red, green & c.green, blue & c.blue, alpha & c.alpha);
00044 }

bool Ars::RGBColor::operator!= const RGBColor c  )  const [inline]
 

Inequality operator does not take into accoutn alpha values

Returns:
true if any of the Red, Green, or Blue color components differ

Definition at line 36 of file arsrgbcolor.h.

References blue, green, and red.

00036 {       return (red != c.red || green != c.green || blue != c.blue);    }

RGBColor Ars::RGBColor::operator+ const RGBColor c  )  const
 

Does standard color mixing.

Definition at line 24 of file arsrgbcolor.cpp.

References alpha, blue, green, red, and RGBColor().

00025 {
00026         double fg_ratio = static_cast<double>(c.alpha) / 0xFF;
00027         double bg_ratio = static_cast<double>(0xFF - c.alpha) / 0xFF;
00028         unsigned char new_red = static_cast<unsigned char>(red * bg_ratio + c.red * fg_ratio);
00029         unsigned char new_green = static_cast<unsigned char>(green * bg_ratio + c.green * fg_ratio);
00030         unsigned char new_blue = static_cast<unsigned char>(blue * bg_ratio + c.blue * fg_ratio);
00031         return RGBColor(new_red, new_green, new_blue, alpha);
00032 }

RGBColor & Ars::RGBColor::operator= const RGBColor c  ) 
 

Assignment operator.

Definition at line 14 of file arsrgbcolor.cpp.

References alpha, blue, green, and red.

00015 {
00016         red = c.red;
00017         green = c.green;
00018         blue = c.blue;
00019         alpha = c.alpha;
00020         return *this;
00021 }

bool Ars::RGBColor::operator== const RGBColor c  )  const [inline]
 

Comparison operator does not take into account alpha values

Returns:
true if the Red, Green, and Blue color components are the same

Definition at line 32 of file arsrgbcolor.h.

References blue, green, and red.

00032 {       return (red == c.red && green == c.green && blue == c.blue);    }

RGBColor Ars::RGBColor::operator^ const RGBColor c  )  const
 

Does XOR color mixing.

Definition at line 47 of file arsrgbcolor.cpp.

References alpha, blue, green, red, and RGBColor().

00048 {
00049         return RGBColor(red ^ c.red, green ^ c.green, blue ^ c.blue, alpha ^ c.alpha);
00050 }

RGBColor Ars::RGBColor::operator| const RGBColor c  )  const
 

Does OR color mixing.

Definition at line 35 of file arsrgbcolor.cpp.

References alpha, blue, green, red, and RGBColor().

00036 {
00037         return RGBColor(red | c.red, green | c.green, blue | c.blue, alpha | c.alpha);
00038 }

unsigned long int Ars::RGBColor::SDLColor SDL_PixelFormat *  pFormat  )  const [inline]
 

Convert the color so an SDL Color

Parameters:
pFormat A pointer to the SDL Pixel Format

Definition at line 28 of file arsrgbcolor.h.

References alpha, blue, green, and red.

Referenced by Ars::HPaint::DrawHLine(), Ars::HPaint::DrawPoint(), Ars::HPaint::DrawRect(), Ars::HPaint::DrawVLine(), and Ars::HPaint::TransparentColor().

00028 {       return SDL_MapRGBA(pFormat, red, green, blue, alpha);   }


Field Documentation

unsigned char Ars::RGBColor::alpha
 

Alpha component (or opacity) of the color.

Definition at line 11 of file arsrgbcolor.h.

Referenced by Cfg::Handler::GetCfgColorHex(), Ars::Rsrc::GetColor(), operator &(), operator+(), operator=(), operator^(), operator|(), RGBColor(), SDLColor(), and Cfg::Handler::SetCfgColorHex().

unsigned char Ars::RGBColor::blue
 

Blue component of the color.

Definition at line 10 of file arsrgbcolor.h.

Referenced by Ars::HPaint::_TextOut(), FadeColor(), Cfg::Handler::GetCfgColorHex(), Ars::Rsrc::GetColor(), operator &(), operator!=(), operator+(), operator=(), operator==(), operator^(), operator|(), RGBColor(), SDLColor(), and Cfg::Handler::SetCfgColorHex().

unsigned char Ars::RGBColor::green
 

Green component of the color.

Definition at line 9 of file arsrgbcolor.h.

Referenced by Ars::HPaint::_TextOut(), FadeColor(), Cfg::Handler::GetCfgColorHex(), Ars::Rsrc::GetColor(), operator &(), operator!=(), operator+(), operator=(), operator==(), operator^(), operator|(), RGBColor(), SDLColor(), and Cfg::Handler::SetCfgColorHex().

unsigned char Ars::RGBColor::red
 

Red component of the color.

Definition at line 8 of file arsrgbcolor.h.

Referenced by Ars::HPaint::_TextOut(), FadeColor(), Cfg::Handler::GetCfgColorHex(), Ars::Rsrc::GetColor(), operator &(), operator!=(), operator+(), operator=(), operator==(), operator^(), operator|(), RGBColor(), SDLColor(), and Cfg::Handler::SetCfgColorHex().


The documentation for this class was generated from the following files:
Generated on Fri Dec 5 04:06:48 2003 for Borqueror by doxygen 1.3.3