From 20f82e2ccb949db99c5eda3d9022fc4fabfb0b29 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 11 Feb 2022 16:47:19 +0000 Subject: [PATCH] Fix CreateWithLogicalSize() to set correct scale in wxMSW too Unlike under Mac (see previous commit), this never worked correctly in wxMSW at all, only SetScaleFactor() could be used to change the scale factor of the bitmaps there. Fix this and make CreateWithLogicalSize(..., scale) result in GetScaleFactor() returning the same scale for the resulting bitmap, as expected, under MSW too. Also add a unit test verifying that this holds. --- src/msw/bitmap.cpp | 7 ++++++- tests/graphics/bmpbundle.cpp | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index ae48064330..fa78d2b1b0 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -765,7 +765,12 @@ bool wxBitmap::Create(int width, int height, const wxDC& dc) bool wxBitmap::CreateWithLogicalSize(const wxSize& size, double scale, int depth) { - return Create(size*scale, depth); + if ( !Create(size*scale, depth) ) + return false; + + GetBitmapData()->m_scaleFactor = scale; + + return true; } bool wxBitmap::DoCreate(int w, int h, int d, WXHDC hdc) diff --git a/tests/graphics/bmpbundle.cpp b/tests/graphics/bmpbundle.cpp index 9d8dcabb41..38c1622161 100644 --- a/tests/graphics/bmpbundle.cpp +++ b/tests/graphics/bmpbundle.cpp @@ -172,8 +172,13 @@ TEST_CASE("BitmapBundle::Scale", "[bmpbundle][scale]") // This is not a wxBitmapBundle test, strictly speaking, but check that // setting scale factor works correctly for bitmaps, as wxBitmapBundle does // this internally. - wxBitmap bmp(16, 16); - bmp.SetScaleFactor(2); + wxBitmap bmp; + bmp.CreateWithLogicalSize(8, 8, 2); +#ifdef wxHAS_DPI_INDEPENDENT_PIXELS + CHECK( bmp.GetLogicalSize() == wxSize(8, 8) ); +#endif + CHECK( bmp.GetDIPSize() == wxSize(8, 8) ); + CHECK( bmp.GetSize() == wxSize(16, 16) ); CHECK( bmp.GetScaleFactor() == 2 ); wxBitmap bmp2(bmp);