From d3194cc6dbc1aaad45ac0ca91cacc2a689ced0b7 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 25 Apr 2021 13:05:10 -0400 Subject: [PATCH] Work around wxWidgets ConvertToDisabled not being dark-mode aware Fixes https://gitlab.com/kicad/code/kicad/-/issues/8297 --- common/tool/action_toolbar.cpp | 36 ++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/common/tool/action_toolbar.cpp b/common/tool/action_toolbar.cpp index e296d83b67..e54aea194d 100644 --- a/common/tool/action_toolbar.cpp +++ b/common/tool/action_toolbar.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,12 @@ #include +wxBitmap MakeDisabledBitmap( const wxBitmap& aSource ) +{ + return aSource.ConvertToDisabled( KIPLATFORM::UI::IsDarkTheme() ? 70 : 255 ); +} + + ACTION_GROUP::ACTION_GROUP( std::string aName, const std::vector& aActions ) { wxASSERT_MSG( aActions.size() > 0, "Action groups must have at least one action" ); @@ -103,7 +110,7 @@ ACTION_TOOLBAR_PALETTE::ACTION_TOOLBAR_PALETTE( wxWindow* aParent, bool aVertica void ACTION_TOOLBAR_PALETTE::AddAction( const TOOL_ACTION& aAction ) { wxBitmap normalBmp = KiScaledBitmap( aAction.GetIcon(), this ); - wxBitmap disabledBmp = normalBmp.ConvertToDisabled(); + wxBitmap disabledBmp = MakeDisabledBitmap( normalBmp ); int padding = ( m_buttonSize.GetWidth() - normalBmp.GetWidth() ) / 2; @@ -214,10 +221,12 @@ void ACTION_TOOLBAR::Add( const TOOL_ACTION& aAction, bool aIsToggleEntry, bool wxASSERT( GetParent() ); wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ), "aIsCancellable requires aIsToggleEntry" ); - int toolId = aAction.GetUIId(); + int toolId = aAction.GetUIId(); + wxBitmap bmp = KiScaledBitmap( aAction.GetIcon(), GetParent() ); - AddTool( toolId, wxEmptyString, KiScaledBitmap( aAction.GetIcon(), GetParent() ), - aAction.GetDescription(), aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL ); + AddTool( toolId, wxEmptyString, bmp, MakeDisabledBitmap( bmp ), + aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL, + aAction.GetDescription(), wxEmptyString, nullptr ); m_toolKinds[ toolId ] = aIsToggleEntry; m_toolActions[ toolId ] = &aAction; @@ -227,10 +236,11 @@ void ACTION_TOOLBAR::Add( const TOOL_ACTION& aAction, bool aIsToggleEntry, bool void ACTION_TOOLBAR::AddButton( const TOOL_ACTION& aAction ) { - int toolId = aAction.GetUIId(); + int toolId = aAction.GetUIId(); + wxBitmap bmp = KiScaledBitmap( aAction.GetIcon(), GetParent() ); - AddTool( toolId, wxEmptyString, KiScaledBitmap( aAction.GetIcon(), GetParent() ), - aAction.GetName(), wxITEM_NORMAL ); + AddTool( toolId, wxEmptyString, bmp, MakeDisabledBitmap( bmp ), + wxITEM_NORMAL, aAction.GetDescription(), wxEmptyString, nullptr ); m_toolKinds[ toolId ] = false; m_toolActions[ toolId ] = &aAction; @@ -267,6 +277,7 @@ void ACTION_TOOLBAR::AddGroup( ACTION_GROUP* aGroup, bool aIsToggleEntry ) { int groupId = aGroup->GetUIId(); const TOOL_ACTION* defaultAction = aGroup->GetDefaultAction(); + wxBitmap bmp = KiScaledBitmap( defaultAction->GetIcon(), GetParent() ); wxASSERT( GetParent() ); wxASSERT( defaultAction ); @@ -276,8 +287,9 @@ void ACTION_TOOLBAR::AddGroup( ACTION_GROUP* aGroup, bool aIsToggleEntry ) m_actionGroups[ groupId ] = aGroup; // Add the main toolbar item representing the group - AddTool( groupId, wxEmptyString, KiScaledBitmap( defaultAction->GetIcon(), GetParent() ), - wxEmptyString, aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL ); + AddTool( groupId, wxEmptyString, bmp, MakeDisabledBitmap( bmp ), + aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL, + wxEmptyString, wxEmptyString, nullptr ); // Select the default action doSelectAction( aGroup, *defaultAction ); @@ -312,7 +324,7 @@ void ACTION_TOOLBAR::doSelectAction( ACTION_GROUP* aGroup, const TOOL_ACTION& aA // Update the item information item->SetShortHelp( aAction.GetDescription() ); item->SetBitmap( KiScaledBitmap( aAction.GetIcon(), GetParent() ) ); - item->SetDisabledBitmap( item->GetBitmap().ConvertToDisabled() ); + item->SetDisabledBitmap( MakeDisabledBitmap( item->GetBitmap() ) ); // Register a new handler with the new UI conditions if( m_toolManager ) @@ -391,7 +403,7 @@ void ACTION_TOOLBAR::SetToolBitmap( const TOOL_ACTION& aAction, const wxBitmap& wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId ); if( tb_item ) - tb_item->SetDisabledBitmap( aBitmap.ConvertToDisabled() ); + tb_item->SetDisabledBitmap( MakeDisabledBitmap( aBitmap ) ); } @@ -805,7 +817,7 @@ void ACTION_TOOLBAR::RefreshBitmaps() wxBitmap bmp = KiScaledBitmap( pair.second->GetIcon(), GetParent() ); tool->SetBitmap( bmp ); - tool->SetDisabledBitmap( bmp.ConvertToDisabled() ); + tool->SetDisabledBitmap( MakeDisabledBitmap( bmp ) ); } Refresh();