From 0e642c113a6bf24d03b3f74e28129bc9da8f6ec6 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Sat, 3 Jan 2026 04:30:57 +0300 Subject: [PATCH] Use bitmap bundles in GRID_CELL_ICON_RENDERER. --- common/widgets/grid_icon_text_helpers.cpp | 16 +++++++++++----- include/widgets/grid_icon_text_helpers.h | 4 ++-- .../dialog_multichannel_repeat_layout.cpp | 2 +- .../dialogs/dialog_multichannel_repeat_layout.h | 8 ++++---- pcbnew/sel_layer.cpp | 3 +-- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/common/widgets/grid_icon_text_helpers.cpp b/common/widgets/grid_icon_text_helpers.cpp index 8f40067909..21bad12011 100644 --- a/common/widgets/grid_icon_text_helpers.cpp +++ b/common/widgets/grid_icon_text_helpers.cpp @@ -154,7 +154,7 @@ wxSize GRID_CELL_ICON_TEXT_RENDERER::GetBestSize( wxGrid& grid, wxGridCellAttr& } -GRID_CELL_ICON_RENDERER::GRID_CELL_ICON_RENDERER( const wxBitmap& icon ) : +GRID_CELL_ICON_RENDERER::GRID_CELL_ICON_RENDERER( const wxBitmapBundle& icon ) : m_icon( icon ) { } @@ -172,9 +172,12 @@ void GRID_CELL_ICON_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& // Draw icon if( m_icon.IsOk() ) { - aDC.DrawBitmap( m_icon, - rect.GetLeft() + ( rect.GetWidth() - m_icon.GetWidth() ) / 2, - rect.GetTop() + ( rect.GetHeight() - m_icon.GetHeight() ) / 2, + wxSize logicSize = aGrid.FromDIP( m_icon.GetDefaultSize() ); + wxSize physSize = aGrid.ToPhys( logicSize ); + + aDC.DrawBitmap( m_icon.GetBitmap( physSize ), + rect.GetLeft() + ( rect.GetWidth() - logicSize.GetWidth() ) / 2, + rect.GetTop() + ( rect.GetHeight() - logicSize.GetHeight() ) / 2, true ); } } @@ -183,7 +186,10 @@ void GRID_CELL_ICON_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& wxSize GRID_CELL_ICON_RENDERER::GetBestSize( wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col ) { - return wxSize( m_icon.GetWidth() + 6, m_icon.GetHeight() + 4 ); + wxSize size = m_icon.GetDefaultSize(); + size.IncBy( 6, 4 ); + + return grid.FromDIP( size ); } diff --git a/include/widgets/grid_icon_text_helpers.h b/include/widgets/grid_icon_text_helpers.h index 58e57e7584..b379764b75 100644 --- a/include/widgets/grid_icon_text_helpers.h +++ b/include/widgets/grid_icon_text_helpers.h @@ -75,7 +75,7 @@ private: class KICOMMON_API GRID_CELL_ICON_RENDERER : public wxGridCellRenderer { public: - GRID_CELL_ICON_RENDERER( const wxBitmap& icon ); + GRID_CELL_ICON_RENDERER( const wxBitmapBundle& aIcon ); void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC, const wxRect& aRect, int aRow, int aCol, bool isSelected ) override; @@ -84,7 +84,7 @@ public: wxGridCellRenderer* Clone() const override; private: - wxBitmap m_icon; + wxBitmapBundle m_icon; }; //---- Grid helpers: custom wxGridCellRenderer that renders just an icon from wxArtprovider - diff --git a/pcbnew/dialogs/dialog_multichannel_repeat_layout.cpp b/pcbnew/dialogs/dialog_multichannel_repeat_layout.cpp index af27a5fd5a..b2851575ee 100644 --- a/pcbnew/dialogs/dialog_multichannel_repeat_layout.cpp +++ b/pcbnew/dialogs/dialog_multichannel_repeat_layout.cpp @@ -39,7 +39,7 @@ DIALOG_MULTICHANNEL_REPEAT_LAYOUT::DIALOG_MULTICHANNEL_REPEAT_LAYOUT( PCB_BASE_F m_parentTool( aParentTool ) { m_board = aFrame->GetBoard(); - m_detailsIcon = KiBitmap( BITMAPS::help, 16 ); + m_detailsIcon = KiBitmapBundleDef( BITMAPS::help, 16 ); m_raGrid->PushEventHandler( new GRID_TRICKS( static_cast( m_raGrid ) ) ); m_raGrid->ClearGrid(); diff --git a/pcbnew/dialogs/dialog_multichannel_repeat_layout.h b/pcbnew/dialogs/dialog_multichannel_repeat_layout.h index e7aaf0436f..861646cc69 100644 --- a/pcbnew/dialogs/dialog_multichannel_repeat_layout.h +++ b/pcbnew/dialogs/dialog_multichannel_repeat_layout.h @@ -25,7 +25,7 @@ #define __DIALOG_MULTICHANNEL_REPEAT_LAYOUT__ #include -#include +#include #include #include @@ -60,9 +60,9 @@ private: void OnGridCellLeftClick( wxGridEvent& aEvent ); std::vector m_targetRAs; - MULTICHANNEL_TOOL* m_parentTool; - BOARD* m_board; - wxBitmap m_detailsIcon; + MULTICHANNEL_TOOL* m_parentTool; + BOARD* m_board; + wxBitmapBundle m_detailsIcon; }; #endif diff --git a/pcbnew/sel_layer.cpp b/pcbnew/sel_layer.cpp index b7c3676f71..f6ad6fde21 100644 --- a/pcbnew/sel_layer.cpp +++ b/pcbnew/sel_layer.cpp @@ -445,8 +445,7 @@ private: // Set the color swatch wxBitmapBundle swatch = m_layerPresentation.CreateLayerPairIcon( layerPair.GetLayerA(), layerPair.GetLayerB() ); - m_grid.SetCellRenderer( aRow, (int) COLNUMS::SWATCH, - new GRID_CELL_ICON_RENDERER( swatch.GetBitmap( swatch.GetDefaultSize() ) ) ); + m_grid.SetCellRenderer( aRow, (int) COLNUMS::SWATCH, new GRID_CELL_ICON_RENDERER( swatch ) ); m_grid.SetReadOnly( aRow, (int) COLNUMS::SWATCH ); m_grid.SetReadOnly( aRow, (int) COLNUMS::LAYERNAMES );