Merge pull request #4939 from sjnewbury/gamelist-text

Always use visible text in GameList
This commit is contained in:
Anthony 2017-03-08 22:38:23 +00:00 committed by GitHub
commit 883bec873f
2 changed files with 14 additions and 5 deletions

View File

@ -624,8 +624,8 @@ void CGameListCtrl::InsertItemInReportView(long index)
UpdateItemAtColumn(item_index, i); UpdateItemAtColumn(item_index, i);
} }
// Background color // List colors
SetBackgroundColor(); SetColors();
} }
static wxColour blend50(const wxColour& c1, const wxColour& c2) static wxColour blend50(const wxColour& c1, const wxColour& c2)
@ -638,7 +638,15 @@ static wxColour blend50(const wxColour& c1, const wxColour& c2)
return a << 24 | b << 16 | g << 8 | r; return a << 24 | b << 16 | g << 8 | r;
} }
void CGameListCtrl::SetBackgroundColor() static wxColour ContrastText(const wxColour& bgc)
{
// Luminance threshold to determine whether to use black text on light background
static constexpr int LUM_THRESHOLD = 186;
int lum = 0.299 * bgc.Red() + 0.587 * bgc.Green() + 0.114 * bgc.Blue();
return (lum > LUM_THRESHOLD) ? *wxBLACK : *wxWHITE;
}
void CGameListCtrl::SetColors()
{ {
for (long i = 0; i < GetItemCount(); i++) for (long i = 0; i < GetItemCount(); i++)
{ {
@ -646,6 +654,7 @@ void CGameListCtrl::SetBackgroundColor()
wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)) : wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)) :
wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
CGameListCtrl::SetItemBackgroundColour(i, color); CGameListCtrl::SetItemBackgroundColour(i, color);
SetItemTextColour(i, ContrastText(color));
} }
} }
@ -796,7 +805,7 @@ void CGameListCtrl::OnColumnClick(wxListEvent& event)
SortItems(wxListCompare, last_sort); SortItems(wxListCompare, last_sort);
} }
SetBackgroundColor(); SetColors();
event.Skip(); event.Skip();
} }

View File

@ -73,7 +73,7 @@ private:
void InitBitmaps(); void InitBitmaps();
void UpdateItemAtColumn(long _Index, int column); void UpdateItemAtColumn(long _Index, int column);
void InsertItemInReportView(long _Index); void InsertItemInReportView(long _Index);
void SetBackgroundColor(); void SetColors();
void ScanForISOs(); void ScanForISOs();
// events // events