Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

color.h

00001 /* 00002 libwftk - Worldforge Toolkit - a widget library 00003 Copyright (C) 2002 Malcolm Walker <malcolm@worldforge.org> 00004 Based on code copyright (C) 1999-2002 Karsten Laux 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the 00018 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, SA. 00020 */ 00021 00022 #ifndef _COLOR_H 00023 #define _COLOR_H 00024 00025 #include <iosfwd> 00026 #include <SDL/SDL_version.h> 00027 #include <SDL/SDL_video.h> 00028 00029 #include <wftk/resources.h> 00030 00031 namespace wftk { 00034 class Color 00035 { 00036 public: 00040 enum { 00041 WFTK_TRANSPARENT = SDL_ALPHA_TRANSPARENT, 00042 WFTK_OPAQUE = SDL_ALPHA_OPAQUE 00043 }; 00044 00046 Color() : r(0), g(0), b(0), a(WFTK_OPAQUE) {} 00048 Color(Uint8 red, 00049 Uint8 green, 00050 Uint8 blue, 00051 Uint8 alpha = WFTK_OPAQUE) : r(red), g(green), b(blue),a(alpha) {} 00053 Color(const SDL_Color& c) : r(c.r), g(c.g), b(c.b), a(WFTK_OPAQUE) {} 00055 Color(const std::string& name) {*this = Color::find(name);} 00057 Color(const char* name) {*this = Color::find(name);} 00059 static const Color& find(const std::string&); 00060 00062 friend bool operator==(const Color &c1, const Color &c2) 00063 { 00064 return c1.r==c2.r && c1.g==c2.g && c1.b==c2.b; 00065 } 00067 friend bool operator!=(const Color &c1, const Color &c2) 00068 { 00069 return c1.r!=c2.r || c1.g!=c2.g || c1.b!=c2.b; 00070 } 00072 friend bool operator<(const Color& c1, const Color& c2) 00073 { 00074 return c1.r < c2.r || (c1.r == c2.r && 00075 (c1.g < c2.g || (c1.g == c2.g && c1.b < c2.b))); 00076 } 00077 00079 friend std::ostream& operator<<(std::ostream& s, const Color& c); 00080 00081 struct ResLoad { 00082 std::pair<Color,bool> operator()(const std::string&); 00083 }; 00084 struct ResInval { 00085 typedef const Color& OutType; 00086 OutType operator()(const std::string& resname) const {return Color::find(resname);} 00087 }; 00102 static ResourceRegistry<Color,ResLoad,ResInval> registry; 00104 typedef Resource<Color> Resource; 00105 00107 Uint8 r; 00109 Uint8 g; 00111 Uint8 b; 00113 Uint8 a; 00114 00115 }; 00116 00117 } 00118 00119 #endif // !_COLOR_H

Generated Mon Sep 6 21:58:16 2004.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.