diff --git a/include/wx/generic/imaglist.h b/include/wx/generic/imaglist.h index 7fe9fc6b6d..a720c36a2d 100644 --- a/include/wx/generic/imaglist.h +++ b/include/wx/generic/imaglist.h @@ -62,6 +62,8 @@ private: // Size of a single bitmap in the list. wxSize m_size; + // Images in the list should have the same scale factor. + double m_scaleFactor; wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxGenericImageList); }; diff --git a/src/generic/imaglist.cpp b/src/generic/imaglist.cpp index bf880c6d2a..e6f6763195 100644 --- a/src/generic/imaglist.cpp +++ b/src/generic/imaglist.cpp @@ -48,13 +48,14 @@ bool wxGenericImageList::Create( int width, int height, bool mask, int WXUNUSED( { m_size = wxSize(width, height); m_useMask = mask; + m_scaleFactor = 1.0; return true; } namespace { -wxBitmap GetImageListBitmap(const wxBitmap& bitmap, bool useMask, const wxSize& imgSize) +wxBitmap GetImageListBitmap(const wxBitmap& bitmap, bool useMask, const wxSize& imgSize, double scaleFactor) { wxBitmap bmp(bitmap); if ( useMask ) @@ -69,7 +70,7 @@ wxBitmap GetImageListBitmap(const wxBitmap& bitmap, bool useMask, const wxSize& #if wxUSE_IMAGE wxImage img = bmp.ConvertToImage(); img.ClearAlpha(); - bmp = wxBitmap(img, -1, bmp.GetScaleFactor()); + bmp = wxBitmap(img, -1, scaleFactor); #endif // wxUSE_IMAGE } } @@ -81,7 +82,7 @@ wxBitmap GetImageListBitmap(const wxBitmap& bitmap, bool useMask, const wxSize& #if wxUSE_IMAGE wxImage img = bmp.ConvertToImage(); img.ConvertAlphaToMask(); - bmp = wxBitmap(img, -1, bmp.GetScaleFactor()); + bmp = wxBitmap(img, -1, scaleFactor); #endif // wxUSE_IMAGE } else @@ -107,7 +108,7 @@ wxBitmap GetImageListBitmap(const wxBitmap& bitmap, bool useMask, const wxSize& #if wxUSE_IMAGE wxImage img = bmp.ConvertToImage(); img.InitAlpha(); - bmp = wxBitmap(img, -1, bmp.GetScaleFactor()); + bmp = wxBitmap(img, -1, scaleFactor); #else bmp.SetMask(NULL); #endif // wxUSE_IMAGE @@ -153,6 +154,13 @@ int wxGenericImageList::Add( const wxBitmap &bitmap ) // This is the first time Add() is called and we hadn't had any fixed // size: adopt the size of our first bitmap as image size. m_size = bitmapSize; + // Save scale factor to check if all images 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; } // There is a special case: a bitmap may contain more than one image, @@ -160,7 +168,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_images.push_back(GetImageListBitmap(bitmap, m_useMask, m_size, m_scaleFactor)); } else if ( bitmapSize.x > m_size.x ) { @@ -168,7 +176,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_images.push_back(GetImageListBitmap(bitmap.GetSubBitmap(rect), m_useMask, m_size, m_scaleFactor)); } } else @@ -233,11 +241,17 @@ 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_images[index] = GetImageListBitmap(bmp, m_useMask, m_size, m_scaleFactor); return true; }