Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

color.h

Go to the documentation of this file.
00001 // color.h
00002 //
00003 // Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 #ifndef _COLOR_H_
00011 #define _COLOR_H_
00012 
00013 class Color
00014 {
00015  public:
00016     Color();
00017     Color(float, float, float);
00018     Color(float, float, float, float);
00019     Color(unsigned char, unsigned char, unsigned char);
00020     Color(Color&, float);
00021 
00022     enum {
00023         Red    = 0,
00024         Green  = 1,
00025         Blue   = 2,
00026         Alpha  = 3
00027     };
00028 
00029     inline float red() const;
00030     inline float green() const;
00031     inline float blue() const;
00032     inline float alpha() const;
00033     inline void get(unsigned char*) const;
00034 
00035     friend bool operator==(Color, Color);
00036     friend bool operator!=(Color, Color);
00037     friend Color operator*(Color, Color);
00038 
00039     static const Color Black;
00040     static const Color White;
00041 
00042     static bool parse(const char*, Color&);
00043 
00044  private:
00045     unsigned char c[4];
00046 };
00047 
00048 
00049 float Color::red() const
00050 {
00051     return c[Red] * (1.0f / 255.0f);
00052 }
00053 
00054 float Color::green() const
00055 {
00056     return c[Green] * (1.0f / 255.0f);
00057 }
00058 
00059 float Color::blue() const
00060 {
00061     return c[Blue] * (1.0f / 255.0f);
00062 }
00063 
00064 float Color::alpha() const
00065 {
00066     return c[Alpha] * (1.0f / 255.0f);
00067 }
00068 
00069 void Color::get(unsigned char* rgba) const
00070 {
00071     rgba[0] = c[Red];
00072     rgba[1] = c[Green];
00073     rgba[2] = c[Blue];
00074     rgba[3] = c[Alpha];
00075 }
00076 
00077 inline bool operator==(Color a, Color b)
00078 {
00079     return (a.c[0] == b.c[2] && a.c[1] == b.c[1] &&
00080             a.c[2] == b.c[2] && a.c[3] == b.c[3]);
00081 }
00082 
00083 inline bool operator!=(Color a, Color b)
00084 {
00085     return !(a == b);
00086 }
00087 
00088 inline Color operator*(Color a, Color b)
00089 {
00090     return Color(a.red() * b.red(),
00091                  a.green() * b.green(),
00092                  a.blue() * b.blue(),
00093                  a.alpha() * b.alpha());
00094 }
00095 
00096 #endif // _COLOR_H_

Generated on Sat Jan 14 22:30:32 2006 for Celestia by  doxygen 1.4.1