Upstream tarball 20080708
[amule.git] / src / MuleColour.h
blob182e65ec51fa29463c2475610601f45ffe5d3ea3
1 #ifndef MULECOLOR_H
2 #define MULECOLOR_H
4 #include <wx/colour.h>
5 #include <wx/settings.h>
7 class CMuleColour : public wxColour
9 public:
11 enum ColourComponent { COLOUR_R = 1, COLOUR_G = 2, COLOUR_B = 4 };
13 CMuleColour() { }
14 CMuleColour(const wxColour& colour) : wxColour(colour) { }
15 CMuleColour(byte r, byte g, byte b) : wxColour(r,g,b) { }
16 CMuleColour(unsigned long rgb) : wxColour() { wxColour::Set(rgb); }
17 CMuleColour(wxSystemColour colour) : wxColour(wxSystemSettings::GetColour(colour)) { }
19 ~CMuleColour() { }
21 const CMuleColour& Blend(byte percentage, ColourComponent flags = (ColourComponent)(COLOUR_R | COLOUR_G | COLOUR_B) )
23 unsigned int red = (unsigned int)(Red() * ((flags & COLOUR_R) ? ((float)percentage/(float)100) : (float)1));
24 unsigned int green = (unsigned int)(Green() * ((flags & COLOUR_G) ? ((float)percentage/(float)100) : (float)1));
25 unsigned int blue = (unsigned int)(Blue() * ((flags & COLOUR_B) ? ((float)percentage/(float)100) : (float)1));
26 Set((red < 255) ? red : 255, (green < 255) ? green : 255, (blue < 255) ? blue : 255, Alpha());
27 return *this;
30 const CMuleColour& BlendWith(const CMuleColour& colour, double covered)
32 unsigned int red = (unsigned int)(Red() + (colour.Red() * covered) + 0.5);
33 unsigned int green = (unsigned int)(Green() + (colour.Green() * covered) + 0.5);
34 unsigned int blue = (unsigned int)(Blue() + (colour.Blue() * covered) + 0.5);
35 Set((red < 255) ? red : 255, (green < 255) ? green : 255, (blue < 255) ? blue : 255, Alpha());
36 return *this;
39 unsigned long GetULong() const { return (Blue() << 16) | (Green() << 8) | Red(); }
41 bool IsBlack() const { return !Red() && !Blue() && !Green(); }
43 bool IsSameAs(const CMuleColour& colour) const { return GetULong() == colour.GetULong(); }
45 private:
49 #endif