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

View File

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