Dark Mode Patches

thanks to dkulp,
see https://github.com/wxWidgets/wxWidgets/pull/840
see #18146
This commit is contained in:
Stefan Csomor
2018-06-21 20:22:53 +02:00
parent c0be6a38c4
commit c6523f016e
3 changed files with 115 additions and 20 deletions

View File

@@ -72,7 +72,7 @@ static wxColor GetBaseColor()
{ {
#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
wxColor baseColour = wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground)); wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
#else #else
wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
#endif #endif
@@ -208,8 +208,22 @@ void wxAuiGenericToolBarArt::DrawBackground(
{ {
wxRect rect = _rect; wxRect rect = _rect;
rect.height++; rect.height++;
wxColour startColour = m_baseColour.ChangeLightness(150);
wxColour endColour = m_baseColour.ChangeLightness(90); int startLightness = 150;
int endLightness = 90;
if ((m_baseColour.Red() < 75)
&& (m_baseColour.Green() < 75)
&& (m_baseColour.Blue() < 75))
{
//dark mode, we cannot go very light
startLightness = 110;
endLightness = 90;
}
wxColour startColour = m_baseColour.ChangeLightness(startLightness);
wxColour endColour = m_baseColour.ChangeLightness(endLightness);
dc.GradientFillLinear(rect, startColour, endColour, wxSOUTH); dc.GradientFillLinear(rect, startColour, endColour, wxSOUTH);
} }
@@ -233,7 +247,11 @@ 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));
#else
dc.SetTextForeground(*wxBLACK); 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
@@ -343,9 +361,19 @@ void wxAuiGenericToolBarArt::DrawButton(
dc.DrawBitmap(bmp, bmpX, bmpY, true); dc.DrawBitmap(bmp, bmpX, bmpY, true);
// set the item's text color based on if it is disabled // set the item's text color based on if it is disabled
#ifdef __WXMAC__
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT));
#else
dc.SetTextForeground(*wxBLACK); dc.SetTextForeground(*wxBLACK);
#endif
if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED) if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED)
{
#ifdef __WXMAC__
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_INACTIVECAPTIONTEXT));
#else
dc.SetTextForeground(DISABLED_TEXT_COLOR); dc.SetTextForeground(DISABLED_TEXT_COLOR);
#endif
}
if ( (m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty() ) if ( (m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty() )
{ {
@@ -470,9 +498,19 @@ void wxAuiGenericToolBarArt::DrawDropDownButton(
dc.DrawBitmap(dropbmp, dropBmpX, dropBmpY, true); dc.DrawBitmap(dropbmp, dropBmpX, dropBmpY, true);
// set the item's text color based on if it is disabled // set the item's text color based on if it is disabled
#ifdef __WXMAC__
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT));
#else
dc.SetTextForeground(*wxBLACK); dc.SetTextForeground(*wxBLACK);
#endif
if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED) if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED)
{
#ifdef __WXMAC__
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_INACTIVECAPTIONTEXT));
#else
dc.SetTextForeground(DISABLED_TEXT_COLOR); dc.SetTextForeground(DISABLED_TEXT_COLOR);
#endif
}
if ( (m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty() ) if ( (m_flags & wxAUI_TB_TEXT) && !item.GetLabel().empty() )
{ {
@@ -511,7 +549,11 @@ 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));
#else
dc.SetTextForeground(*wxBLACK); 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

@@ -152,7 +152,7 @@ wxString wxAuiChopText(wxDC& dc, const wxString& text, int max_size)
wxAuiDefaultDockArt::wxAuiDefaultDockArt() wxAuiDefaultDockArt::wxAuiDefaultDockArt()
{ {
#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
wxColor baseColour = wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground)); wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
#else #else
wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
#endif #endif
@@ -178,7 +178,11 @@ wxAuiDefaultDockArt::wxAuiDefaultDockArt()
m_activeCaptionTextColour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); m_activeCaptionTextColour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
m_inactiveCaptionColour = darker1Colour; m_inactiveCaptionColour = darker1Colour;
m_inactiveCaptionGradientColour = baseColour.ChangeLightness(97); m_inactiveCaptionGradientColour = baseColour.ChangeLightness(97);
#ifdef __WXMAC__
m_inactiveCaptionTextColour = wxSystemSettings::GetColour(wxSYS_COLOUR_INACTIVECAPTIONTEXT);
#else
m_inactiveCaptionTextColour = *wxBLACK; m_inactiveCaptionTextColour = *wxBLACK;
#endif
m_sashBrush = wxBrush(baseColour); m_sashBrush = wxBrush(baseColour);
m_backgroundBrush = wxBrush(baseColour); m_backgroundBrush = wxBrush(baseColour);
@@ -378,16 +382,25 @@ void wxAuiDefaultDockArt::DrawSash(wxDC& dc, wxWindow *window, int orientation,
wxUnusedVar(window); wxUnusedVar(window);
wxUnusedVar(orientation); wxUnusedVar(orientation);
HIRect splitterRect = CGRectMake( rect.x , rect.y , rect.width , rect.height ); if ( wxPlatformInfo::Get().CheckOSVersion(10, 14) && wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW).Red() < 128 )
CGContextRef cgContext ; {
wxGCDCImpl *impl = (wxGCDCImpl*) dc.GetImpl(); dc.SetPen(*wxTRANSPARENT_PEN);
cgContext = (CGContextRef) impl->GetGraphicsContext()->GetNativeContext() ; dc.SetBrush(m_sashBrush);
dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
}
else
{
HIRect splitterRect = CGRectMake( rect.x , rect.y , rect.width , rect.height );
CGContextRef cgContext ;
wxGCDCImpl *impl = (wxGCDCImpl*) dc.GetImpl();
cgContext = (CGContextRef) impl->GetGraphicsContext()->GetNativeContext() ;
HIThemeSplitterDrawInfo drawInfo ; HIThemeSplitterDrawInfo drawInfo ;
drawInfo.version = 0 ; drawInfo.version = 0 ;
drawInfo.state = kThemeStateActive ; drawInfo.state = kThemeStateActive ;
drawInfo.adornment = kHIThemeSplitterAdornmentNone ; drawInfo.adornment = kHIThemeSplitterAdornmentNone ;
HIThemeDrawPaneSplitter( &splitterRect , &drawInfo , cgContext , kHIThemeOrientationNormal ) ; HIThemeDrawPaneSplitter( &splitterRect , &drawInfo , cgContext , kHIThemeOrientationNormal ) ;
}
#elif defined(__WXGTK__) #elif defined(__WXGTK__)
// clear out the rectangle first // clear out the rectangle first

