Upstream tarball 20080512
[amule.git] / src / Color.h
blob17ac69ddefffdea44328696fe5f6c9d4cdacbd22
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2004-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2004-2008 Carlo Wood <carlo@alinoe.com>
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #ifndef COLOR_H
27 #define COLOR_H
29 #if !defined(__WXPM__) && !defined(__WXMSW__) // Otherwise already defined in wx/defs.h.
30 #include <inttypes.h> // Do_not_auto_remove (old gcc)
31 typedef uint32_t COLORREF;
32 #else
33 #include "Types.h" // Do_not_auto_remove (Needed for windows compilation)
34 typedef unsigned long COLORREF;
35 #endif
38 inline int G_BLEND(int a, int percentage)
40 int result = a * percentage / 100;
41 return (result > 255) ? 255 : result;
45 #if !defined(__WXMSW__)
46 inline COLORREF RGB(int a, int b, int c)
48 COLORREF result;
49 result = (c & 0xff) << 16;
50 result |= (b & 0xff) << 8;
51 result |= (a & 0xff);
52 return result;
56 inline int GetBValue(COLORREF rgb)
58 return (rgb >> 16) & 0xff;
62 inline int GetGValue(COLORREF rgb)
64 return (rgb >> 8) & 0xff;
68 inline int GetRValue(COLORREF rgb)
70 return rgb & 0xff;
73 #endif
76 inline COLORREF DarkenColour(COLORREF rgb, int level)
78 return RGB(GetRValue(rgb) / level, GetGValue(rgb) / level, GetBValue(rgb) / level);
82 #if wxUSE_GUI
84 #include <wx/colour.h> // Needed for wxColour
86 inline wxColour BLEND( wxColour colour, int percentage )
88 int red = G_BLEND( colour.Red(), percentage );
89 int green = G_BLEND( colour.Green(), percentage );
90 int blue = G_BLEND( colour.Blue(), percentage );
92 return wxColour( red, green, blue );
96 inline wxColour WxColourFromCr(COLORREF cr)
98 return wxColour(GetRValue(cr),GetGValue(cr),GetBValue(cr));
102 inline COLORREF CrFromWxColour(wxColour col)
104 return RGB(col.Red(), col.Green(), col.Blue());
107 #endif /* wxUSE_GUI */
109 #define SYSCOLOR(x) (wxSystemSettings::GetColour(x))
112 #endif
113 // File_checked_for_headers