Improved retrieving bitmaps from wxArtProvider in propgrid sample.

Retrieve from wxArtProvider bitmaps of required size instead of rescaling them in the application.
This commit is contained in:
Artur Wieczorek
2015-08-08 22:21:25 +02:00
parent 2a882b2bb3
commit c5d6f9d103

View File

@@ -1175,35 +1175,6 @@ void FormMain::PopulateWithStandardItems ()
// -----------------------------------------------------------------------
// Helper procedure to rescale bitmaps
static void RescaleBitmap(const wxBitmap& srcBmp, wxBitmap& dstBmp)
{
// Source bitmap should rescaled to the size of target bitmap.
if ( srcBmp.GetSize() != dstBmp.GetSize() )
{
#if wxUSE_IMAGE
// Use high-quality wxImage scaling functions
wxImage img = srcBmp.ConvertToImage();
img.Rescale(dstBmp.GetWidth(), dstBmp.GetHeight(), wxIMAGE_QUALITY_HIGH);
dstBmp = wxBitmap(img);
#else
// Old method of scaling the image
double scaleX = (double)dstBmp.GetWidth() / (double)srcBmp.GetWidth();
double scaleY = (double)dstBmp.GetHeight() / (double)srcBmp.GetHeight();
dstBmp.UseAlpha(srcBmp.HasAlpha());
{
wxMemoryDC dc(dstBmp);
dc.SetUserScale(scaleX, scaleY);
dc.DrawBitmap(srcBmp, 0, 0);
}
#endif
}
else
{
dstBmp = srcBmp;
}
}
void FormMain::PopulateWithExamples ()
{
wxPropertyGridManager* pgman = m_pPropGridManager;
@@ -1587,21 +1558,12 @@ void FormMain::PopulateWithExamples ()
//
// Test adding variable height bitmaps in wxPGChoices
wxPGChoices bc;
wxBitmap smallBmp(16, 16);
wxBitmap bmp = wxArtProvider::GetBitmap(wxART_CDROM);
RescaleBitmap(bmp, smallBmp);
wxBitmap mediumBmp(32, 32);
bmp = wxArtProvider::GetBitmap(wxART_FLOPPY);
RescaleBitmap(bmp, mediumBmp);
wxBitmap largeBmp(64, 64);
bmp = wxArtProvider::GetBitmap(wxART_HARDDISK);
RescaleBitmap(bmp, largeBmp);
bc.Add(wxT("Wee"), smallBmp);
bc.Add(wxT("Not so wee"), mediumBmp);
bc.Add(wxT("Friggin' huge"), largeBmp);
bc.Add(wxT("Wee"),
wxArtProvider::GetBitmap(wxART_CDROM, wxART_OTHER, wxSize(16, 16)));
bc.Add(wxT("Not so wee"),
wxArtProvider::GetBitmap(wxART_FLOPPY, wxART_OTHER, wxSize(32, 32)));
bc.Add(wxT("Friggin' huge"),
wxArtProvider::GetBitmap(wxART_HARDDISK, wxART_OTHER, wxSize(64, 64)));
pg->Append( new wxEnumProperty(wxT("Variable Height Bitmaps"),
wxPG_LABEL,