Work around wxWidgets ConvertToDisabled not being dark-mode aware

Fixes https://gitlab.com/kicad/code/kicad/-/issues/8297
This commit is contained in:
Jon Evans 2021-04-25 13:05:10 -04:00
parent e3eacafbcb
commit d3194cc6db
1 changed files with 24 additions and 12 deletions

View File

@ -27,6 +27,7 @@
#include <bitmaps.h>
#include <eda_draw_frame.h>
#include <functional>
#include <kiplatform/ui.h>
#include <math/util.h>
#include <memory>
#include <pgm_base.h>
@ -43,6 +44,12 @@
#include <wx/sizer.h>
wxBitmap MakeDisabledBitmap( const wxBitmap& aSource )
{
return aSource.ConvertToDisabled( KIPLATFORM::UI::IsDarkTheme() ? 70 : 255 );
}
ACTION_GROUP::ACTION_GROUP( std::string aName, const std::vector<const TOOL_ACTION*>& 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();