Upstream tarball 9407
[amule.git] / src / MuleColour.h
blob26bdf6d21ccacd16ffe07653d1cc11a1483689ab
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 //
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
8 // respective authors.
9 //
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.
19 //
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
25 #ifndef MULECOLOR_H
26 #define MULECOLOR_H
28 #include <wx/colour.h>
29 #include <wx/settings.h>
30 #include "Types.h"
32 class wxPen;
33 class wxBrush;
35 class CMuleColour
37 public:
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(byte r, byte g, byte b) { Init(); Set(r,g,b); }
44 CMuleColour(unsigned long rgb)
46 Init();
47 Set((rgb & 0xFF), (rgb >> 8) & 0xFF, (rgb >> 16) & 0xFF);
50 CMuleColour(wxSystemColour colour)
52 Init();
53 const wxColour& wxcolour = wxSystemSettings::GetColour(colour);
54 Set(wxcolour.Red(), wxcolour.Green(), wxcolour.Blue());
57 void Init() {
58 m_cachedpen = NULL;
59 m_cachedbrush = NULL;
62 ~CMuleColour() { }
64 void Set(byte red, byte green, byte blue) { m_red = red; m_green = green; m_blue = blue; }
66 inline byte Red() const { return m_red; }
67 inline byte Green() const { return m_green; }
68 inline byte Blue() const { return m_blue; }
70 const CMuleColour& Blend(byte 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);
76 return *this;
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);
85 return *this;
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;
101 private:
102 byte m_red;
103 byte m_green;
104 byte m_blue;
106 mutable wxPen* m_cachedpen;
107 mutable wxBrush* m_cachedbrush;
110 #endif