From fc75497794fd6287d479eb92de49a037b5a016d5 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Thu, 10 Oct 2019 20:16:53 -0700 Subject: [PATCH 01/11] Update wxAuiGenericTabArt and wxAuiSimpleTabArt to properly handle scaled content. --- src/aui/tabart.cpp | 182 +++++++++++++++++++++++++-------------------- 1 file changed, 102 insertions(+), 80 deletions(-) diff --git a/src/aui/tabart.cpp b/src/aui/tabart.cpp index 3814d8dc31..4891388d43 100644 --- a/src/aui/tabart.cpp +++ b/src/aui/tabart.cpp @@ -96,7 +96,7 @@ static void DrawButtons(wxDC& dc, dc.SetPen(wxPen(bkcolour.ChangeLightness(75))); // draw the background behind the button - dc.DrawRectangle(rect.x, rect.y, 16-offset.x, 16-offset.y); + dc.DrawRectangle(rect.x, rect.y, bmp.GetWidth()-offset.x, bmp.GetHeight()-offset.y); } // draw the button itself @@ -221,7 +221,7 @@ void wxAuiGenericTabArt::SetSizingInfo(const wxSize& tab_ctrl_size, { m_fixedTabWidth = wxWindow::FromDIP(100, NULL); - int tot_width = (int)tab_ctrl_size.x - GetIndentSize() - 4; + int tot_width = (int)tab_ctrl_size.x - GetIndentSize() - wxWindow::FromDIP(4, NULL); if (m_flags & wxAUI_NB_CLOSE_BUTTON) tot_width -= m_activeCloseBmp.GetScaledWidth(); @@ -528,16 +528,10 @@ void wxAuiGenericTabArt::DrawTab(wxDC& dc, int text_offset; - int close_button_width = 0; - if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) - { - close_button_width = m_activeCloseBmp.GetScaledWidth(); - } - int bitmap_offset = 0; if (page.bitmap.IsOk()) { - bitmap_offset = tab_x + 8; + bitmap_offset = tab_x + wnd->FromDIP(8); // draw bitmap dc.DrawBitmap(page.bitmap, @@ -546,14 +540,49 @@ void wxAuiGenericTabArt::DrawTab(wxDC& dc, true); text_offset = bitmap_offset + page.bitmap.GetScaledWidth(); - text_offset += 3; // bitmap padding - + text_offset += wnd->FromDIP(3); // bitmap padding } else { - text_offset = tab_x + 8; + text_offset = tab_x + wnd->FromDIP(8); } + // draw close button if necessary + int close_button_width = 0; + if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) + { + wxBitmap bmp = m_disabledCloseBmp; + + if (close_button_state == wxAUI_BUTTON_STATE_HOVER || + close_button_state == wxAUI_BUTTON_STATE_PRESSED) + { + bmp = m_activeCloseBmp; + } + +#if wxUSE_IMAGE + if (wnd->FromDIP(1) > 1.0 && (bmp.GetWidth() == 16 || bmp.GetHeight() == 16)) + { + wxImage img = bmp.ConvertToImage(); + img.Rescale(wnd->FromDIP(16), wnd->FromDIP(16), wxIMAGE_QUALITY_BOX_AVERAGE); + bmp = img; + } +#endif // wxUSE_IMAGE + + int offsetY = tab_y-1; + if (m_flags & wxAUI_NB_BOTTOM) + offsetY = 1; + + wxRect rect(tab_x + tab_width - bmp.GetWidth() - wnd->FromDIP(1), + offsetY + (tab_height/2) - (bmp.GetHeight()/2), + bmp.GetWidth(), + tab_height); + + IndentPressedBitmap(wnd->FromDIP(wxSize(1, 1)), &rect, close_button_state); + dc.DrawBitmap(bmp, rect.x, rect.y, true); + + *out_button_rect = rect; + close_button_width = bmp.GetScaledWidth(); + } wxString draw_text = wxAuiChopText(dc, caption, @@ -599,32 +628,6 @@ void wxAuiGenericTabArt::DrawTab(wxDC& dc, wxRendererNative::Get().DrawFocusRect(wnd, dc, focusRect, 0); } - // draw close button if necessary - if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) - { - wxBitmap bmp = m_disabledCloseBmp; - - if (close_button_state == wxAUI_BUTTON_STATE_HOVER || - close_button_state == wxAUI_BUTTON_STATE_PRESSED) - { - bmp = m_activeCloseBmp; - } - - int offsetY = tab_y-1; - if (m_flags & wxAUI_NB_BOTTOM) - offsetY = 1; - - wxRect rect(tab_x + tab_width - close_button_width - 1, - offsetY + (tab_height/2) - (bmp.GetScaledHeight()/2), - close_button_width, - tab_height); - - IndentPressedBitmap(wnd->FromDIP(wxSize(1, 1)), &rect, close_button_state); - dc.DrawBitmap(bmp, rect.x, rect.y, true); - - *out_button_rect = rect; - } - *out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height); dc.DestroyClippingRegion(); @@ -673,14 +676,15 @@ wxSize wxAuiGenericTabArt::GetTabSize(wxDC& dc, // if the close button is showing, add space for it if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) - tab_width += m_activeCloseBmp.GetScaledWidth() + 3; + // increase by button size plus the padding + tab_width += wnd->FromDIP(16) + wnd->FromDIP(3); // if there's a bitmap, add space for it if (bitmap.IsOk()) { - tab_width += bitmap.GetScaledWidth(); - tab_width += 3; // right side bitmap padding - tab_height = wxMax(tab_height, bitmap.GetScaledHeight()); + // increase by bitmap plus right side bitmap padding + tab_width += bitmap.GetWidth() + wnd->FromDIP(3); + tab_height = wxMax(tab_height, bitmap.GetHeight()); } // add padding @@ -742,20 +746,29 @@ void wxAuiGenericTabArt::DrawButton(wxDC& dc, if (!bmp.IsOk()) return; +#if wxUSE_IMAGE + if (wnd->FromDIP(1) > 1.0 && (bmp.GetWidth() == 16 || bmp.GetHeight() == 16)) + { + wxImage img = bmp.ConvertToImage(); + img.Rescale(wnd->FromDIP(16), wnd->FromDIP(16), wxIMAGE_QUALITY_BOX_AVERAGE); + bmp = img; + } +#endif // wxUSE_IMAGE + rect = in_rect; if (orientation == wxLEFT) { rect.SetX(in_rect.x); - rect.SetY(((in_rect.y + in_rect.height)/2) - (bmp.GetScaledHeight()/2)); - rect.SetWidth(bmp.GetScaledWidth()); - rect.SetHeight(bmp.GetScaledHeight()); + rect.SetY(((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2)); + rect.SetWidth(bmp.GetWidth()); + rect.SetHeight(bmp.GetHeight()); } else { - rect = wxRect(in_rect.x + in_rect.width - bmp.GetScaledWidth(), - ((in_rect.y + in_rect.height)/2) - (bmp.GetScaledHeight()/2), - bmp.GetScaledWidth(), bmp.GetScaledHeight()); + rect = wxRect(in_rect.x + in_rect.width - bmp.GetWidth(), + ((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2), + bmp.GetWidth(), bmp.GetHeight()); } IndentPressedBitmap(wnd->FromDIP(wxSize(1, 1)), &rect, button_state); @@ -937,7 +950,7 @@ void wxAuiSimpleTabArt::SetSizingInfo(const wxSize& tab_ctrl_size, { m_fixedTabWidth = wxWindow::FromDIP(100, NULL); - int tot_width = (int)tab_ctrl_size.x - GetIndentSize() - 4; + int tot_width = (int)tab_ctrl_size.x - GetIndentSize() - wxWindow::FromDIP(4, NULL); if (m_flags & wxAUI_NB_CLOSE_BUTTON) tot_width -= m_activeCloseBmp.GetScaledWidth(); @@ -1093,20 +1106,38 @@ void wxAuiSimpleTabArt::DrawTab(wxDC& dc, //dc.DrawLines(active ? WXSIZEOF(points) - 1 : WXSIZEOF(points), points); dc.DrawLines(WXSIZEOF(points), points); - int text_offset; - int close_button_width = 0; + // draw close button if necessary if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { - close_button_width = m_activeCloseBmp.GetScaledWidth(); - text_offset = tab_x + (tab_height/2) + ((tab_width-close_button_width)/2) - (textx/2); - } - else - { - text_offset = tab_x + (tab_height/3) + (tab_width/2) - (textx/2); + wxBitmap bmp; + if (page.active) + bmp = m_activeCloseBmp; + else + bmp = m_disabledCloseBmp; + +#if wxUSE_IMAGE + if (wnd->FromDIP(1) > 1.0 && (bmp.GetWidth() == 16 || bmp.GetHeight() == 16)) + { + wxImage img = bmp.ConvertToImage(); + img.Rescale(wnd->FromDIP(16), wnd->FromDIP(16), wxIMAGE_QUALITY_BOX_AVERAGE); + bmp = img; + } +#endif // wxUSE_IMAGE + + wxRect rect(tab_x + tab_width - bmp.GetWidth() - 1, + tab_y + (tab_height/2) - (bmp.GetHeight()/2) + 1, + bmp.GetWidth(), + tab_height - 1); + DrawButtons(dc, wnd->FromDIP(wxSize(1, 1)), rect, bmp, *wxWHITE, close_button_state); + + *out_button_rect = rect; + close_button_width = bmp.GetWidth(); } + text_offset = tab_x + (tab_height/2) + ((tab_width-close_button_width)/2) - (textx/2); + // set minimum text offset if (text_offset < tab_x + tab_height) text_offset = tab_x + tab_height; @@ -1133,25 +1164,6 @@ void wxAuiSimpleTabArt::DrawTab(wxDC& dc, wxRendererNative::Get().DrawFocusRect(wnd, dc, focusRect, 0); } - // draw close button if necessary - if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) - { - wxBitmap bmp; - if (page.active) - bmp = m_activeCloseBmp; - else - bmp = m_disabledCloseBmp; - - wxRect rect(tab_x + tab_width - close_button_width - 1, - tab_y + (tab_height/2) - (bmp.GetScaledHeight()/2) + 1, - close_button_width, - tab_height - 1); - DrawButtons(dc, wnd->FromDIP(wxSize(1, 1)), rect, bmp, *wxWHITE, close_button_state); - - *out_button_rect = rect; - } - - *out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height); dc.DestroyClippingRegion(); @@ -1180,7 +1192,7 @@ int wxAuiSimpleTabArt::GetAdditionalBorderSpace(wxWindow* WXUNUSED(wnd)) } wxSize wxAuiSimpleTabArt::GetTabSize(wxDC& dc, - wxWindow* WXUNUSED(wnd), + wxWindow* wnd, const wxString& caption, const wxBitmap& WXUNUSED(bitmap), bool WXUNUSED(active), @@ -1192,11 +1204,12 @@ wxSize wxAuiSimpleTabArt::GetTabSize(wxDC& dc, dc.SetFont(m_measuringFont); dc.GetTextExtent(caption, &measured_textx, &measured_texty); - wxCoord tab_height = measured_texty + 4; - wxCoord tab_width = measured_textx + tab_height + 5; + wxCoord tab_height = measured_texty + wnd->FromDIP(4); + wxCoord tab_width = measured_textx + tab_height + wnd->FromDIP(5); if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) - tab_width += m_activeCloseBmp.GetScaledWidth(); + // increase by button size plus the padding + tab_width += wnd->FromDIP(16) + wnd->FromDIP(3); if (m_flags & wxAUI_NB_TAB_FIXED_WIDTH) { @@ -1251,6 +1264,15 @@ void wxAuiSimpleTabArt::DrawButton(wxDC& dc, if (!bmp.IsOk()) return; +#if wxUSE_IMAGE + if (wnd->FromDIP(1) > 1.0 && (bmp.GetWidth() == 16 || bmp.GetHeight() == 16)) + { + wxImage img = bmp.ConvertToImage(); + img.Rescale(wnd->FromDIP(16), wnd->FromDIP(16), wxIMAGE_QUALITY_BOX_AVERAGE); + bmp = img; + } +#endif // wxUSE_IMAGE + rect = in_rect; if (orientation == wxLEFT) From ab439fcdee3842951256b81ce126a9825246955c Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Fri, 11 Oct 2019 15:01:21 -0700 Subject: [PATCH 02/11] Updated to fix formatting style for multi-line `if`. --- src/aui/tabart.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/aui/tabart.cpp b/src/aui/tabart.cpp index 4891388d43..ac17452965 100644 --- a/src/aui/tabart.cpp +++ b/src/aui/tabart.cpp @@ -643,7 +643,7 @@ int wxAuiGenericTabArt::GetBorderWidth(wxWindow* wnd) wxAuiManager* mgr = wxAuiManager::GetManager(wnd); if (mgr) { - wxAuiDockArt* art = mgr->GetArtProvider(); + wxAuiDockArt* art = mgr->GetArtProvider(); if (art) return art->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE); } @@ -676,8 +676,10 @@ wxSize wxAuiGenericTabArt::GetTabSize(wxDC& dc, // if the close button is showing, add space for it if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) + { // increase by button size plus the padding tab_width += wnd->FromDIP(16) + wnd->FromDIP(3); + } // if there's a bitmap, add space for it if (bitmap.IsOk()) From 27dcd02dcf2037fa0105b5f66bc072034a3ed2c1 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Fri, 11 Oct 2019 15:02:24 -0700 Subject: [PATCH 03/11] Updated bitmap scaling in wxAui{Generic,Simple}TabArt for better results. --- src/aui/dockart.cpp | 17 +++++++++++++++++ src/aui/tabart.cpp | 46 ++++++++++----------------------------------- 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/src/aui/dockart.cpp b/src/aui/dockart.cpp index c5d04e1efd..46e4a5bbe4 100644 --- a/src/aui/dockart.cpp +++ b/src/aui/dockart.cpp @@ -55,6 +55,7 @@ #endif #endif +#include // -- wxAuiDefaultDockArt class implementation -- @@ -88,6 +89,22 @@ 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) +{ +#if wxUSE_IMAGE + // scale to a close round number to improve quality + scale = floor(scale + 0.25); + 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); + } +#endif // wxUSE_IMAGE + return bmp; +} static void DrawGradientRectangle(wxDC& dc, const wxRect& rect, diff --git a/src/aui/tabart.cpp b/src/aui/tabart.cpp index ac17452965..6987f4f284 100644 --- a/src/aui/tabart.cpp +++ b/src/aui/tabart.cpp @@ -72,6 +72,8 @@ private: wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h, const wxColour& color); +wxBitmap wxAuiScaleBitmap(const wxBitmap& bmp, double scale); + wxString wxAuiChopText(wxDC& dc, const wxString& text, int max_size); static void DrawButtons(wxDC& dc, @@ -224,9 +226,9 @@ void wxAuiGenericTabArt::SetSizingInfo(const wxSize& tab_ctrl_size, int tot_width = (int)tab_ctrl_size.x - GetIndentSize() - wxWindow::FromDIP(4, NULL); if (m_flags & wxAUI_NB_CLOSE_BUTTON) - tot_width -= m_activeCloseBmp.GetScaledWidth(); + tot_width -= m_activeCloseBmp.GetWidth(); if (m_flags & wxAUI_NB_WINDOWLIST_BUTTON) - tot_width -= m_activeWindowListBmp.GetScaledWidth(); + tot_width -= m_activeWindowListBmp.GetWidth(); if (tab_count > 0) { @@ -559,14 +561,7 @@ void wxAuiGenericTabArt::DrawTab(wxDC& dc, bmp = m_activeCloseBmp; } -#if wxUSE_IMAGE - if (wnd->FromDIP(1) > 1.0 && (bmp.GetWidth() == 16 || bmp.GetHeight() == 16)) - { - wxImage img = bmp.ConvertToImage(); - img.Rescale(wnd->FromDIP(16), wnd->FromDIP(16), wxIMAGE_QUALITY_BOX_AVERAGE); - bmp = img; - } -#endif // wxUSE_IMAGE + bmp = wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor()); int offsetY = tab_y-1; if (m_flags & wxAUI_NB_BOTTOM) @@ -748,14 +743,7 @@ void wxAuiGenericTabArt::DrawButton(wxDC& dc, if (!bmp.IsOk()) return; -#if wxUSE_IMAGE - if (wnd->FromDIP(1) > 1.0 && (bmp.GetWidth() == 16 || bmp.GetHeight() == 16)) - { - wxImage img = bmp.ConvertToImage(); - img.Rescale(wnd->FromDIP(16), wnd->FromDIP(16), wxIMAGE_QUALITY_BOX_AVERAGE); - bmp = img; - } -#endif // wxUSE_IMAGE + bmp = wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor()); rect = in_rect; @@ -955,9 +943,9 @@ void wxAuiSimpleTabArt::SetSizingInfo(const wxSize& tab_ctrl_size, int tot_width = (int)tab_ctrl_size.x - GetIndentSize() - wxWindow::FromDIP(4, NULL); if (m_flags & wxAUI_NB_CLOSE_BUTTON) - tot_width -= m_activeCloseBmp.GetScaledWidth(); + tot_width -= m_activeCloseBmp.GetWidth(); if (m_flags & wxAUI_NB_WINDOWLIST_BUTTON) - tot_width -= m_activeWindowListBmp.GetScaledWidth(); + tot_width -= m_activeWindowListBmp.GetWidth(); if (tab_count > 0) { @@ -1119,14 +1107,7 @@ void wxAuiSimpleTabArt::DrawTab(wxDC& dc, else bmp = m_disabledCloseBmp; -#if wxUSE_IMAGE - if (wnd->FromDIP(1) > 1.0 && (bmp.GetWidth() == 16 || bmp.GetHeight() == 16)) - { - wxImage img = bmp.ConvertToImage(); - img.Rescale(wnd->FromDIP(16), wnd->FromDIP(16), wxIMAGE_QUALITY_BOX_AVERAGE); - bmp = img; - } -#endif // wxUSE_IMAGE + bmp = wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor()); wxRect rect(tab_x + tab_width - bmp.GetWidth() - 1, tab_y + (tab_height/2) - (bmp.GetHeight()/2) + 1, @@ -1266,14 +1247,7 @@ void wxAuiSimpleTabArt::DrawButton(wxDC& dc, if (!bmp.IsOk()) return; -#if wxUSE_IMAGE - if (wnd->FromDIP(1) > 1.0 && (bmp.GetWidth() == 16 || bmp.GetHeight() == 16)) - { - wxImage img = bmp.ConvertToImage(); - img.Rescale(wnd->FromDIP(16), wnd->FromDIP(16), wxIMAGE_QUALITY_BOX_AVERAGE); - bmp = img; - } -#endif // wxUSE_IMAGE + bmp = wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor()); rect = in_rect; From dbc659f5b2f322212255ce1d8d811731da080f5f Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Fri, 11 Oct 2019 22:32:49 -0700 Subject: [PATCH 04/11] Disabled scaling for wxAui*TabArt on Mac/GTK3. --- src/aui/dockart.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aui/dockart.cpp b/src/aui/dockart.cpp index 46e4a5bbe4..2d4c3b5819 100644 --- a/src/aui/dockart.cpp +++ b/src/aui/dockart.cpp @@ -92,7 +92,7 @@ wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h, // wxAuiScaleBitmap is a utility function that scales a TabArt bitmap wxBitmap wxAuiScaleBitmap(const wxBitmap& bmp, double scale) { -#if wxUSE_IMAGE +#if wxUSE_IMAGE && !defined(__WXGTK3__) && !defined(__WXMAC__) // scale to a close round number to improve quality scale = floor(scale + 0.25); if (scale > 1.0 && !(bmp.GetScaleFactor() > 1.0)) From f55609b997152f6475ae5978823e8d7ae53f0fc1 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Sat, 12 Oct 2019 10:27:54 -0700 Subject: [PATCH 05/11] Move Mac/GTK3 check to avoid warning on unused variable. --- src/aui/dockart.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aui/dockart.cpp b/src/aui/dockart.cpp index 2d4c3b5819..9afb24c439 100644 --- a/src/aui/dockart.cpp +++ b/src/aui/dockart.cpp @@ -92,9 +92,9 @@ wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h, // wxAuiScaleBitmap is a utility function that scales a TabArt bitmap wxBitmap wxAuiScaleBitmap(const 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(); From af0ad629ca8c2735116ef7810902ac121018bf07 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Sat, 12 Oct 2019 10:31:12 -0700 Subject: [PATCH 06/11] Update to fix formatting style for multi-line `if`. --- src/aui/tabart.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/aui/tabart.cpp b/src/aui/tabart.cpp index 6987f4f284..a4ffea3806 100644 --- a/src/aui/tabart.cpp +++ b/src/aui/tabart.cpp @@ -1191,8 +1191,10 @@ wxSize wxAuiSimpleTabArt::GetTabSize(wxDC& dc, wxCoord tab_width = measured_textx + tab_height + wnd->FromDIP(5); if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) + { // increase by button size plus the padding tab_width += wnd->FromDIP(16) + wnd->FromDIP(3); + } if (m_flags & wxAUI_NB_TAB_FIXED_WIDTH) { From ba8cbf6027920e8656ef0f5dd680614360f34379 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Sat, 12 Oct 2019 10:34:57 -0700 Subject: [PATCH 07/11] Fix width for toolbar items with dropdown when scalefactor >1. --- src/aui/auibar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aui/auibar.cpp b/src/aui/auibar.cpp index 4f3a694382..3722a1b34f 100644 --- a/src/aui/auibar.cpp +++ b/src/aui/auibar.cpp @@ -634,7 +634,7 @@ wxSize wxAuiGenericToolBarArt::GetToolSize( // and add some extra space in front of the drop down button if (item.HasDropDown()) { - int dropdownWidth = wnd->FromDIP(GetElementSize(wxAUI_TBART_DROPDOWN_SIZE)); + int dropdownWidth = GetElementSize(wxAUI_TBART_DROPDOWN_SIZE); width += dropdownWidth + wnd->FromDIP(4); } From e4111c521e6880f81d8faf40357ed18f8b76b99a Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Tue, 15 Oct 2019 22:20:29 -0700 Subject: [PATCH 08/11] Update to use `GetScaled*` methods in auiTabArt calculations. --- src/aui/tabart.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/aui/tabart.cpp b/src/aui/tabart.cpp index a4ffea3806..1f81485b5e 100644 --- a/src/aui/tabart.cpp +++ b/src/aui/tabart.cpp @@ -98,7 +98,7 @@ static void DrawButtons(wxDC& dc, dc.SetPen(wxPen(bkcolour.ChangeLightness(75))); // draw the background behind the button - dc.DrawRectangle(rect.x, rect.y, bmp.GetWidth()-offset.x, bmp.GetHeight()-offset.y); + dc.DrawRectangle(rect.x, rect.y, bmp.GetScaledWidth()-offset.x, bmp.GetScaledHeight()-offset.y); } // draw the button itself @@ -226,9 +226,9 @@ void wxAuiGenericTabArt::SetSizingInfo(const wxSize& tab_ctrl_size, int tot_width = (int)tab_ctrl_size.x - GetIndentSize() - wxWindow::FromDIP(4, NULL); if (m_flags & wxAUI_NB_CLOSE_BUTTON) - tot_width -= m_activeCloseBmp.GetWidth(); + tot_width -= m_activeCloseBmp.GetScaledWidth(); if (m_flags & wxAUI_NB_WINDOWLIST_BUTTON) - tot_width -= m_activeWindowListBmp.GetWidth(); + tot_width -= m_activeWindowListBmp.GetScaledWidth(); if (tab_count > 0) { @@ -567,9 +567,9 @@ void wxAuiGenericTabArt::DrawTab(wxDC& dc, if (m_flags & wxAUI_NB_BOTTOM) offsetY = 1; - wxRect rect(tab_x + tab_width - bmp.GetWidth() - wnd->FromDIP(1), - offsetY + (tab_height/2) - (bmp.GetHeight()/2), - bmp.GetWidth(), + wxRect rect(tab_x + tab_width - bmp.GetScaledWidth() - wnd->FromDIP(1), + offsetY + (tab_height/2) - (bmp.GetScaledHeight()/2), + bmp.GetScaledWidth(), tab_height); IndentPressedBitmap(wnd->FromDIP(wxSize(1, 1)), &rect, close_button_state); @@ -673,15 +673,15 @@ wxSize wxAuiGenericTabArt::GetTabSize(wxDC& dc, if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { // increase by button size plus the padding - tab_width += wnd->FromDIP(16) + wnd->FromDIP(3); + tab_width += m_activeCloseBmp.GetScaledWidth() + wnd->FromDIP(3); } // if there's a bitmap, add space for it if (bitmap.IsOk()) { // increase by bitmap plus right side bitmap padding - tab_width += bitmap.GetWidth() + wnd->FromDIP(3); - tab_height = wxMax(tab_height, bitmap.GetHeight()); + tab_width += bitmap.GetScaledWidth() + wnd->FromDIP(3); + tab_height = wxMax(tab_height, bitmap.GetScaledHeight()); } // add padding @@ -750,15 +750,15 @@ void wxAuiGenericTabArt::DrawButton(wxDC& dc, if (orientation == wxLEFT) { rect.SetX(in_rect.x); - rect.SetY(((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2)); - rect.SetWidth(bmp.GetWidth()); - rect.SetHeight(bmp.GetHeight()); + rect.SetY(((in_rect.y + in_rect.height)/2) - (bmp.GetScaledHeight()/2)); + rect.SetWidth(bmp.GetScaledWidth()); + rect.SetHeight(bmp.GetScaledHeight()); } else { - rect = wxRect(in_rect.x + in_rect.width - bmp.GetWidth(), - ((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2), - bmp.GetWidth(), bmp.GetHeight()); + rect = wxRect(in_rect.x + in_rect.width - bmp.GetScaledWidth(), + ((in_rect.y + in_rect.height)/2) - (bmp.GetScaledHeight()/2), + bmp.GetScaledWidth(), bmp.GetScaledHeight()); } IndentPressedBitmap(wnd->FromDIP(wxSize(1, 1)), &rect, button_state); @@ -943,9 +943,9 @@ void wxAuiSimpleTabArt::SetSizingInfo(const wxSize& tab_ctrl_size, int tot_width = (int)tab_ctrl_size.x - GetIndentSize() - wxWindow::FromDIP(4, NULL); if (m_flags & wxAUI_NB_CLOSE_BUTTON) - tot_width -= m_activeCloseBmp.GetWidth(); + tot_width -= m_activeCloseBmp.GetScaledWidth(); if (m_flags & wxAUI_NB_WINDOWLIST_BUTTON) - tot_width -= m_activeWindowListBmp.GetWidth(); + tot_width -= m_activeWindowListBmp.GetScaledWidth(); if (tab_count > 0) { @@ -1109,14 +1109,14 @@ void wxAuiSimpleTabArt::DrawTab(wxDC& dc, bmp = wxAuiScaleBitmap(bmp, wnd->GetContentScaleFactor()); - wxRect rect(tab_x + tab_width - bmp.GetWidth() - 1, - tab_y + (tab_height/2) - (bmp.GetHeight()/2) + 1, - bmp.GetWidth(), + wxRect rect(tab_x + tab_width - bmp.GetScaledWidth() - 1, + tab_y + (tab_height/2) - (bmp.GetScaledHeight()/2) + 1, + bmp.GetScaledWidth(), tab_height - 1); DrawButtons(dc, wnd->FromDIP(wxSize(1, 1)), rect, bmp, *wxWHITE, close_button_state); *out_button_rect = rect; - close_button_width = bmp.GetWidth(); + close_button_width = bmp.GetScaledWidth(); } text_offset = tab_x + (tab_height/2) + ((tab_width-close_button_width)/2) - (textx/2); @@ -1193,7 +1193,7 @@ wxSize wxAuiSimpleTabArt::GetTabSize(wxDC& dc, if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { // increase by button size plus the padding - tab_width += wnd->FromDIP(16) + wnd->FromDIP(3); + tab_width += m_activeCloseBmp.GetScaledWidth() + wnd->FromDIP(3); } if (m_flags & wxAUI_NB_TAB_FIXED_WIDTH) From 571fda28cf2186d93143d5d0ec19fd95e495586a Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Wed, 23 Oct 2019 20:10:45 -0700 Subject: [PATCH 09/11] Add scaling of dock art as required by scaling. --- src/aui/dockart.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/aui/dockart.cpp b/src/aui/dockart.cpp index 9afb24c439..7818b2b8aa 100644 --- a/src/aui/dockart.cpp +++ b/src/aui/dockart.cpp @@ -765,6 +765,7 @@ void wxAuiDefaultDockArt::DrawPaneButton(wxDC& dc, break; } + bmp = wxAuiScaleBitmap(bmp, window->GetContentScaleFactor()); wxRect rect = _rect; @@ -791,10 +792,11 @@ void wxAuiDefaultDockArt::DrawPaneButton(wxDC& dc, } // draw the background behind the button - dc.DrawRectangle(rect.x, rect.y, 16-window->FromDIP(1), 16-window->FromDIP(1)); + dc.DrawRectangle(rect.x, rect.y, + bmp.GetScaledWidth() - window->FromDIP(1), + bmp.GetScaledHeight() - window->FromDIP(1)); } - // draw the button itself dc.DrawBitmap(bmp, rect.x, rect.y, true); } From 82f5c84a06d2924c695221186fdfb37d0136a2b3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 25 Oct 2019 00:27:29 +0200 Subject: [PATCH 10/11] Remove trivial differences with master No real changes. --- src/aui/tabart.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/aui/tabart.cpp b/src/aui/tabart.cpp index 1f81485b5e..efb641342c 100644 --- a/src/aui/tabart.cpp +++ b/src/aui/tabart.cpp @@ -1096,8 +1096,11 @@ void wxAuiSimpleTabArt::DrawTab(wxDC& dc, //dc.DrawLines(active ? WXSIZEOF(points) - 1 : WXSIZEOF(points), points); dc.DrawLines(WXSIZEOF(points), points); + int text_offset; + int close_button_width = 0; + // draw close button if necessary if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { From 55d033c68c7a406505cf22b2592ce43d2da2582e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 25 Oct 2019 00:30:42 +0200 Subject: [PATCH 11/11] 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;