mirror of
https://github.com/cemu-project/Cemu.git
synced 2024-12-26 09:41:54 +01:00
Refactor wxGameList color code and match previous style on light theme (#261)
Refactored to pre-calculate the game list row colors at the beginning of the function. If the background color is almost white as it is on Windows, we'll use the previous bluish secondary color instead of grey-scale lightness adjustment.
This commit is contained in:
parent
6ef36152c2
commit
910cdf4d5c
@ -269,40 +269,34 @@ long wxGameList::GetStyleFlags(Style style) const
|
|||||||
|
|
||||||
void wxGameList::UpdateItemColors(sint32 startIndex)
|
void wxGameList::UpdateItemColors(sint32 startIndex)
|
||||||
{
|
{
|
||||||
|
|
||||||
wxWindowUpdateLocker lock(this);
|
wxWindowUpdateLocker lock(this);
|
||||||
|
// get the background color so we can determine the theme in use
|
||||||
|
wxColour bgColour = GetBackgroundColour();
|
||||||
|
uint32 bgLightness = (bgColour.GetRed() + bgColour.GetGreen() + bgColour.GetBlue()) / 3;
|
||||||
|
bool isDarkTheme = bgLightness < 128;
|
||||||
|
wxColour bgColourPrimary = bgColour; // color for odd rows
|
||||||
|
wxColour bgColourSecondary = bgColour.ChangeLightness(isDarkTheme ? 110 : 90); // color for even rows
|
||||||
|
|
||||||
// Get the background color so we can determine the theme in use
|
// for very light themes we'll use a blue tint to match the older Windows Cemu look
|
||||||
const wxColour bgColour = GetBackgroundColour();
|
if (bgLightness > 250)
|
||||||
|
bgColourSecondary = wxColour(bgColour.Red() - 13, bgColour.Green() - 6, bgColour.Blue() - 2);
|
||||||
|
|
||||||
for (int i = startIndex; i < GetItemCount(); ++i)
|
for (int i = startIndex; i < GetItemCount(); ++i)
|
||||||
{
|
{
|
||||||
const auto titleId = (uint64)GetItemData(i);
|
const auto titleId = (uint64)GetItemData(i);
|
||||||
if (GetConfig().IsGameListFavorite(titleId))//entry->favorite)
|
if (GetConfig().IsGameListFavorite(titleId))
|
||||||
{
|
{
|
||||||
SetItemBackgroundColour(i, kFavoriteColor);
|
SetItemBackgroundColour(i, kFavoriteColor);
|
||||||
SetItemTextColour(i, 0x000000UL);
|
SetItemTextColour(i, 0x000000UL);
|
||||||
}
|
}
|
||||||
else if ((i&1) != 0)
|
else if ((i&1) != 0)
|
||||||
{
|
{
|
||||||
// Depending on the background RGB value:
|
SetItemBackgroundColour(i, bgColourPrimary);
|
||||||
// Light theme row color will be 10% darker (90)
|
|
||||||
// Dark theme row color will be 10% brighter (110)
|
|
||||||
int alpha = bgColour.GetRGB() > 0x808080 ? 90 : 110;
|
|
||||||
SetItemBackgroundColour(i, bgColour.ChangeLightness(alpha));
|
|
||||||
|
|
||||||
// Text can be changed to other values for alternating rows if needed
|
|
||||||
SetItemTextColour(i, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
|
SetItemTextColour(i, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Depending on the background RGB value:
|
SetItemBackgroundColour(i, bgColourSecondary);
|
||||||
// Light theme row color will be 0% darker (100)
|
|
||||||
// Dark theme row color will be 0% brighter (100)
|
|
||||||
int alpha = bgColour.GetRGB() > 0x808080 ? 100 : 100;
|
|
||||||
SetItemBackgroundColour(i, bgColour.ChangeLightness(alpha));
|
|
||||||
|
|
||||||
// Text color can be modified to other values for alternating rows if needed
|
|
||||||
SetItemTextColour(i, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
|
SetItemTextColour(i, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -310,7 +304,7 @@ void wxGameList::UpdateItemColors(sint32 startIndex)
|
|||||||
|
|
||||||
static inline int strongorder_to_int(const std::strong_ordering &wo)
|
static inline int strongorder_to_int(const std::strong_ordering &wo)
|
||||||
{
|
{
|
||||||
/* No easy conversion seems to exists in C++20 */
|
// no easy conversion seems to exists in C++20
|
||||||
if (wo < 0)
|
if (wo < 0)
|
||||||
return -1;
|
return -1;
|
||||||
else if (wo > 0)
|
else if (wo > 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user