Extract custom wxBitmapBundleImpl in treectrl sample
No changes yet, just prepare for using this class in another function. This commit is best viewed with Git --color-moved option.
This commit is contained in:
parent
366d06847b
commit
188dc81d6e
1 changed files with 36 additions and 33 deletions
|
|
@ -955,6 +955,42 @@ MyTreeCtrl::MyTreeCtrl(wxWindow *parent, const wxWindowID id,
|
|||
AddTestItemsToTree(NUM_CHILDREN_PER_LEVEL, NUM_LEVELS);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
class FixedSizeImpl : public wxBitmapBundleImpl
|
||||
{
|
||||
public:
|
||||
FixedSizeImpl(const wxSize& sizeDef, const wxIcon& icon)
|
||||
: m_sizeDef(sizeDef),
|
||||
m_icon(icon)
|
||||
{
|
||||
}
|
||||
|
||||
wxSize GetDefaultSize() const override
|
||||
{
|
||||
return m_sizeDef;
|
||||
}
|
||||
|
||||
wxSize GetPreferredBitmapSizeAtScale(double scale) const override
|
||||
{
|
||||
return m_sizeDef*scale;
|
||||
}
|
||||
|
||||
wxBitmap GetBitmap(const wxSize& size) override
|
||||
{
|
||||
wxBitmap bmp(m_icon);
|
||||
if ( size != bmp.GetSize() )
|
||||
wxBitmap::Rescale(bmp, size);
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
private:
|
||||
const wxSize m_sizeDef;
|
||||
const wxIcon m_icon;
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
void MyTreeCtrl::CreateImages(int size)
|
||||
{
|
||||
if ( size == -1 )
|
||||
|
|
@ -994,39 +1030,6 @@ void MyTreeCtrl::CreateImages(int size)
|
|||
// DPI, to ensure they are of the desired size.
|
||||
wxVector<wxBitmapBundle> images;
|
||||
|
||||
class FixedSizeImpl : public wxBitmapBundleImpl
|
||||
{
|
||||
public:
|
||||
FixedSizeImpl(const wxSize& sizeDef, const wxIcon& icon)
|
||||
: m_sizeDef(sizeDef),
|
||||
m_icon(icon)
|
||||
{
|
||||
}
|
||||
|
||||
wxSize GetDefaultSize() const override
|
||||
{
|
||||
return m_sizeDef;
|
||||
}
|
||||
|
||||
wxSize GetPreferredBitmapSizeAtScale(double scale) const override
|
||||
{
|
||||
return m_sizeDef*scale;
|
||||
}
|
||||
|
||||
wxBitmap GetBitmap(const wxSize& size) override
|
||||
{
|
||||
wxBitmap bmp(m_icon);
|
||||
if ( size != bmp.GetSize() )
|
||||
wxBitmap::Rescale(bmp, size);
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
private:
|
||||
const wxSize m_sizeDef;
|
||||
const wxIcon m_icon;
|
||||
};
|
||||
|
||||
for ( size_t i = 0; i < WXSIZEOF(icons); i++ )
|
||||
{
|
||||
images.push_back(wxBitmapBundle::FromImpl(new FixedSizeImpl(iconSize, icons[i])));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue