Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
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 public: 00040 csColor () { } 00042 csColor (float r, float g, float b) 00043 { red = r; green = g; blue = b; } 00045 csColor (const csColor& c) 00046 { red = c.red; green = c.green; blue = c.blue; } 00048 void Set (float r, float g, float b) 00049 { red = r; green = g; blue = b; } 00051 void Set (const csColor& c) 00052 { red = c.red; green = c.green; blue = c.blue; } 00054 void Clamp (float r, float g, float b) 00055 { 00056 if (red > r) red = r; 00057 if (green > g) green = g; 00058 if (blue > b) blue = b; 00059 } 00061 void ClampDown () 00062 { 00063 if (red < 0) red = 0; 00064 if (green < 0) green = 0; 00065 if (blue < 0) blue = 0; 00066 } 00068 csColor& operator= (const csColor& c) 00069 { red = c.red; green = c.green; blue = c.blue; return *this; } 00071 csColor& operator*= (float f) 00072 { red *= f; green *= f; blue *= f; return *this; } 00074 csColor& operator+= (const csColor& c) 00075 { red += c.red; green += c.green; blue += c.blue; return *this; } 00077 csColor& operator-= (const csColor& c) 00078 { red -= c.red; green -= c.green; blue -= c.blue; return *this; } 00080 bool operator== (const csColor& c) const 00081 { return red == c.red && green == c.green && blue == c.blue; } 00083 bool operator!= (const csColor& c) const 00084 { return red != c.red || green != c.green || blue != c.blue; } 00086 void Add (float r, float g, float b) 00087 { red += r; green += g; blue += b; } 00089 void Subtract (float r, float g, float b) 00090 { red -= r; green -= g; blue -= b; } 00091 }; 00092 00094 inline csColor operator/ (const csColor& v, float f) 00095 { f = 1.0f/f; return csColor(v.red*f, v.green*f, v.blue*f); } 00097 inline csColor operator* (const csColor& v1, const csColor& v2) 00098 { 00099 return csColor (v1.red * v2.red, 00100 v1.green * v2.green, 00101 v1.blue * v2.blue); 00102 } 00103 00107 class csColor4 : public csColor 00108 { 00109 public: 00111 float alpha; 00112 00114 csColor4 () { } 00116 csColor4 (float r, float g, float b, float a = 1.0f) : csColor (r, g, b) 00117 { alpha = a; } 00118 csColor4 (const csColor& c) : csColor (c), alpha (1.0f) { } 00119 void Set (const csColor& c) 00120 { 00121 red = c.red; 00122 green = c.green; 00123 blue = c.blue; 00124 alpha = 1.0f; 00125 } 00126 void Set (const csColor4& c) 00127 { 00128 red = c.red; 00129 green = c.green; 00130 blue = c.blue; 00131 alpha = c.alpha; 00132 } 00133 void Set (float r, float g, float b) 00134 { 00135 red = r; 00136 green = g; 00137 blue = b; 00138 alpha = 1.0f; 00139 } 00140 void Set (float r, float g, float b, float a) 00141 { 00142 red = r; 00143 green = g; 00144 blue = b; 00145 alpha = a; 00146 } 00148 csColor4& operator= (const csColor4& c) 00149 { red = c.red; green = c.green; blue = c.blue; alpha = c.alpha; return *this; } 00151 csColor4& operator= (const csColor& c) 00152 { red = c.red; green = c.green; blue = c.blue; alpha = 1.0f; return *this; } 00154 csColor4& operator*= (float f) 00155 { red *= f; green *= f; blue *= f; alpha *= f; return *this; } 00157 csColor4& operator+= (const csColor4& c) 00158 { red += c.red; green += c.green; blue += c.blue; alpha += c.alpha; return *this; } 00160 csColor4& operator+= (const csColor& c) 00161 { red += c.red; green += c.green; blue += c.blue; return *this; } 00163 csColor4& operator-= (const csColor4& c) 00164 { red -= c.red; green -= c.green; blue -= c.blue; alpha -= c.alpha; return *this; } 00166 csColor& operator-= (const csColor& c) 00167 { red -= c.red; green -= c.green; blue -= c.blue; return *this; } 00169 bool operator== (const csColor4& c) const 00170 { return red == c.red && green == c.green && blue == c.blue && alpha == c.alpha; } 00172 bool operator!= (const csColor4& c) const 00173 { return red != c.red || green != c.green || blue != c.blue || alpha != c.alpha; } 00174 }; 00175 00177 inline csColor operator* (const csColor& s, float f) 00178 { csColor c (s); c *= f; return c; } 00179 00181 inline csColor operator* (float f, const csColor& s) 00182 { csColor c (s); c *= f; return c; } 00183 00185 inline csColor operator+ (const csColor& s1, const csColor& s2) 00186 { csColor c (s1); c += s2; return c; } 00188 inline csColor operator- (const csColor& s1, const csColor& s2) 00189 { csColor c (s1); c -= s2; return c; } 00190 00191 #endif // __CS_CSCOLOR_H__
Generated for Crystal Space by doxygen 1.3.9.1