Fix bitmap scaling for SPLIT_BUTTON

This commit is contained in:
Jon Evans 2023-06-03 12:41:40 -04:00
parent 8f69336ad1
commit 1aff03eadb
2 changed files with 10 additions and 9 deletions

View File

@ -93,11 +93,11 @@ void SPLIT_BUTTON::SetWidthPadding( int aPadding )
} }
void SPLIT_BUTTON::SetBitmap( const wxBitmap& aBmp ) void SPLIT_BUTTON::SetBitmap( const wxBitmapBundle& aBmp )
{ {
m_bitmap = aBmp; m_bitmap = aBmp;
SetMinSize( wxSize( m_bitmap.GetWidth(), m_bitmap.GetHeight() ) ); SetMinSize( m_bitmap.GetPreferredBitmapSizeFor( this ) );
} }
@ -284,16 +284,17 @@ void SPLIT_BUTTON::OnPaint( wxPaintEvent& WXUNUSED( aEvent ) )
if( m_bitmap.IsOk() ) if( m_bitmap.IsOk() )
{ {
wxMemoryDC mdc( m_bitmap ); wxBitmap bmp = m_bitmap.GetBitmapFor( this );
wxMemoryDC mdc( bmp );
r1.x = ( width - m_bitmap.GetWidth() ) / 2; r1.x = ( width - bmp.GetWidth() ) / 2;
if( r1.x < 0 ) if( r1.x < 0 )
r1.x = 0; r1.x = 0;
r1.y += ( size.GetHeight() - m_bitmap.GetHeight() ) / 2; r1.y += ( size.GetHeight() - bmp.GetHeight() ) / 2;
dc.Blit( wxPoint( r1.x, r1.y ), m_bitmap.GetSize(), &mdc, wxPoint( 0, 0 ), wxCOPY, true ); dc.Blit( wxPoint( r1.x, r1.y ), bmp.GetSize(), &mdc, wxPoint( 0, 0 ), wxCOPY, true );
} }
else else
{ {

View File

@ -25,7 +25,7 @@
#ifndef __SPLIT_BUTTON_H__ #ifndef __SPLIT_BUTTON_H__
#define __SPLIT_BUTTON_H__ #define __SPLIT_BUTTON_H__
#include <wx/bitmap.h> #include <wx/bmpbndl.h>
#include <wx/panel.h> #include <wx/panel.h>
class wxButton; class wxButton;
@ -40,7 +40,7 @@ public:
~SPLIT_BUTTON(); ~SPLIT_BUTTON();
wxMenu* GetSplitButtonMenu(); wxMenu* GetSplitButtonMenu();
void SetBitmap( const wxBitmap& aBmp ); void SetBitmap( const wxBitmapBundle& aBmp );
void SetMinSize( const wxSize& aSize ) override; void SetMinSize( const wxSize& aSize ) override;
void SetWidthPadding( int aPadding ); void SetWidthPadding( int aPadding );
void SetLabel( const wxString& aLabel ) override; void SetLabel( const wxString& aLabel ) override;
@ -65,7 +65,7 @@ private:
bool m_bLButtonDown = false; bool m_bLButtonDown = false;
wxString m_label; wxString m_label;
wxMenu* m_pMenu = nullptr; wxMenu* m_pMenu = nullptr;
wxBitmap m_bitmap; wxBitmapBundle m_bitmap;
wxSize m_unadjustedMinSize; wxSize m_unadjustedMinSize;
}; };