src/video/color.hpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program 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
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef HEADER_SUPERTUX_VIDEO_COLOR_HPP
00018 #define HEADER_SUPERTUX_VIDEO_COLOR_HPP
00019 
00020 #include <assert.h>
00021 #include <vector>
00022 
00023 #include "util/log.hpp"
00024 
00025 class Color
00026 {
00027 public:
00028   Color() :
00029     red(0), 
00030     green(0), 
00031     blue(0), 
00032     alpha(1.0f)
00033   {}
00034 
00035   Color(float red_, float green_, float blue_, float alpha_ = 1.0) :
00036     red(red_),
00037     green(green_), 
00038     blue(blue_), 
00039     alpha(alpha_)
00040   {
00041     assert(0 <= red   && red <= 1.0);
00042     assert(0 <= green && green <= 1.0);
00043     assert(0 <= blue  && blue <= 1.0);
00044   }
00045 
00046   Color(const std::vector<float>& vals) :
00047     red(),
00048     green(),
00049     blue(),
00050     alpha()
00051   {
00052     assert(vals.size() >= 3);
00053     red   = vals[0];
00054     green = vals[1];
00055     blue  = vals[2];
00056     if(vals.size() > 3)
00057       alpha = vals[3];
00058     else
00059       alpha = 1.0;
00060     assert(0 <= red   && red <= 1.0);
00061     assert(0 <= green && green <= 1.0);
00062     assert(0 <= blue  && blue <= 1.0);
00063   }
00064 
00065   bool operator==(const Color& other) const
00066   {
00067     return red == other.red && green == other.green && blue == other.blue
00068       && alpha == other.alpha;
00069   }
00070 
00071   float greyscale() const
00072   {
00073     return red * 0.30 + green * 0.59 + blue * 0.11;
00074   }
00075 
00076   bool operator < (const Color& other) const
00077   {
00078     return greyscale() < other.greyscale();
00079   }
00080 
00081   float red, green, blue, alpha;
00082 
00083   static const Color BLACK;
00084   static const Color RED;
00085   static const Color GREEN;
00086   static const Color BLUE;
00087   static const Color CYAN;
00088   static const Color MAGENTA;
00089   static const Color YELLOW;
00090   static const Color WHITE;
00091 };
00092 
00093 #endif
00094 
00095 /* EOF */

Generated on Mon Jun 9 03:38:23 2014 for SuperTux by  doxygen 1.5.1