Skip to content

Commit

Permalink
Merge pull request #4939 from sjnewbury/gamelist-text
Browse files Browse the repository at this point in the history
Always use visible text in GameList
  • Loading branch information
Helios747 committed Mar 8, 2017
2 parents 5acf2c8 + 28f4793 commit 883bec8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions Source/Core/DolphinWX/GameListCtrl.cpp
Expand Up @@ -624,8 +624,8 @@ void CGameListCtrl::InsertItemInReportView(long index)
UpdateItemAtColumn(item_index, i);
}

// Background color
SetBackgroundColor();
// List colors
SetColors();
}

static wxColour blend50(const wxColour& c1, const wxColour& c2)
Expand All @@ -638,14 +638,23 @@ static wxColour blend50(const wxColour& c1, const wxColour& c2)
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++)
{
wxColour color = (i & 1) ? blend50(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT),
wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)) :
wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
CGameListCtrl::SetItemBackgroundColour(i, color);
SetItemTextColour(i, ContrastText(color));
}
}

Expand Down Expand Up @@ -796,7 +805,7 @@ void CGameListCtrl::OnColumnClick(wxListEvent& event)
SortItems(wxListCompare, last_sort);
}

SetBackgroundColor();
SetColors();

event.Skip();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinWX/GameListCtrl.h
Expand Up @@ -73,7 +73,7 @@ class CGameListCtrl : public wxListCtrl
void InitBitmaps();
void UpdateItemAtColumn(long _Index, int column);
void InsertItemInReportView(long _Index);
void SetBackgroundColor();
void SetColors();
void ScanForISOs();

// events
Expand Down

0 comments on commit 883bec8

Please sign in to comment.