CrystalSpace

Public API Reference

Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | 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   csColor& operator*= (const csColor& c)
00081   { red *= c.red; green *= c.green; blue *= c.blue; return *this; }
00083   bool operator== (const csColor& c) const
00084   { return red == c.red && green == c.green && blue == c.blue; }
00086   bool operator!= (const csColor& c) const
00087   { return red != c.red || green != c.green || blue != c.blue; }
00089   void Add (float r, float g, float b)
00090   { red += r; green += g; blue += b; }
00092   void Subtract (float r, float g, float b)
00093   { red -= r; green -= g; blue -= b; }
00094 };
00095 
00097 inline csColor operator/ (const csColor& v, float f)
00098 { f = 1.0f/f; return csColor(v.red*f, v.green*f, v.blue*f); }
00100 inline csColor operator* (const csColor& v1, const csColor& v2)
00101 {
00102   return csColor (v1.red * v2.red,
00103                   v1.green * v2.green,
00104                   v1.blue * v2.blue);
00105 }
00106 
00110 class csColor4 : public csColor
00111 {
00112 public:
00114   float alpha;
00115 
00117   csColor4 () { }
00119   csColor4 (float r, float g, float b, float a = 1.0f) : csColor (r, g, b)
00120   { alpha = a; }
00121   csColor4 (const csColor& c) : csColor (c), alpha (1.0f) { }
00122   void Set (const csColor& c)
00123   {
00124     red = c.red;
00125     green = c.green;
00126     blue = c.blue;
00127     alpha = 1.0f;
00128   }
00129   void Set (const csColor4& c)
00130   {
00131     red = c.red;
00132     green = c.green;
00133     blue = c.blue;
00134     alpha = c.alpha;
00135   }
00136   void Set (float r, float g, float b)
00137   {
00138     red = r;
00139     green = g;
00140     blue = b;
00141     alpha = 1.0f;
00142   }
00143   void Set (float r, float g, float b, float a)
00144   {
00145     red = r;
00146     green = g;
00147     blue = b;
00148     alpha = a;
00149   }
00151   csColor4& operator= (const csColor4& c)
00152   { red = c.red; green = c.green; blue = c.blue; alpha = c.alpha; return *this; }
00154   csColor4& operator= (const csColor& c)
00155   { red = c.red; green = c.green; blue = c.blue; alpha = 1.0f; return *this; }
00157   csColor4& operator*= (float f)
00158   { red *= f; green *= f; blue *= f; alpha *= f; return *this; }
00160   csColor4& operator+= (const csColor4& c)
00161   { red += c.red; green += c.green; blue += c.blue; alpha += c.alpha; return *this; }
00163   csColor4& operator+= (const csColor& c)
00164   { red += c.red; green += c.green; blue += c.blue; return *this; }
00166   csColor4& operator-= (const csColor4& c)
00167   { red -= c.red; green -= c.green; blue -= c.blue; alpha -= c.alpha; return *this; }
00169   csColor& operator-= (const csColor& c)
00170   { red -= c.red; green -= c.green; blue -= c.blue; return *this; }
00172   bool operator== (const csColor4& c) const
00173   { return red == c.red && green == c.green && blue == c.blue && alpha == c.alpha; }
00175   bool operator!= (const csColor4& c) const
00176   { return red != c.red || green != c.green || blue != c.blue || alpha != c.alpha; }
00177 };
00178 
00180 inline csColor operator* (const csColor& s, float f)
00181 { csColor c (s); c *= f; return c; }
00182 
00184 inline csColor operator* (float f, const csColor& s)
00185 { csColor c (s); c *= f; return c; }
00186 
00188 inline csColor operator+ (const csColor& s1, const csColor& s2)
00189 { csColor c (s1); c += s2; return c; }
00191 inline csColor operator- (const csColor& s1, const csColor& s2)
00192 { csColor c (s1); c -= s2; return c; }
00193 
00194 #endif // __CS_CSCOLOR_H__

Generated for Crystal Space by doxygen 1.4.4