Fix language getting reset to system default on saving preferences
[amule.git] / src / MuleColour.cpp
blob0ca3b3c48fbf9bc1b1eb4c90aec5e3d954f766f9
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 #include "MuleColour.h"
27 #include <wx/pen.h>
28 #include <wx/brush.h>
30 #include <map>
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
41 wxPen* result = NULL;
43 if (m_cachedpen && (m_cachedpen->GetWidth() == width) && (m_cachedpen->GetStyle() == style)) {
44 result = m_cachedpen;
45 } else {
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()) {
49 result = it->second;
50 m_cachedpen = result;
51 } else {
52 result = wxThePenList->FindOrCreatePen(wxColour(m_red, m_green, m_blue), width, style);
53 m_cachedpen = result;
54 wxPenCache.insert(std::pair<uint32_t, wxPen*>(hash, result));
58 return *result;
59 #else
60 return *wxThePenList->FindOrCreatePen(wxColour(m_red, m_green, m_blue), width, style);
61 #endif
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;
71 } else {
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()) {
75 result = it->second;
76 m_cachedbrush = result;
77 } else {
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));
84 return *result;
85 #else
86 return *wxTheBrushList->FindOrCreateBrush(wxColour(m_red, m_green, m_blue), style);
87 #endif