View File

@@ -163,7 +163,7 @@ wxAuiGenericTabArt::wxAuiGenericTabArt()
m_tabCtrlHeight = 0; m_tabCtrlHeight = 0;
#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
wxColor baseColour = wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground)); wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
#else #else
wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
#endif #endif
@@ -262,9 +262,20 @@ void wxAuiGenericTabArt::DrawBackground(wxDC& dc,
const wxRect& rect) const wxRect& rect)
{ {
// draw background // draw background
int topLightness = 90;
int bottomLightness = 170;
if ((m_baseColour.Red() < 75)
&& (m_baseColour.Green() < 75)
&& (m_baseColour.Blue() < 75))
{
//dark mode, we cannot go very light
topLightness = 90;
bottomLightness = 110;
}
wxColor top_color = m_baseColour.ChangeLightness(90);
wxColor bottom_color = m_baseColour.ChangeLightness(170); wxColor top_color = m_baseColour.ChangeLightness(topLightness);
wxColor bottom_color = m_baseColour.ChangeLightness(bottomLightness);
wxRect r; wxRect r;
if (m_flags &wxAUI_NB_BOTTOM) if (m_flags &wxAUI_NB_BOTTOM)
@@ -427,8 +438,17 @@ void wxAuiGenericTabArt::DrawTab(wxDC& dc,
dc.DrawRectangle(r.x+1, r.y+1, r.width-1, r.height-4); dc.DrawRectangle(r.x+1, r.y+1, r.width-1, r.height-4);
// this white helps fill out the gradient at the top of the tab // this white helps fill out the gradient at the top of the tab
dc.SetPen(*wxWHITE_PEN); wxColor gradient = *wxWHITE;
dc.SetBrush(*wxWHITE_BRUSH); if ((m_baseColour.Red() < 75)
&& (m_baseColour.Green() < 75)
&& (m_baseColour.Blue() < 75))
{
//dark mode, we go darker
gradient = m_activeColour.ChangeLightness(70);
}
dc.SetPen(wxPen(gradient));
dc.SetBrush(wxBrush(gradient));
dc.DrawRectangle(r.x+2, r.y+1, r.width-3, r.height-4); dc.DrawRectangle(r.x+2, r.y+1, r.width-3, r.height-4);
// these two points help the rounded corners appear more antialiased // these two points help the rounded corners appear more antialiased
@@ -444,7 +464,7 @@ void wxAuiGenericTabArt::DrawTab(wxDC& dc,
r.y -= 2; r.y -= 2;
// draw gradient background // draw gradient background
wxColor top_color = *wxWHITE; wxColor top_color = gradient;
wxColor bottom_color = m_activeColour; wxColor bottom_color = m_activeColour;
dc.GradientFillLinear(r, bottom_color, top_color, wxNORTH); dc.GradientFillLinear(r, bottom_color, top_color, wxNORTH);
} }
@@ -466,6 +486,15 @@ void wxAuiGenericTabArt::DrawTab(wxDC& dc,
// -- draw top gradient fill for glossy look // -- draw top gradient fill for glossy look
wxColor top_color = m_baseColour; wxColor top_color = m_baseColour;
wxColor bottom_color = top_color.ChangeLightness(160); wxColor bottom_color = top_color.ChangeLightness(160);
if ((m_baseColour.Red() < 75)
&& (m_baseColour.Green() < 75)
&& (m_baseColour.Blue() < 75))
{
//dark mode, we go darker
top_color = m_activeColour.ChangeLightness(70);
bottom_color = m_baseColour;
}
dc.GradientFillLinear(r, bottom_color, top_color, wxNORTH); dc.GradientFillLinear(r, bottom_color, top_color, wxNORTH);
r.y += r.height; r.y += r.height;
@@ -532,6 +561,16 @@ void wxAuiGenericTabArt::DrawTab(wxDC& dc,
tab_width - (text_offset-tab_x) - close_button_width); tab_width - (text_offset-tab_x) - close_button_width);
// draw tab text // draw tab text
#if defined( __WXMAC__ )
if (page.active)
{
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT));
}
else
{
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_INACTIVECAPTIONTEXT));
}
#endif
dc.DrawText(draw_text, dc.DrawText(draw_text,
text_offset, text_offset,
drawn_tab_yoff + (drawn_tab_height)/2 - (texty/2) - 1); drawn_tab_yoff + (drawn_tab_height)/2 - (texty/2) - 1);
@@ -1317,3 +1356,4 @@ void wxAuiSimpleTabArt::SetMeasuringFont(const wxFont& font)
} }
#endif // wxUSE_AUI #endif // wxUSE_AUI