Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

WP_Color.h

Go to the documentation of this file.
00001 /* Copyright (C) 2001 W.P. van Paassen - peter@paassen.tmfweb.nl
00002 
00003    This program is free software; you can redistribute it and/or modify it under
00004    the terms of the GNU General Public License as published by the Free
00005    Software Foundation; either version 2 of the License, or (at your
00006    option) any later version.
00007 
00008    This program is distributed in the hope that it will be useful, but WITHOUT
00009    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00010    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00011    for more details.
00012 
00013    You should have received a copy of the GNU General Public License
00014    along with this program; see the file COPYING.  If not, write to the Free
00015    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
00016 
00017 #ifndef WP_COLOR_H
00018 #define WP_COLOR_H
00019 
00020 #include "WP_Def.h"
00021 namespace WPCG
00022 {
00041 class WP_Color
00042 {
00043 public:
00044         WP_Color(){ components[0] = components[1] = components[2] = 0.0; components[3] = 1.0;};
00045 
00052         WP_Color(scalar r, scalar g, scalar b, scalar a=1.0){ components[0] = r; components[1] = g; components[2] = b;
00053                 components[3] = a;};
00054 
00061         WP_Color(byte r, byte g, byte b, byte a = 255)
00062           { 
00063             float m = 1.0/255.0;
00064             components[0] = r * m; 
00065             components[1] = g * m; 
00066             components[2] = b * m;
00067             components[3] = a * m;
00068           };
00069 
00070         ~WP_Color(){};
00071 
00072         //copy constructor
00073         WP_Color(const WP_Color& c)
00074           {
00075             components[0] = c.components[0];
00076             components[1] = c.components[1];
00077             components[2] = c.components[2];
00078             components[3] = c.components[3];   
00079           }
00080 
00086         WP_Color& operator=(const WP_Color& c)
00087         {
00088           if (this == &c)
00089             return *this;
00090           components[0] = c.components[0];
00091           components[1] = c.components[1]; 
00092           components[2] = c.components[2];
00093           components[3] = c.components[3];
00094           return *this;
00095         };
00096 
00102         byte fromFloatToByte(int index)
00103           {
00104             if (index >= 0 && index < 4)
00105               {
00106                 return (byte)(components[index] * 255.0);
00107               }
00108             return (byte)0;
00109           }
00110 
00114         scalar components[4];
00115 };
00116 }
00117 #endif
00118 

Generated on Tue Jan 28 20:26:33 2003 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002