Prevent negative center calc on BITMAP_BUTTON

This commit is contained in:
Marek Roszko 2023-08-06 13:53:34 -04:00
parent 856b70b4df
commit ca55656850
1 changed files with 4 additions and 1 deletions

View File

@ -289,7 +289,10 @@ void BITMAP_BUTTON::OnPaint( wxPaintEvent& aEvent )
wxBitmap bmpImg = bmp.GetBitmapFor( this );
if( m_centerBitmap )
{
drawBmpPos = wxPoint( (rect.width - bmpImg.GetWidth()) / 2, (rect.height - bmpImg.GetHeight()) / 2 );
// dont let it go negative if bmp is larger than the button
int x = std::max( ( rect.width - bmpImg.GetWidth() ) / 2, 0 );
int y = std::max( ( rect.height - bmpImg.GetHeight() ) / 2, 0 );
drawBmpPos = wxPoint( x, y );
}
// Draw the bitmap with the upper-left corner offset by the padding