csutil/cscolor.h
00001 /* 00002 Copyright (C) 1998-2001 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_CSCOLOR_H__ 00020 #define __CS_CSCOLOR_H__ 00021 00022 #include "csextern.h" 00023 00029 class csColor 00030 { 00031 public: 00033 float red; 00035 float green; 00037 float blue; 00038 00039 public: 00041 csColor () { } 00043 csColor (float r, float g, float b) 00044 { red = r; green = g; blue = b; } 00046 csColor (const csColor& c) 00047 { red = c.red; green = c.green; blue = c.blue; } 00049 void Set (float r, float g, float b) 00050 { red = r; green = g; blue = b; } 00052 void Clamp (float r, float g, float b) 00053 { 00054 if (red > r) red = r; 00055 if (green > g) green = g; 00056 if (blue > b) blue = b; 00057 } 00059 void ClampDown () 00060 { 00061 if (red < 0) red = 0; 00062 if (green < 0) green = 0; 00063 if (blue < 0) blue = 0; 00064 } 00066 csColor& operator= (const csColor& c) 00067 { red = c.red; green = c.green; blue = c.blue; return *this; } 00069 csColor& operator*= (float f) 00070 { red *= f; green *= f; blue *= f; return *this; } 00072 csColor& operator+= (const csColor& c) 00073 { red += c.red; green += c.green; blue += c.blue; return *this; } 00075 csColor& operator-= (const csColor& c) 00076 { red -= c.red; green -= c.green; blue -= c.blue; return *this; } 00078 void Add (float r, float g, float b) 00079 { red += r; green += g; blue += b; } 00081 void Subtract (float r, float g, float b) 00082 { red -= r; green -= g; blue -= b; } 00083 }; 00084 00086 inline csColor operator* (const csColor& s, float f) 00087 { csColor c (s); c *= f; return c; } 00088 00090 inline csColor operator* (float f, const csColor& s) 00091 { csColor c (s); c *= f; return c; } 00092 00094 inline csColor operator+ (const csColor& s1, const csColor& s2) 00095 { csColor c (s1); c += s2; return c; } 00097 inline csColor operator- (const csColor& s1, const csColor& s2) 00098 { csColor c (s1); c -= s2; return c; } 00099 00100 #endif // __CS_CSCOLOR_H__
Generated for Crystal Space by doxygen 1.2.18