From 55d033c68c7a406505cf22b2592ce43d2da2582e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 25 Oct 2019 00:30:42 +0200 Subject: [PATCH] Scale the bitmap in place in wxAuiScaleBitmap() This makes the function simpler and is slightly more efficient. No real changes. --- src/aui/dockart.cpp | 15 +++++++++------ src/aui/tabart.cpp | 11 ++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/aui/dockart.cpp b/src/aui/dockart.cpp index 7818b2b8aa..4ebf227714 100644 --- a/src/aui/dockart.cpp +++ b/src/aui/dockart.cpp @@ -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; diff --git a/src/aui/tabart.cpp b/src/aui/tabart.cpp index efb641342c..60e7939a7e 100644 --- a/src/aui/tabart.cpp +++ b/src/aui/tabart.cpp @@ -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;