Replace wxGenericImageList::m_{width,height} with m_size

Using a single wxSize variable is slightly simpler and shorter than
using 2 ints.

No real changes.
This commit is contained in:
Vadim Zeitlin
2018-10-30 22:01:32 +01:00
parent c374eefd34
commit 26c6db4b90
2 changed files with 12 additions and 14 deletions

View File

@@ -21,7 +21,7 @@ class WXDLLIMPEXP_FWD_CORE wxColour;
class WXDLLIMPEXP_CORE wxGenericImageList: public wxObject class WXDLLIMPEXP_CORE wxGenericImageList: public wxObject
{ {
public: public:
wxGenericImageList() { m_width = m_height = 0; } wxGenericImageList() { }
wxGenericImageList( int width, int height, bool mask = true, int initialCount = 1 ); wxGenericImageList( int width, int height, bool mask = true, int initialCount = 1 );
virtual ~wxGenericImageList(); virtual ~wxGenericImageList();
bool Create( int width, int height, bool mask = true, int initialCount = 1 ); bool Create( int width, int height, bool mask = true, int initialCount = 1 );
@@ -29,7 +29,7 @@ public:
virtual int GetImageCount() const; virtual int GetImageCount() const;
virtual bool GetSize( int index, int &width, int &height ) const; virtual bool GetSize( int index, int &width, int &height ) const;
virtual wxSize GetSize() const { return wxSize(m_width, m_height); } virtual wxSize GetSize() const { return m_size; }
int Add( const wxBitmap& bitmap ); int Add( const wxBitmap& bitmap );
int Add( const wxBitmap& bitmap, const wxBitmap& mask ); int Add( const wxBitmap& bitmap, const wxBitmap& mask );
@@ -50,8 +50,8 @@ public:
private: private:
wxObjectList m_images; wxObjectList m_images;
int m_width; // Size of a single bitmap in the list.
int m_height; wxSize m_size;
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxGenericImageList); wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxGenericImageList);
}; };

View File

@@ -47,8 +47,7 @@ int wxGenericImageList::GetImageCount() const
bool wxGenericImageList::Create( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) ) bool wxGenericImageList::Create( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) )
{ {
m_width = width; m_size = wxSize(width, height);
m_height = height;
return Create(); return Create();
} }
@@ -60,8 +59,8 @@ bool wxGenericImageList::Create()
int wxGenericImageList::Add( const wxBitmap &bitmap ) int wxGenericImageList::Add( const wxBitmap &bitmap )
{ {
wxASSERT_MSG( (bitmap.GetScaledWidth() >= m_width && bitmap.GetScaledHeight() == m_height) wxASSERT_MSG( (bitmap.GetScaledWidth() >= m_size.x && bitmap.GetScaledHeight() == m_size.y)
|| (m_width == 0 && m_height == 0), || m_size == wxSize(0, 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.") );
@@ -73,12 +72,12 @@ int wxGenericImageList::Add( const wxBitmap &bitmap )
{ {
// 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.GetScaledWidth() > m_width && bitmap.GetScaledHeight() >= m_height) if (m_size.x > 0 && bitmap.GetScaledWidth() > m_size.x && bitmap.GetScaledHeight() >= m_size.y)
{ {
int numImages = bitmap.GetScaledWidth() / m_width; int numImages = bitmap.GetScaledWidth() / m_size.x;
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_size.x * subIndex, 0, m_size.x, m_size.y);
wxBitmap tmpBmp = bitmap.GetSubBitmap(rect); wxBitmap tmpBmp = bitmap.GetSubBitmap(rect);
m_images.Append( new wxBitmap(tmpBmp) ); m_images.Append( new wxBitmap(tmpBmp) );
} }
@@ -89,10 +88,9 @@ int wxGenericImageList::Add( const wxBitmap &bitmap )
} }
} }
if (m_width == 0 && m_height == 0) if ( m_size == wxSize(0, 0) )
{ {
m_width = bitmap.GetScaledWidth(); m_size = bitmap.GetScaledSize();
m_height = bitmap.GetScaledHeight();
} }
return m_images.GetCount() - 1; return m_images.GetCount() - 1;