diff --git a/include/wx/propgrid/propgrid.h b/include/wx/propgrid/propgrid.h index b7768fd2df..ee2b620fad 100644 --- a/include/wx/propgrid/propgrid.h +++ b/include/wx/propgrid/propgrid.h @@ -1235,6 +1235,9 @@ public: // Checks system screen design used for laying out various dialogs. static bool IsSmallScreen(); + // Returns rescaled bitmap + static wxBitmap RescaleBitmap(const wxBitmap& srcBmp, double scaleX, double scaleY); + // Returns rectangle that fully contains properties between and including // p1 and p2. Rectangle is in virtual scrolled window coordinates. wxRect GetPropertyRect( const wxPGProperty* p1, diff --git a/src/propgrid/editors.cpp b/src/propgrid/editors.cpp index 64eab238f9..d2b1097a73 100644 --- a/src/propgrid/editors.cpp +++ b/src/propgrid/editors.cpp @@ -2160,25 +2160,7 @@ void wxPGMultiButton::Add( const wxBitmap& bitmap, int itemid ) if ( bitmap.GetHeight() > hMax ) { double scale = (double)hMax / bitmap.GetHeight(); - int w = wxRound(bitmap.GetWidth()*scale); - int h = wxRound(bitmap.GetHeight()*scale); -#if wxUSE_IMAGE - // Here we use high-quality wxImage scaling functions available - wxImage img = bitmap.ConvertToImage(); - img.Rescale(w, h, wxIMAGE_QUALITY_HIGH); - scaledBmp = img; -#else // !wxUSE_IMAGE - scaledBmp.Create(w, h, bitmap.GetDepth()); -#if defined(__WXMSW__) || defined(__WXOSX__) - // wxBitmap::UseAlpha() is used only on wxMSW and wxOSX. - scaledBmp.UseAlpha(bitmap.HasAlpha()); -#endif // __WXMSW__ || __WXOSX__ - { - wxMemoryDC dc(scaledBmp); - dc.SetUserScale(scale, scale); - dc.DrawBitmap(bitmap, 0, 0); - } -#endif // wxUSE_IMAGE/!wxUSE_IMAGE + scaledBmp = wxPropertyGrid::RescaleBitmap(bitmap, scale, scale); } else { diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index f2c96bd1b7..556080c7ad 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -2162,30 +2162,8 @@ void wxPGProperty::SetValueImage( wxBitmap& bmp ) if ( imSz.y != maxSz.y ) { -#if wxUSE_IMAGE - // Here we use high-quality wxImage scaling functions available - wxImage img = bmp.ConvertToImage(); double scaleY = (double)maxSz.y / (double)imSz.y; - img.Rescale(wxRound(bmp.GetWidth()*scaleY), - wxRound(bmp.GetHeight()*scaleY), - wxIMAGE_QUALITY_HIGH); - wxBitmap* bmpNew = new wxBitmap(img); -#else // !wxUSE_IMAGE - // This is the old, deprecated method of scaling the image - wxBitmap* bmpNew = new wxBitmap(maxSz.x,maxSz.y,bmp.GetDepth()); -#if defined(__WXMSW__) || defined(__WXOSX__) - // wxBitmap::UseAlpha() is used only on wxMSW and wxOSX. - bmpNew->UseAlpha(bmp.HasAlpha()); -#endif // __WXMSW__ || __WXOSX__ - { - wxMemoryDC dc(*bmpNew); - double scaleY = (double)maxSz.y / (double)imSz.y; - dc.SetUserScale(scaleY, scaleY); - dc.DrawBitmap(bmp, 0, 0); - } -#endif // wxUSE_IMAGE/!wxUSE_IMAGE - - m_valueBitmap = bmpNew; + m_valueBitmap = new wxBitmap(wxPropertyGrid::RescaleBitmap(bmp, scaleY, scaleY)); } else { diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index b31b49d42d..cfd7f3d926 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -1838,6 +1838,36 @@ bool wxPropertyGrid::IsSmallScreen() // ----------------------------------------------------------------------- +// static +wxBitmap wxPropertyGrid::RescaleBitmap(const wxBitmap& srcBmp, + double scaleX, double scaleY) +{ + int w = wxRound(srcBmp.GetWidth()*scaleX); + int h = wxRound(srcBmp.GetHeight()*scaleY); + +#if wxUSE_IMAGE + // Here we use high-quality wxImage scaling functions available + wxImage img = srcBmp.ConvertToImage(); + img.Rescale(w, h, wxIMAGE_QUALITY_HIGH); + wxBitmap dstBmp(img); +#else // !wxUSE_IMAGE + wxBitmap dstBmp(w, h, srcBmp.GetDepth()); +#if defined(__WXMSW__) || defined(__WXOSX__) + // wxBitmap::UseAlpha() is used only on wxMSW and wxOSX. + dstBmp.UseAlpha(srcBmp.HasAlpha()); +#endif // __WXMSW__ || __WXOSX__ + { + wxMemoryDC dc(dstBmp); + dc.SetUserScale(scaleX, scaleY); + dc.DrawBitmap(srcBmp, 0, 0); + } +#endif // wxUSE_IMAGE/!wxUSE_IMAGE + + return dstBmp; +} + +// ----------------------------------------------------------------------- + wxPGProperty* wxPropertyGrid::DoGetItemAtY( int y ) const { // Outside?