color_range.hpp

Go to the documentation of this file.
00001 /* $Id: color_range.hpp 23842 2008-02-16 08:47:16Z mordante $ */
00002 /*
00003    Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 //! @file color_range.hpp
00016 //!
00017 
00018 #ifndef COLOR_RANGE_H_INCLUDED
00019 #define COLOR_RANGE_H_INCLUDED
00020 
00021 //These macros interfere with MS VC++
00022 #ifdef _MSC_VER
00023     #undef max
00024     #undef min
00025 #endif
00026 
00027 #include "global.hpp"
00028 #include <map>
00029 #include <string>
00030 #include <vector>
00031 
00032 #include "SDL_types.h"
00033 
00034 //- Convert comma separated string into rgb values
00035 std::vector<Uint32> string2rgb(std::string s);
00036 
00037 class color_range
00038 {
00039 public:
00040   color_range(Uint32 mid , Uint32 max = 0x00FFFFFF , Uint32 min = 0x00000000 , Uint32 rep = 0x00808080):mid_(mid),max_(max),min_(min),rep_(rep){};
00041   color_range(const std::vector<Uint32>& v)
00042     : mid_(v.size()     ? v[0] : 0x00808080),
00043       max_(v.size() > 1 ? v[1] : 0x00FFFFFF),
00044       min_(v.size() > 2 ? v[2] : 0x00000000),
00045       rep_(v.size() > 3 ? v[3] : mid_)
00046   {
00047   };
00048   color_range() : mid_(0x00808080), max_(0x00FFFFFF), min_(0x00000000), rep_(0x00808080) {};
00049   Uint32 mid() const{return(mid_);};
00050   Uint32 max() const{return(max_);};
00051   Uint32 min() const{return(min_);};
00052 //note: use mid() instead of rep() unless high contrast is needed over a map or minimap!
00053   Uint32 rep() const{return(rep_);};
00054   bool operator<(const color_range& b) const
00055   {
00056     if(mid_ != b.mid()) return(mid_ < b.mid());
00057     if(max_ != b.max()) return(max_ < b.max());
00058     if(min_ != b.min()) return(min_ < b.min());
00059     return(rep_ < b.rep());
00060   }
00061   bool operator==(const color_range& b) const
00062   {
00063     return(mid_ == b.mid() && max_ == b.max() && min_ == b.min() && rep_ == b.rep());
00064   }
00065   int index() const; // the default team index for this color, or 0 for none
00066 private:
00067   Uint32 mid_ , max_ , min_ , rep_;
00068 };
00069 
00070 std::vector<Uint32> palette(color_range cr); //return color palette from color range
00071 std::map<Uint32, Uint32> recolor_range(const color_range& new_rgb, const std::vector<Uint32>& old_rgb);
00072 std::string rgb2highlight(Uint32 rgb);
00073 #endif

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs