Game Accessibility Library logo SourceForge.net Logo
Game Accessibility Suite: CAT/CATColor.h Source File

CATColor.h

Go to the documentation of this file.
00001 /// \file CATColor.h
00002 /// \brief Color struct/functions for GUI
00003 /// \ingroup CAT
00004 ///
00005 /// Copyright (c) 2002-2008 by Michael Ellison.
00006 /// See COPYING.txt for the \ref gaslicense License (MIT License).
00007 ///
00008 // $Author: mikeellison $
00009 // $Date: 2008-01-21 08:33:12 -0600 (Mon, 21 Jan 2008) $
00010 // $Revision:   $
00011 // $NoKeywords: $
00012 //---------------------------------------------------------------------------
00013 #ifndef CATCOLOR_H_
00014 #define CATCOLOR_H_
00015 
00016 #include "CATTypes.h"
00017 /// \brief   Color structure. Alpha channel - 255 opaque, 0 transparent.
00018 /// \ingroup CAT
00019 struct CATCOLOR
00020 {
00021    union
00022    {      
00023       CATUInt32  rgba;    ///< rgba color - stored in *big endian* format.
00024       struct
00025       {
00026          CATUInt8 r;      ///< red   channel
00027          CATUInt8 g;      ///< green channel
00028          CATUInt8 b;      ///< blue  channel
00029          CATUInt8 a;      ///< alpha channel
00030       };
00031    };
00032 };
00033 
00034 /// \class CATColor
00035 /// \brief Color wrapper class
00036 /// \ingroup CAT
00037 ///
00038 /// Alpha channel - 255 is opaque, 0 is transparent.
00039 class CATColor : public CATCOLOR
00040 {
00041    public:
00042       /// Basic constructor initializes to opaque black.
00043       CATColor()
00044       {
00045          // Default to opaque black.
00046          r = g = b = 0;
00047          a = 255;
00048       }
00049       
00050       /// Construct to build a color by providing red, green, blue, and optionally alpha.
00051       ///
00052       /// All values are 0-255.  255 alpha is opaque, 0 is transparent.
00053       CATColor( CATUInt8 red, 
00054                 CATUInt8 green, 
00055                 CATUInt8 blue,
00056                 CATUInt8 alpha = 255)
00057       {
00058          r = red;
00059          g = green;
00060          b = blue;
00061          a = alpha;
00062       }
00063 
00064       /// Color destructor
00065       ~CATColor()  
00066       {}
00067 
00068       /// Intensity() returns the grey level of the color
00069       ///
00070       /// \return CATUInt8 - intensity / greylevel of color
00071       inline CATUInt8 Intensity() const
00072       {
00073          return ((CATUInt8)( 0.3f*(r) + 0.59f*(g) + 0.11f*(b)));
00074       }   
00075 };
00076 
00077 
00078 #endif // CATCOLOR_H_
00079 
00080 

Generated on Mon Feb 11 04:09:42 2008 for Game Accessibility Suite by doxygen 1.5.4