wxOSX Retina fixes: wxImageList::GetSize().

wxImageList returns size of its bitmap as pixel size, i.e.  twice the
displayed screen on HiDPI screens.  Unfortunately,
wxImageList::GetSize() is used heavily in (generic) GUI drawing code,
e.g.  to properly size wxListCtrl's icon columns.  As wxImageList is
used primarily by controls, it seems reasonable to adjust for scaling
here, rather than requiring all users of the class to do it.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75351 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2013-12-04 14:33:10 +00:00
parent b5e7f21065
commit 04121a371a

View File

@@ -73,16 +73,16 @@ int wxImageList::Add( const wxIcon &bitmap )
int wxImageList::Add( const wxBitmap &bitmap ) int wxImageList::Add( const wxBitmap &bitmap )
{ {
wxASSERT_MSG( (bitmap.GetWidth() >= m_width && bitmap.GetHeight() == m_height) wxASSERT_MSG( (bitmap.GetScaledWidth() >= m_width && bitmap.GetScaledHeight() == m_height)
|| (m_width == 0 && m_height == 0), || (m_width == 0 && m_height == 0),
wxT("invalid bitmap size in wxImageList: this might work ") wxT("invalid bitmap size in wxImageList: this might work ")
wxT("on this platform but definitely won't under Windows.") ); wxT("on this platform but definitely won't under Windows.") );
// Mimic behaviour of Windows ImageList_Add that automatically breaks up the added // Mimic behaviour of Windows ImageList_Add that automatically breaks up the added
// bitmap into sub-images of the correct size // bitmap into sub-images of the correct size
if (m_width > 0 && bitmap.GetWidth() > m_width && bitmap.GetHeight() >= m_height) if (m_width > 0 && bitmap.GetScaledWidth() > m_width && bitmap.GetScaledHeight() >= m_height)
{ {
int numImages = bitmap.GetWidth() / m_width; int numImages = bitmap.GetScaledWidth() / m_width;
for (int subIndex = 0; subIndex < numImages; subIndex++) for (int subIndex = 0; subIndex < numImages; subIndex++)
{ {
wxRect rect(m_width * subIndex, 0, m_width, m_height); wxRect rect(m_width * subIndex, 0, m_width, m_height);
@@ -97,8 +97,8 @@ int wxImageList::Add( const wxBitmap &bitmap )
if (m_width == 0 && m_height == 0) if (m_width == 0 && m_height == 0)
{ {
m_width = bitmap.GetWidth(); m_width = bitmap.GetScaledWidth();
m_height = bitmap.GetHeight(); m_height = bitmap.GetScaledHeight();
} }
return m_images.GetCount() - 1; return m_images.GetCount() - 1;
@@ -275,8 +275,8 @@ bool wxImageList::GetSize( int index, int &width, int &height ) const
else else
{ {
wxBitmap *bm = static_cast< wxBitmap* >(obj ) ; wxBitmap *bm = static_cast< wxBitmap* >(obj ) ;
width = bm->GetWidth(); width = bm->GetScaledWidth();
height = bm->GetHeight(); height = bm->GetScaledHeight();
} }
return true; return true;