diff --git a/Source/Project64/UserInterface/RomBrowser.h b/Source/Project64/UserInterface/RomBrowser.h index 1b9190d0b..b804b6505 100644 --- a/Source/Project64/UserInterface/RomBrowser.h +++ b/Source/Project64/UserInterface/RomBrowser.h @@ -122,7 +122,8 @@ private: NoOfSortKeys = 3 }; - void AllocateBrushs(void); + typedef std::map HBRUSH_MAP; + void RomListReset(void); void RomListLoaded(void); void RomAddedToList(int32_t ListPos); @@ -156,5 +157,6 @@ private: bool m_ShowingRomBrowser; bool m_AllowSelectionLastRom; static std::wstring m_UnknownGoodName; + HBRUSH_MAP m_Brushes; std::string m_LastRom; }; diff --git a/Source/Project64/UserInterface/RomBrowserClass.cpp b/Source/Project64/UserInterface/RomBrowserClass.cpp index 870a2e309..434be7d92 100644 --- a/Source/Project64/UserInterface/RomBrowserClass.cpp +++ b/Source/Project64/UserInterface/RomBrowserClass.cpp @@ -253,8 +253,6 @@ int32_t CRomBrowser::CalcSortPosition(uint32_t lParam) void CRomBrowser::RomAddedToList(int32_t ListPos) { - m_RomInfo[ListPos].SelColorBrush = NULL; - LVITEMW lvItem; memset(&lvItem, 0, sizeof(lvItem)); lvItem.mask = LVIF_TEXT | LVIF_PARAM; @@ -277,21 +275,6 @@ void CRomBrowser::RomAddedToList(int32_t ListPos) } } -void CRomBrowser::AllocateBrushs(void) -{ - for (size_t count = 0; count < m_RomInfo.size(); count++) - { - if (m_RomInfo[count].SelColor == -1) - { - m_RomInfo[count].SelColorBrush = (uint32_t)((HBRUSH)(COLOR_HIGHLIGHT + 1)); - } - else - { - m_RomInfo[count].SelColorBrush = (uint32_t)CreateSolidBrush(m_RomInfo[count].SelColor); - } - } -} - void CRomBrowser::RomListReset(void) { WriteTrace(TraceUserInterface, TraceDebug, "1"); @@ -313,23 +296,15 @@ void CRomBrowser::CreateRomListControl(void) void CRomBrowser::DeallocateBrushs(void) { - for (size_t count = 0; count < m_RomInfo.size(); count++) + for (HBRUSH_MAP::iterator itr = m_Brushes.begin(); itr != m_Brushes.end(); itr++) { - if (m_RomInfo[count].SelColor == -1) - { - continue; - } - if (m_RomInfo[count].SelColorBrush) - { - DeleteObject((HBRUSH)m_RomInfo[count].SelColorBrush); - m_RomInfo[count].SelColorBrush = NULL; - } + DeleteObject(itr->second); } + m_Brushes.clear(); } void CRomBrowser::RomListLoaded(void) { - AllocateBrushs(); RomList_SortList(); } @@ -498,7 +473,7 @@ bool CRomBrowser::RomListDrawItem(int32_t idCtrl, uint32_t lParam) RECT rcItem, rcDraw; wchar_t String[300]; LVITEMW lvItem; - HBRUSH hBrush; + HBRUSH hBrush = (HBRUSH)(COLOR_WINDOW + 1); LV_COLUMN lvc; int32_t nColumn; @@ -519,12 +494,20 @@ bool CRomBrowser::RomListDrawItem(int32_t idCtrl, uint32_t lParam) } if (bSelected) { - hBrush = (HBRUSH)pRomInfo->SelColorBrush; + HBRUSH_MAP::iterator itr = m_Brushes.find(pRomInfo->SelColor); + if (itr != m_Brushes.end()) + { + hBrush = itr->second; + } + else + { + std::pair res = m_Brushes.insert(HBRUSH_MAP::value_type(pRomInfo->SelColor, CreateSolidBrush(pRomInfo->SelColor))); + hBrush = res.first->second; + } SetTextColor(ditem->hDC, pRomInfo->SelTextColor); } else { - hBrush = (HBRUSH)(COLOR_WINDOW + 1); SetTextColor(ditem->hDC, pRomInfo->TextColor); } FillRect(ditem->hDC, &ditem->rcItem, hBrush); diff --git a/Source/Project64/UserInterface/RomList.cpp b/Source/Project64/UserInterface/RomList.cpp index 24ee993d0..8a1437665 100644 --- a/Source/Project64/UserInterface/RomList.cpp +++ b/Source/Project64/UserInterface/RomList.cpp @@ -148,10 +148,6 @@ void CRomList::FillRomList(strlist & FileList, const CPath & BaseDirectory, cons do { - uint8_t ext_ID; - int8_t new_list_entry = 0; - const uint8_t exts = sizeof(ROM_extensions) / sizeof(ROM_extensions[0]); - WriteTrace(TraceRomList, TraceVerbose, "Found: \"%s\" m_StopRefresh = %s", (const char *)SearchPath, m_StopRefresh ? "true" : "false"); if (m_StopRefresh) { @@ -314,14 +310,6 @@ void CRomList::FillRomList(strlist & FileList, const CPath & BaseDirectory, cons WriteTrace(TraceUserInterface, TraceDebug, "16"); FillRomExtensionInfo(&RomInfo); - if (RomInfo.SelColor == -1) - { - RomInfo.SelColorBrush = (uint32_t)((HBRUSH)(COLOR_HIGHLIGHT + 1)); - } - else - { - RomInfo.SelColorBrush = (uint32_t)CreateSolidBrush(RomInfo.SelColor); - } WriteTrace(TraceUserInterface, TraceDebug, "17"); int32_t ListPos = m_RomInfo.size(); m_RomInfo.push_back(RomInfo); @@ -469,18 +457,7 @@ bool CRomList::FillRomInfo(ROM_INFO * pRomInfo) pRomInfo->CRC1 = *(uint32_t *)(RomData + 0x10); pRomInfo->CRC2 = *(uint32_t *)(RomData + 0x14); pRomInfo->CicChip = GetCicChipID(RomData); - FillRomExtensionInfo(pRomInfo); - - if (pRomInfo->SelColor == -1) - { - pRomInfo->SelColorBrush = (uint32_t)((HBRUSH)(COLOR_HIGHLIGHT + 1)); - } - else - { - pRomInfo->SelColorBrush = (uint32_t)CreateSolidBrush(pRomInfo->SelColor); - } - return true; } return false; diff --git a/Source/Project64/UserInterface/RomList.h b/Source/Project64/UserInterface/RomList.h index d0108340c..904ed3020 100644 --- a/Source/Project64/UserInterface/RomList.h +++ b/Source/Project64/UserInterface/RomList.h @@ -39,7 +39,6 @@ public: uint32_t TextColor; int32_t SelColor; uint32_t SelTextColor; - uint32_t SelColorBrush; int32_t RomSize; uint8_t Manufacturer; uint8_t Country;