From ca556568502ea894017758d92b73a5a40cc590b6 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Sun, 6 Aug 2023 13:53:34 -0400 Subject: [PATCH] Prevent negative center calc on BITMAP_BUTTON --- common/widgets/bitmap_button.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/widgets/bitmap_button.cpp b/common/widgets/bitmap_button.cpp index 0af43c4531..4c5499e979 100644 --- a/common/widgets/bitmap_button.cpp +++ b/common/widgets/bitmap_button.cpp @@ -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