1 // 2 // This file is part of the aMule Project. 3 // 4 // Copyright (c) 2003-2011 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. 14 // 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 23 // 24 25 #ifndef MULECOLOR_H 26 #define MULECOLOR_H 27 28 #include <wx/colour.h> 29 #include <wx/settings.h> 30 #include "Types.h" 31 32 class wxPen; 33 class wxBrush; 34 35 class CMuleColour 36 { 37 public: 38 39 enum ColourComponent { COLOUR_R = 1, COLOUR_G = 2, COLOUR_B = 4 }; 40 CMuleColour()41 CMuleColour() { Init(); Set(0,0,0); } CMuleColour(const wxColour & colour)42 CMuleColour(const wxColour& colour) { Init(); Set(colour.Red(), colour.Green(), colour.Blue()); } CMuleColour(byte r,byte g,byte b)43 CMuleColour(byte r, byte g, byte b) { Init(); Set(r,g,b); } CMuleColour(unsigned long rgb)44 CMuleColour(unsigned long rgb) 45 { 46 Init(); 47 Set((rgb & 0xFF), (rgb >> 8) & 0xFF, (rgb >> 16) & 0xFF); 48 } 49 CMuleColour(wxSystemColour colour)50 CMuleColour(wxSystemColour colour) 51 { 52 Init(); 53 const wxColour& wxcolour = wxSystemSettings::GetColour(colour); 54 Set(wxcolour.Red(), wxcolour.Green(), wxcolour.Blue()); 55 } 56 Init()57 void Init() { 58 m_cachedpen = NULL; 59 m_cachedbrush = NULL; 60 } 61 ~CMuleColour()62 ~CMuleColour() { } 63 Set(byte red,byte green,byte blue)64 void Set(byte red, byte green, byte blue) { m_red = red; m_green = green; m_blue = blue; } 65 Red()66 inline byte Red() const { return m_red; } Green()67 inline byte Green() const { return m_green; } Blue()68 inline byte Blue() const { return m_blue; } 69 70 const CMuleColour& Blend(byte percentage, ColourComponent flags = (ColourComponent)(COLOUR_R | COLOUR_G | COLOUR_B) ) 71 { 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; 77 } 78 BlendWith(const CMuleColour & colour,double covered)79 const CMuleColour& BlendWith(const CMuleColour& colour, double covered) 80 { 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; 86 } 87 GetULong()88 unsigned long GetULong() const { return (Blue() << 16) | (Green() << 8) | Red(); } 89 IsBlack()90 bool IsBlack() const { return !Red() && !Blue() && !Green(); } 91 IsSameAs(const CMuleColour & colour)92 bool IsSameAs(const CMuleColour& colour) const { return (Red() == colour.Red()) && (Green() == colour.Green()) && (Blue() == colour.Blue()); } 93 wxColour()94 operator wxColour() const { 95 return wxColor(m_red, m_green, m_blue); 96 } 97 98 const wxPen& GetPen(int width = 1, int style = wxSOLID) const; 99 const wxBrush& GetBrush(int style = wxSOLID) const; 100 101 private: 102 byte m_red; 103 byte m_green; 104 byte m_blue; 105 106 mutable wxPen* m_cachedpen; 107 mutable wxBrush* m_cachedbrush; 108 }; 109 110 #endif 111