2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include <wx/colour.h>
29 #include <wx/settings.h>
39 enum ColourComponent
{ COLOUR_R
= 1, COLOUR_G
= 2, COLOUR_B
= 4 };
41 CMuleColour() { Init(); Set(0,0,0); }
42 CMuleColour(const wxColour
& colour
) { Init(); Set(colour
.Red(), colour
.Green(), colour
.Blue()); }
43 CMuleColour(uint8_t r
, uint8_t g
, uint8_t b
) { Init(); Set(r
,g
,b
); }
44 CMuleColour(unsigned long rgb
)
47 Set((rgb
& 0xFF), (rgb
>> 8) & 0xFF, (rgb
>> 16) & 0xFF);
50 CMuleColour(wxSystemColour colour
)
53 const wxColour
& wxcolour
= wxSystemSettings::GetColour(colour
);
54 Set(wxcolour
.Red(), wxcolour
.Green(), wxcolour
.Blue());
64 void Set(uint8_t red
, uint8_t green
, uint8_t blue
) { m_red
= red
; m_green
= green
; m_blue
= blue
; }
66 inline uint8_t Red() const { return m_red
; }
67 inline uint8_t Green() const { return m_green
; }
68 inline uint8_t Blue() const { return m_blue
; }
70 const CMuleColour
& Blend(uint8_t percentage
, ColourComponent flags
= (ColourComponent
)(COLOUR_R
| COLOUR_G
| COLOUR_B
) )
72 unsigned int red
= (unsigned int)(Red() * ((flags
& COLOUR_R
) ? ((float)percentage
/(float)100) : (float)1));
73 unsigned int green
= (unsigned int)(Green() * ((flags
& COLOUR_G
) ? ((float)percentage
/(float)100) : (float)1));
74 unsigned int blue
= (unsigned int)(Blue() * ((flags
& COLOUR_B
) ? ((float)percentage
/(float)100) : (float)1));
75 Set((red
< 255) ? red
: 255, (green
< 255) ? green
: 255, (blue
< 255) ? blue
: 255);
79 const CMuleColour
& BlendWith(const CMuleColour
& colour
, double covered
)
81 unsigned int red
= (unsigned int)(Red() + (colour
.Red() * covered
) + 0.5);
82 unsigned int green
= (unsigned int)(Green() + (colour
.Green() * covered
) + 0.5);
83 unsigned int blue
= (unsigned int)(Blue() + (colour
.Blue() * covered
) + 0.5);
84 Set((red
< 255) ? red
: 255, (green
< 255) ? green
: 255, (blue
< 255) ? blue
: 255);
88 unsigned long GetULong() const { return (Blue() << 16) | (Green() << 8) | Red(); }
90 bool IsBlack() const { return !Red() && !Blue() && !Green(); }
92 bool IsSameAs(const CMuleColour
& colour
) const { return (Red() == colour
.Red()) && (Green() == colour
.Green()) && (Blue() == colour
.Blue()); }
94 operator wxColour() const {
95 return wxColor(m_red
, m_green
, m_blue
);
98 const wxPen
& GetPen(int width
= 1, int style
= wxSOLID
) const;
99 const wxBrush
& GetBrush(int style
= wxSOLID
) const;
106 mutable wxPen
* m_cachedpen
;
107 mutable wxBrush
* m_cachedbrush
;