Merge branch 'aui-dark-mode'

Fixes for AUI in dark mode, especially, but not only, under macOS.

See https://github.com/wxWidgets/wxWidgets/pull/1955

Closes #18812.
This commit is contained in:
Vadim Zeitlin 2020-07-14 20:26:52 +02:00
commit c073995352
3 changed files with 88 additions and 86 deletions

View File

@ -69,11 +69,7 @@ wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h,
static wxColor GetBaseColor() static wxColor GetBaseColor()
{ {
#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
#else
wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
#endif
// the baseColour is too pale to use as our base colour, // the baseColour is too pale to use as our base colour,
// so darken it a bit -- // so darken it a bit --
@ -120,13 +116,6 @@ private:
}; };
static const unsigned char
DISABLED_TEXT_GREY_HUE = wxColour::AlphaBlend(0, 255, 0.4);
const wxColour DISABLED_TEXT_COLOR(DISABLED_TEXT_GREY_HUE,
DISABLED_TEXT_GREY_HUE,
DISABLED_TEXT_GREY_HUE);
wxAuiGenericToolBarArt::wxAuiGenericToolBarArt() wxAuiGenericToolBarArt::wxAuiGenericToolBarArt()
{ {
UpdateColoursFromSystem(); UpdateColoursFromSystem();
@ -139,18 +128,6 @@ wxAuiGenericToolBarArt::wxAuiGenericToolBarArt()
m_overflowSize = wxWindow::FromDIP(16, NULL); m_overflowSize = wxWindow::FromDIP(16, NULL);
m_dropdownSize = wxWindow::FromDIP(10, NULL); m_dropdownSize = wxWindow::FromDIP(10, NULL);
// TODO: Provide x1.5 and x2.0 versions or migrate to SVG.
static const unsigned char buttonDropdownBits[] = { 0xe0, 0xf1, 0xfb };
static const unsigned char overflowBits[] = { 0x80, 0xff, 0x80, 0xc1, 0xe3, 0xf7 };
m_buttonDropDownBmp = wxAuiBitmapFromBits(buttonDropdownBits, 5, 3,
wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT));
m_disabledButtonDropDownBmp = wxAuiBitmapFromBits(
buttonDropdownBits, 5, 3,
wxColor(128,128,128));
m_overflowBmp = wxAuiBitmapFromBits(overflowBits, 7, 6,
wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT));
m_disabledOverflowBmp = wxAuiBitmapFromBits(overflowBits, 7, 6, wxColor(128,128,128));
m_font = *wxNORMAL_FONT; m_font = *wxNORMAL_FONT;
} }
@ -175,6 +152,21 @@ void wxAuiGenericToolBarArt::UpdateColoursFromSystem()
m_gripperPen1 = wxPen(darker5Colour, pen_width); m_gripperPen1 = wxPen(darker5Colour, pen_width);
m_gripperPen2 = wxPen(darker3Colour, pen_width); m_gripperPen2 = wxPen(darker3Colour, pen_width);
m_gripperPen3 = wxPen(*wxStockGDI::GetColour(wxStockGDI::COLOUR_WHITE), pen_width); m_gripperPen3 = wxPen(*wxStockGDI::GetColour(wxStockGDI::COLOUR_WHITE), pen_width);
// Note: update the bitmaps here as they depend on the system colours too.
// TODO: Provide x1.5 and x2.0 versions or migrate to SVG.
static const unsigned char buttonDropdownBits[] = { 0xe0, 0xf1, 0xfb };
static const unsigned char overflowBits[] = { 0x80, 0xff, 0x80, 0xc1, 0xe3, 0xf7 };
m_buttonDropDownBmp = wxAuiBitmapFromBits(buttonDropdownBits, 5, 3,
wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT));
m_disabledButtonDropDownBmp = wxAuiBitmapFromBits(
buttonDropdownBits, 5, 3,
wxColor(128,128,128));
m_overflowBmp = wxAuiBitmapFromBits(overflowBits, 7, 6,
wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT));
m_disabledOverflowBmp = wxAuiBitmapFromBits(overflowBits, 7, 6, wxColor(128,128,128));
} }
void wxAuiGenericToolBarArt::SetFlags(unsigned int flags) void wxAuiGenericToolBarArt::SetFlags(unsigned int flags)
@ -249,11 +241,7 @@ void wxAuiGenericToolBarArt::DrawLabel(
const wxRect& rect) const wxRect& rect)
{ {
dc.SetFont(m_font); dc.SetFont(m_font);
#ifdef __WXMAC__
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT)); dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT));
#else
dc.SetTextForeground(*wxBLACK);
#endif
// we only care about the text height here since the text // we only care about the text height here since the text
// will get cropped based on the width of the item // will get cropped based on the width of the item
@ -366,11 +354,7 @@ void wxAuiGenericToolBarArt::DrawButton(
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT)); dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT));
if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED) if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED)
{ {
#ifdef __WXMAC__ dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_INACTIVECAPTIONTEXT));
#else
dc.SetTextForeground(DISABLED_TEXT_COLOR);
#endif
} }
if ( (m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty() ) if ( (m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty() )
@ -500,11 +484,7 @@ void wxAuiGenericToolBarArt::DrawDropDownButton(
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT)); dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT));
if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED) if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED)
{ {
#ifdef __WXMAC__ dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_INACTIVECAPTIONTEXT));
#else
dc.SetTextForeground(DISABLED_TEXT_COLOR);
#endif
} }
if ( (m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty() ) if ( (m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty() )
@ -544,11 +524,7 @@ void wxAuiGenericToolBarArt::DrawControlLabel(
return; return;
// set the label's text color // set the label's text color
#ifdef __WXMAC__
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT)); dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT));
#else
dc.SetTextForeground(*wxBLACK);
#endif
textX = rect.x + (rect.width/2) - (textWidth/2) + 1; textX = rect.x + (rect.width/2) - (textWidth/2) + 1;
textY = rect.y + rect.height - textHeight - 1; textY = rect.y + rect.height - textHeight - 1;

