2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-2008 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
25 #include "MuleColour.h"
32 #define USE_MULE_PEN_CACHE 1
33 #define USE_MULE_BRUSH_CACHE 1
35 std::map
<uint32_t, wxPen
*> wxPenCache
;
36 std::map
<uint32_t, wxBrush
*> wxBrushCache
;
38 const wxPen
& CMuleColour::GetPen(int width
, int style
) const
40 #if USE_MULE_PEN_CACHE
43 if (m_cachedpen
&& (m_cachedpen
->GetWidth() == width
) && (m_cachedpen
->GetStyle() == style
)) {
46 const uint32_t hash
= ((width
& 0xF) << 28) | ((style
& 0xF) << 24) | (GetULong() & 0xFFFFFF);
47 std::map
<uint32_t, wxPen
*>::iterator it
= wxPenCache
.find(hash
);
48 if (it
!= wxPenCache
.end()) {
52 result
= wxThePenList
->FindOrCreatePen(wxColour(m_red
, m_green
, m_blue
), width
, style
);
54 wxPenCache
.insert(std::pair
<uint32_t, wxPen
*>(hash
, result
));
60 return *wxThePenList
->FindOrCreatePen(wxColour(m_red
, m_green
, m_blue
), width
, style
);
64 const wxBrush
& CMuleColour::GetBrush(int style
) const
66 #if USE_MULE_BRUSH_CACHE
67 wxBrush
* result
= NULL
;
69 if (m_cachedbrush
&& (m_cachedbrush
->GetStyle() == style
)) {
70 result
= m_cachedbrush
;
72 const uint32_t hash
= ((style
& 0xF) << 24) | (GetULong() & 0xFFFFFF);
73 std::map
<uint32_t, wxBrush
*>::iterator it
= wxBrushCache
.find(hash
);
74 if (it
!= wxBrushCache
.end()) {
76 m_cachedbrush
= result
;
78 result
= wxTheBrushList
->FindOrCreateBrush(wxColour(m_red
, m_green
, m_blue
), style
);
79 m_cachedbrush
= result
;
80 wxBrushCache
.insert(std::pair
<uint32_t, wxBrush
*>(hash
, result
));
86 return *wxTheBrushList
->FindOrCreateBrush(wxColour(m_red
, m_green
, m_blue
), style
);