Move duplicated code to rescale the bitmap to the shared function

This commit is contained in:
Artur Wieczorek 2020-04-10 20:45:34 +02:00
parent f95d6463d3
commit c4f5fd3581
4 changed files with 35 additions and 42 deletions

View File

@ -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,

View File

@ -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
{

View File

@ -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
{

View File

@ -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?