diff --git a/include/wx/bmpbndl.h b/include/wx/bmpbndl.h index 1b137e588a..ddcba2930d 100644 --- a/include/wx/bmpbndl.h +++ b/include/wx/bmpbndl.h @@ -152,7 +152,11 @@ public: // Implementation only from now on. // Get the bitmap size preferred by the majority of the elements of the - // bundles at the scale appropriate for the given scale. + // bundles at the given scale or the scale appropriate for the given window. + static wxSize + GetConsensusSizeFor(double scale, + const wxVector& bundles, + const wxSize& sizeDefault); static wxSize GetConsensusSizeFor(wxWindow* win, const wxVector& bundles, diff --git a/src/common/bmpbndl.cpp b/src/common/bmpbndl.cpp index 3316c0b14e..fb02842521 100644 --- a/src/common/bmpbndl.cpp +++ b/src/common/bmpbndl.cpp @@ -596,7 +596,15 @@ wxBitmapBundle::GetConsensusSizeFor(wxWindow* win, const wxVector& bundles, const wxSize& sizeDefault) { - const double scale = win->GetDPIScaleFactor(); + return GetConsensusSizeFor(win->GetDPIScaleFactor(), bundles, sizeDefault); +} + +/* static */ +wxSize +wxBitmapBundle::GetConsensusSizeFor(double scale, + const wxVector& bundles, + const wxSize& sizeDefault) +{ const wxSize sizeIdeal = sizeDefault*scale; // We want to use preferred bitmap size, but the preferred sizes can be diff --git a/tests/graphics/bmpbundle.cpp b/tests/graphics/bmpbundle.cpp index c90e022e6d..dbb2e9a50e 100644 --- a/tests/graphics/bmpbundle.cpp +++ b/tests/graphics/bmpbundle.cpp @@ -460,3 +460,34 @@ TEST_CASE("BitmapBundle::Scale", "[bmpbundle][scale]") } #endif // ports with scaled bitmaps support + +TEST_CASE("BitmapBundle::GetConsensusSize", "[bmpbundle]") +{ + // Just a trivial helper to make writing the tests below simpler. + struct Bundles + { + wxVector vec; + + void Add(int size) + { + vec.push_back(wxBitmapBundle::FromBitmap(wxSize(size, size))); + } + + int GetConsensusSize(double scale) const + { + return wxBitmapBundle::GetConsensusSizeFor(scale, vec, wxSize()).y; + } + } bundles; + + // When there is a tie, a larger size is chosen by default. + bundles.Add(16); + bundles.Add(24); + CHECK( bundles.GetConsensusSize(2) == 48 ); + + // Breaking the tie results in the smaller size winning now. + bundles.Add(16); + CHECK( bundles.GetConsensusSize(2) == 32 ); + + // Integer scaling factors should be preferred. + CHECK( bundles.GetConsensusSize(1.5) == 16 ); +}