Scale the bitmap in place in wxAuiScaleBitmap()

This makes the function simpler and is slightly more efficient.

No real changes.
This commit is contained in:
Vadim Zeitlin
2019-10-25 00:30:42 +02:00
parent 82f5c84a06
commit 55d033c68c
2 changed files with 15 additions and 11 deletions

View File

@@ -89,21 +89,24 @@ wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h,
return wxBitmap(img);
}
// wxAuiScaleBitmap is a utility function that scales a TabArt bitmap
wxBitmap wxAuiScaleBitmap(const wxBitmap& bmp, double scale)
// A utility function to scales a bitmap in place for use at the given scale
// factor.
void wxAuiScaleBitmap(wxBitmap& bmp, double scale)
{
#if wxUSE_IMAGE && !defined(__WXGTK3__) && !defined(__WXMAC__)
// scale to a close round number to improve quality
scale = floor(scale + 0.25);
#if wxUSE_IMAGE && !defined(__WXGTK3__) && !defined(__WXMAC__)
if (scale > 1.0 && !(bmp.GetScaleFactor() > 1.0))
{
wxImage img = bmp.ConvertToImage();
img.Rescale(bmp.GetWidth()*scale, bmp.GetHeight()*scale,
wxIMAGE_QUALITY_BOX_AVERAGE);
return wxBitmap(img);
bmp = wxBitmap(img);
}
#else
wxUnusedVar(bmp);
wxUnusedVar(scale);
#endif // wxUSE_IMAGE
return bmp;
}
static void DrawGradientRectangle(wxDC& dc,
@@ -765,7 +768,7 @@ void wxAuiDefaultDockArt::DrawPaneButton(wxDC& dc,
break;
}
bmp = wxAuiScaleBitmap(bmp, window->GetContentScaleFactor());
wxAuiScaleBitmap(bmp, window->GetContentScaleFactor());
wxRect rect = _rect;

View File

@@ -72,7 +72,8 @@ private:
wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h,
const wxColour& color);
wxBitmap wxAuiScaleBitmap(const wxBitmap& bmp, double scale);
// This function is defined in dockart.cpp.
void wxAuiScaleBitmap(wxBitmap& bmp, double scale);
wxString wxAuiChopText(wxDC& dc, const wxString& text, int max_size);
@@ -561,7 +562,7 @@ void wxAuiGenericTabArt::DrawTab(wxDC& dc,
bmp = m_activeCloseBmp;
}
bmp = wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor());
wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor());
int offsetY = tab_y-1;
if (m_flags & wxAUI_NB_BOTTOM)
@@ -743,7 +744,7 @@ void wxAuiGenericTabArt::DrawButton(wxDC& dc,
if (!bmp.IsOk())
return;
bmp = wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor());
wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor());
rect = in_rect;
@@ -1110,7 +1111,7 @@ void wxAuiSimpleTabArt::DrawTab(wxDC& dc,
else
bmp = m_disabledCloseBmp;
bmp = wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor());
wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor());
wxRect rect(tab_x + tab_width - bmp.GetScaledWidth() - 1,
tab_y + (tab_height/2) - (bmp.GetScaledHeight()/2) + 1,
@@ -1252,7 +1253,7 @@ void wxAuiSimpleTabArt::DrawButton(wxDC& dc,
if (!bmp.IsOk())
return;
bmp = wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor());
wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor());
rect = in_rect;