SFML logo
  • Main Page
  • Namespaces
  • Classes
  • Files
  • File List

Color.cpp

00001 
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024 
00026 // Headers
00028 #include <SFML/Graphics/Color.hpp>
00029 #include <algorithm>
00030 
00031 
00032 namespace sf
00033 {
00035 // Static member data
00037 const Color Color::Black(0, 0, 0);
00038 const Color Color::White(255, 255, 255);
00039 const Color Color::Red(255, 0, 0);
00040 const Color Color::Green(0, 255, 0);
00041 const Color Color::Blue(0, 0, 255);
00042 const Color Color::Yellow(255, 255, 0);
00043 const Color Color::Magenta(255, 0, 255);
00044 const Color Color::Cyan(0, 255, 255);
00045 
00046 
00048 Color::Color() :
00049 r(0),
00050 g(0),
00051 b(0),
00052 a(255)
00053 {
00054 
00055 }
00056 
00057 
00059 Color::Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) :
00060 r(red),
00061 g(green),
00062 b(blue),
00063 a(alpha)
00064 {
00065 
00066 }
00067 
00068 
00070 bool operator ==(const Color& left, const Color& right)
00071 {
00072     return (left.r == right.r) &&
00073            (left.g == right.g) &&
00074            (left.b == right.b) &&
00075            (left.a == right.a);
00076 }
00077 
00078 
00080 bool operator !=(const Color& left, const Color& right)
00081 {
00082     return !(left == right);
00083 }
00084 
00085 
00087 Color operator +(const Color& left, const Color& right)
00088 {
00089     return Color(static_cast<Uint8>(std::min(left.r + right.r, 255)),
00090                  static_cast<Uint8>(std::min(left.g + right.g, 255)),
00091                  static_cast<Uint8>(std::min(left.b + right.b, 255)),
00092                  static_cast<Uint8>(std::min(left.a + right.a, 255)));
00093 }
00094 
00095 
00097 Color operator *(const Color& left, const Color& right)
00098 {
00099     return Color(static_cast<Uint8>(left.r * right.r / 255),
00100                  static_cast<Uint8>(left.g * right.g / 255),
00101                  static_cast<Uint8>(left.b * right.b / 255),
00102                  static_cast<Uint8>(left.a * right.a / 255));
00103 }
00104 
00105 
00107 Color& operator +=(Color& left, const Color& right)
00108 {
00109     return left = left + right;
00110 }
00111 
00112 
00114 Color& operator *=(Color& left, const Color& right)
00115 {
00116     return left = left * right;
00117 }
00118 
00119 } // namespace sf

 ::  Copyright © 2007-2008 Laurent Gomila, all rights reserved  ::  Documentation generated by doxygen 1.5.2  ::