mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-03-30 06:26:55 +00:00
Fix palette icon scaling on Windows, also extend KiBitmapBundle because we use bundles wrong
wxBitmapBundle assumes the smallest bitmap added is the intended "original" size for a particular use case. And generally that is probably true. However, we re-use icons in some places where we intend for them to start at 16 or start at 24. This is problematic when GetPreferredBitmapSizeFor is called for calculations because it'll return the 16*scale number instead of 24*scale number. So let's just allow passing in a min height restriction to KiBitmapBundle for when we reuse bitmaps.
This commit is contained in:
parent
636c6c4efb
commit
50e2a12e17
common
include
@ -107,9 +107,9 @@ wxBitmap KiBitmap( BITMAPS aBitmap, int aHeightTag )
|
||||
}
|
||||
|
||||
|
||||
wxBitmapBundle KiBitmapBundle( BITMAPS aBitmap )
|
||||
wxBitmapBundle KiBitmapBundle( BITMAPS aBitmap, int aMinHeight )
|
||||
{
|
||||
return GetBitmapStore()->GetBitmapBundle( aBitmap );
|
||||
return GetBitmapStore()->GetBitmapBundle( aBitmap, aMinHeight );
|
||||
}
|
||||
|
||||
|
||||
|
@ -121,7 +121,7 @@ wxBitmap BITMAP_STORE::GetBitmap( BITMAPS aBitmapId, int aHeight )
|
||||
}
|
||||
|
||||
|
||||
wxBitmapBundle BITMAP_STORE::GetBitmapBundle( BITMAPS aBitmapId )
|
||||
wxBitmapBundle BITMAP_STORE::GetBitmapBundle( BITMAPS aBitmapId, int aMinHeight )
|
||||
{
|
||||
wxVector<wxBitmap> bmps;
|
||||
|
||||
@ -130,6 +130,9 @@ wxBitmapBundle BITMAP_STORE::GetBitmapBundle( BITMAPS aBitmapId )
|
||||
if( info.theme != m_theme )
|
||||
continue;
|
||||
|
||||
if( aMinHeight > 0 && info.height < aMinHeight )
|
||||
continue;
|
||||
|
||||
bmps.push_back( wxBitmap( getImage( info.id, info.height ) ) );
|
||||
}
|
||||
|
||||
|
@ -114,16 +114,15 @@ ACTION_TOOLBAR_PALETTE::ACTION_TOOLBAR_PALETTE( wxWindow* aParent, bool aVertica
|
||||
|
||||
void ACTION_TOOLBAR_PALETTE::AddAction( const TOOL_ACTION& aAction )
|
||||
{
|
||||
wxBitmapBundle normalBmp = KiBitmapBundle( aAction.GetIcon() );
|
||||
int size = Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size;
|
||||
wxBitmapBundle normalBmp = KiBitmapBundle( aAction.GetIcon(), size );
|
||||
|
||||
int bmpWidth = normalBmp.GetPreferredBitmapSizeFor( this ).GetWidth();
|
||||
int padding = ( m_buttonSize.GetWidth() - bmpWidth ) / 2;
|
||||
int size = Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size;
|
||||
wxSize bmSize( size, size );
|
||||
bmSize *= KIPLATFORM::UI::GetPixelScaleFactor( m_parent );
|
||||
bmSize *= KIPLATFORM::UI::GetContentScaleFactor( m_parent );
|
||||
|
||||
BITMAP_BUTTON* button = new BITMAP_BUTTON( m_panel, aAction.GetUIId(), wxDefaultPosition,
|
||||
bmSize );
|
||||
BITMAP_BUTTON* button = new BITMAP_BUTTON( m_panel, aAction.GetUIId() );
|
||||
|
||||
button->SetIsToolbarButton();
|
||||
button->SetBitmap( normalBmp );
|
||||
|
@ -336,14 +336,14 @@ void BITMAP_BUTTON::OnPaint( wxPaintEvent& aEvent )
|
||||
|
||||
wxPoint drawBmpPos( m_padding, m_padding );
|
||||
wxBitmap bmpImg;
|
||||
double scale = KIPLATFORM::UI::GetPixelScaleFactor( this );
|
||||
double scale = KIPLATFORM::UI::GetContentScaleFactor( this );
|
||||
wxSize bmSize;
|
||||
|
||||
if( m_isToolbarButton )
|
||||
{
|
||||
int size = Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size;
|
||||
bmSize = wxSize( size, size );
|
||||
bmpImg = bmp.GetBitmap( bmSize * scale );
|
||||
bmSize = wxSize( size, size ) * scale;
|
||||
bmpImg = bmp.GetBitmap( bmSize );
|
||||
|
||||
// wxBitmapBundle::GetBitmap thinks we need this rescaled to match the base size
|
||||
if( bmpImg.IsOk() )
|
||||
|
@ -60,9 +60,13 @@ public:
|
||||
/**
|
||||
* Constructs and returns a bitmap bundle containing all available sizes of the given ID
|
||||
* @param aBitmapId is from the BITMAPS enum in bitmaps_list.h
|
||||
* @param aMinHeight is the minimum height of the bitmaps to include in the bundle.
|
||||
* This is important for uses of GetPreferredBitmap and more on wxBitmap bundles because
|
||||
* wx assumes the smallest bitmap is the "original" intended size. This is a problem where
|
||||
* some icons may be reused between controls at different intended sizes.
|
||||
*/
|
||||
wxBitmapBundle GetBitmapBundle( BITMAPS aBitmapId );
|
||||
|
||||
wxBitmapBundle GetBitmapBundle( BITMAPS aBitmapId, int aMinHeight = -1 );
|
||||
|
||||
/**
|
||||
* Constructs and returns a bitmap bundle for the given icon ID, with the bitmaps
|
||||
* converted to disabled state according to the current UI theme.
|
||||
|
@ -56,7 +56,7 @@ KICOMMON_API BITMAP_STORE* GetBitmapStore();
|
||||
*/
|
||||
KICOMMON_API wxBitmap KiBitmap( BITMAPS aBitmap, int aHeightTag = -1 );
|
||||
|
||||
KICOMMON_API wxBitmapBundle KiBitmapBundle( BITMAPS aBitmap );
|
||||
KICOMMON_API wxBitmapBundle KiBitmapBundle( BITMAPS aBitmap, int aMinHeight = -1 );
|
||||
|
||||
KICOMMON_API wxBitmapBundle KiDisabledBitmapBundle( BITMAPS aBitmap );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user