View File

@ -95,9 +95,38 @@ wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h,
const wxColour& color) const wxColour& color)
{ {
wxImage img = wxBitmap((const char*)bits, w, h).ConvertToImage(); wxImage img = wxBitmap((const char*)bits, w, h).ConvertToImage();
img.Replace(0,0,0,123,123,123); if (color.Alpha() == wxALPHA_OPAQUE)
img.Replace(255,255,255,color.Red(),color.Green(),color.Blue()); {
img.SetMaskColour(123,123,123); img.Replace(0,0,0,123,123,123);
img.Replace(255,255,255,color.Red(),color.Green(),color.Blue());
img.SetMaskColour(123,123,123);
}
else
{
img.InitAlpha();
const int newr = color.Red();
const int newg = color.Green();
const int newb = color.Blue();
const int newa = color.Alpha();
for (int x = 0; x < w; x++)
{
for (int y = 0; y < h; y++)
{
int r = img.GetRed(x, y);
int g = img.GetGreen(x, y);
int b = img.GetBlue(x, y);
if (r == 0 && g == 0 && b == 0)
{
img.SetAlpha(x, y, wxALPHA_TRANSPARENT);
}
else
{
img.SetRGB(x, y, newr, newg, newb);
img.SetAlpha(x, y, newa);
}
}
}
}
return wxBitmap(img); return wxBitmap(img);
} }
@ -268,40 +297,29 @@ wxAuiDefaultDockArt::InitBitmaps ()
0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
#ifdef __WXMAC__ #ifdef __WXMAC__
m_inactiveCloseBitmap = wxAuiBitmapFromBits(close_bits, 16, 16, *wxWHITE); const wxColour inactive = wxSystemSettings::GetColour(wxSYS_COLOUR_INACTIVECAPTION);
m_activeCloseBitmap = wxAuiBitmapFromBits(close_bits, 16, 16, *wxWHITE ); const wxColour active = wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT);
#else #else
m_inactiveCloseBitmap = wxAuiBitmapFromBits(close_bits, 16, 16, m_inactiveCaptionTextColour); const wxColor inactive = m_inactiveCaptionTextColour;
m_activeCloseBitmap = wxAuiBitmapFromBits(close_bits, 16, 16, m_activeCaptionTextColour); const wxColor active = m_activeCaptionTextColour;
#endif #endif
#ifdef __WXMAC__ m_inactiveCloseBitmap = wxAuiBitmapFromBits(close_bits, 16, 16, inactive);
m_inactiveMaximizeBitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, *wxWHITE); m_activeCloseBitmap = wxAuiBitmapFromBits(close_bits, 16, 16, active);
m_activeMaximizeBitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, *wxWHITE );
#else
m_inactiveMaximizeBitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, m_inactiveCaptionTextColour);
m_activeMaximizeBitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, m_activeCaptionTextColour);
#endif
#ifdef __WXMAC__ m_inactiveMaximizeBitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, inactive);
m_inactiveRestoreBitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, *wxWHITE); m_activeMaximizeBitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, active);
m_activeRestoreBitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, *wxWHITE );
#else
m_inactiveRestoreBitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, m_inactiveCaptionTextColour);
m_activeRestoreBitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, m_activeCaptionTextColour);
#endif
m_inactivePinBitmap = wxAuiBitmapFromBits(pin_bits, 16, 16, m_inactiveCaptionTextColour); m_inactiveRestoreBitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, inactive);
m_activePinBitmap = wxAuiBitmapFromBits(pin_bits, 16, 16, m_activeCaptionTextColour); m_activeRestoreBitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, active);
m_inactivePinBitmap = wxAuiBitmapFromBits(pin_bits, 16, 16, inactive);
m_activePinBitmap = wxAuiBitmapFromBits(pin_bits, 16, 16, active);
} }
void wxAuiDefaultDockArt::UpdateColoursFromSystem() void wxAuiDefaultDockArt::UpdateColoursFromSystem()
{ {
#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
#else
wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
#endif
// the baseColour is too pale to use as our base colour, // the baseColour is too pale to use as our base colour,
// so darken it a bit -- // so darken it a bit --

View File

@ -176,14 +176,6 @@ static const unsigned char list_bits[] = {
wxAuiGenericTabArt::wxAuiGenericTabArt() wxAuiGenericTabArt::wxAuiGenericTabArt()
: m_normalFont(*wxNORMAL_FONT) : m_normalFont(*wxNORMAL_FONT)
, m_selectedFont(m_normalFont) , m_selectedFont(m_normalFont)
, m_activeCloseBmp(wxAuiBitmapFromBits(close_bits, 16, 16, *wxBLACK))
, m_disabledCloseBmp(wxAuiBitmapFromBits(close_bits, 16, 16, wxColour(128,128,128)))
, m_activeLeftBmp(wxAuiBitmapFromBits(left_bits, 16, 16, *wxBLACK))
, m_disabledLeftBmp(wxAuiBitmapFromBits(left_bits, 16, 16, wxColour(128,128,128)))
, m_activeRightBmp(wxAuiBitmapFromBits(right_bits, 16, 16, *wxBLACK))
, m_disabledRightBmp(wxAuiBitmapFromBits(right_bits, 16, 16, wxColour(128,128,128)))
, m_activeWindowListBmp(wxAuiBitmapFromBits(list_bits, 16, 16, *wxBLACK))
, m_disabledWindowListBmp(wxAuiBitmapFromBits(list_bits, 16, 16, wxColour(128,128,128)))
{ {
m_selectedFont.SetWeight(wxFONTWEIGHT_BOLD); m_selectedFont.SetWeight(wxFONTWEIGHT_BOLD);
m_measuringFont = m_selectedFont; m_measuringFont = m_selectedFont;
@ -201,11 +193,7 @@ wxAuiGenericTabArt::~wxAuiGenericTabArt()
void wxAuiGenericTabArt::UpdateColoursFromSystem() void wxAuiGenericTabArt::UpdateColoursFromSystem()
{ {
#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
#else
wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
#endif
// the baseColour is too pale to use as our base colour, // the baseColour is too pale to use as our base colour,
// so darken it a bit -- // so darken it a bit --
@ -223,6 +211,17 @@ void wxAuiGenericTabArt::UpdateColoursFromSystem()
m_borderPen = wxPen(borderColour); m_borderPen = wxPen(borderColour);
m_baseColourPen = wxPen(m_baseColour); m_baseColourPen = wxPen(m_baseColour);
m_baseColourBrush = wxBrush(m_baseColour); m_baseColourBrush = wxBrush(m_baseColour);
const int disabledLightness = wxSystemSettings::GetAppearance().IsUsingDarkBackground() ? 130 : 70;
m_activeCloseBmp = wxAuiBitmapFromBits(close_bits, 16, 16, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
m_disabledCloseBmp = wxAuiBitmapFromBits(close_bits, 16, 16, wxSystemSettings::GetColour(wxSYS_COLOUR_INACTIVECAPTIONTEXT).ChangeLightness(disabledLightness));
m_activeLeftBmp = wxAuiBitmapFromBits(left_bits, 16, 16, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
m_disabledLeftBmp = wxAuiBitmapFromBits(left_bits, 16, 16, wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
m_activeRightBmp = wxAuiBitmapFromBits(right_bits, 16, 16, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
m_disabledRightBmp = wxAuiBitmapFromBits(right_bits, 16, 16, wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
m_activeWindowListBmp = wxAuiBitmapFromBits(list_bits, 16, 16, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
m_disabledWindowListBmp = wxAuiBitmapFromBits(list_bits, 16, 16, wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
} }
wxAuiTabArt* wxAuiGenericTabArt::Clone() wxAuiTabArt* wxAuiGenericTabArt::Clone()
@ -280,9 +279,19 @@ void wxAuiGenericTabArt::DrawBackground(wxDC& dc,
wxWindow* WXUNUSED(wnd), wxWindow* WXUNUSED(wnd),
const wxRect& rect) const wxRect& rect)
{ {
// draw background // draw background using arbitrary hard-coded, but at least adapted to dark
int topLightness = 90; // mode, gradient
int bottomLightness = 170; int topLightness, bottomLightness;
if (wxSystemSettings::GetAppearance().IsUsingDarkBackground())
{
topLightness = 110;
bottomLightness = 90;
}
else
{
topLightness = 90;
bottomLightness = 170;
}
wxColor top_color = m_baseColour.ChangeLightness(topLightness); wxColor top_color = m_baseColour.ChangeLightness(topLightness);
wxColor bottom_color = m_baseColour.ChangeLightness(bottomLightness); wxColor bottom_color = m_baseColour.ChangeLightness(bottomLightness);
@ -436,9 +445,8 @@ void wxAuiGenericTabArt::DrawTab(wxDC& dc,
int drawn_tab_yoff = border_points[1].y; int drawn_tab_yoff = border_points[1].y;
int drawn_tab_height = border_points[0].y - border_points[1].y; int drawn_tab_height = border_points[0].y - border_points[1].y;
bool isdark = (m_baseColour.Red() < 75) bool isdark = wxSystemSettings::GetAppearance().IsUsingDarkBackground();
&& (m_baseColour.Green() < 75)
&& (m_baseColour.Blue() < 75);
wxColor back_color = m_baseColour; wxColor back_color = m_baseColour;
if (page.active) if (page.active)
{ {