Revert "Assure that all images in the generic wxImageList have the same scale factor"

This reverts commit b6d305e4f2 because
silently discarding images using a different scale factor is simply too
user-unfriendly: this can silently break the existing code, i.e. it can
still compile perfectly and not give any errors during run-time but not
show any images neither.

Also revert most of dc43d15cf7 (Add tests of storing HiDPI images in
generic wxImageList (wxOSX, wxGTK3), 2021-04-05) as these tests don't
pass any longer because the behaviour was intentionally changed.

See #22189.
This commit is contained in:
Vadim Zeitlin
2022-03-20 22:10:20 +01:00
parent d9a48edc81
commit cc02b3cece
3 changed files with 46 additions and 232 deletions

View File

@@ -63,7 +63,6 @@ bool wxGenericImageList::Create( int width, int height, bool mask, int WXUNUSED(
// Prevent from storing negative dimensions
m_size = wxSize(wxMax(width, 0), wxMax(height, 0));
m_useMask = mask;
m_scaleFactor = 1.0;
// Images must have proper size
return m_size != wxSize(0, 0);
@@ -71,7 +70,7 @@ bool wxGenericImageList::Create( int width, int height, bool mask, int WXUNUSED(
namespace
{
wxBitmap GetImageListBitmap(const wxBitmap& bitmap, bool useMask, const wxSize& imgSize, double scaleFactor)
wxBitmap GetImageListBitmap(const wxBitmap& bitmap, bool useMask, const wxSize& imgSize)
{
wxBitmap bmp(bitmap);
if ( useMask )
@@ -86,7 +85,7 @@ wxBitmap GetImageListBitmap(const wxBitmap& bitmap, bool useMask, const wxSize&
#if wxUSE_IMAGE
wxImage img = bmp.ConvertToImage();
img.ClearAlpha();
bmp = wxBitmap(img, -1, scaleFactor);
bmp = wxBitmap(img, -1, bmp.GetScaleFactor());
#endif // wxUSE_IMAGE
}
}
@@ -98,7 +97,7 @@ wxBitmap GetImageListBitmap(const wxBitmap& bitmap, bool useMask, const wxSize&
#if wxUSE_IMAGE
wxImage img = bmp.ConvertToImage();
img.ConvertAlphaToMask();
bmp = wxBitmap(img, -1, scaleFactor);
bmp = wxBitmap(img, -1, bmp.GetScaleFactor());
#endif // wxUSE_IMAGE
}
else
@@ -124,7 +123,7 @@ wxBitmap GetImageListBitmap(const wxBitmap& bitmap, bool useMask, const wxSize&
#if wxUSE_IMAGE
wxImage img = bmp.ConvertToImage();
img.InitAlpha();
bmp = wxBitmap(img, -1, scaleFactor);
bmp = wxBitmap(img, -1, bmp.GetScaleFactor());
#else
bmp.SetMask(NULL);
#endif // wxUSE_IMAGE
@@ -149,6 +148,7 @@ wxBitmap GetImageListBitmap(const wxBitmap& bitmap, bool useMask, const wxSize&
#if wxUSE_IMAGE
wxImage img = bmp.ConvertToImage();
// We need image with new physical size
const double scaleFactor = bmp.GetScaleFactor();
wxImage imgResized = img.Size(scaleFactor * imgSize, wxPoint(0, 0), 0, 0, 0);
bmpResized = wxBitmap(imgResized, -1, scaleFactor);
#else
@@ -166,18 +166,6 @@ int wxGenericImageList::Add( const wxBitmap &bitmap )
if ( m_size == wxSize(0, 0) )
return -1;
if ( m_images.empty() )
{
// This is the first time Add() is called so we should save
// scale factor to check if further images will have the same scaling
m_scaleFactor = bitmap.GetScaleFactor();
}
else if ( bitmap.GetScaleFactor() != m_scaleFactor )
{
// All images in the list should have the same scale factor
return -1;
}
// We use the logical size here as image list images size is specified in
// logical pixels, just as window coordinates and sizes are.
const wxSize bitmapSize = bitmap.GetLogicalSize();
@@ -187,7 +175,7 @@ int wxGenericImageList::Add( const wxBitmap &bitmap )
// ImageList_Add() does.
if ( bitmapSize.x == m_size.x )
{
m_images.push_back(GetImageListBitmap(bitmap, m_useMask, m_size, m_scaleFactor));
m_images.push_back(GetImageListBitmap(bitmap, m_useMask, m_size));
}
else if ( bitmapSize.x > m_size.x )
{
@@ -195,7 +183,7 @@ int wxGenericImageList::Add( const wxBitmap &bitmap )
for (int subIndex = 0; subIndex < numImages; subIndex++)
{
wxRect rect(m_size.x * subIndex, 0, m_size.x, m_size.y);
m_images.push_back(GetImageListBitmap(bitmap.GetSubBitmap(rect), m_useMask, m_size, m_scaleFactor));
m_images.push_back(GetImageListBitmap(bitmap.GetSubBitmap(rect), m_useMask, m_size));
}
}
else
@@ -260,17 +248,11 @@ wxGenericImageList::Replace(int index,
if ( !DoGetPtr(index) )
return false;
if ( bitmap.GetScaleFactor() != m_scaleFactor )
{
// All images in the list should have the same scale factor
return false;
}
wxBitmap bmp(bitmap);
if ( mask.IsOk() )
bmp.SetMask(new wxMask(mask));
m_images[index] = GetImageListBitmap(bmp, m_useMask, m_size, m_scaleFactor);
m_images[index] = GetImageListBitmap(bmp, m_useMask, m_size);
return true;
}