diff --git a/src/base/axis.cpp b/src/base/axis.cpp index f47d030c..bbdad978 100644 --- a/src/base/axis.cpp +++ b/src/base/axis.cpp @@ -14,7 +14,6 @@ namespace Wisteria::GraphItems { //----------------------------------------- void Axis::AdjustLabelSizeIfUsingBackgroundColor(Label& axisLabel, - wxDC& dc, const bool useMaxWidth) const { if (GetFontBackgroundColor().IsOk() && @@ -26,7 +25,7 @@ namespace Wisteria::GraphItems if (useMaxWidth) { axisLabel.SetMinimumUserSizeDIPs( - dc.ToDIP(m_maxLabelWidth), std::nullopt); + DownscaleFromScreenAndCanvas(m_maxLabelWidth), std::nullopt); } axisLabel.SetPadding(std::max(4, GetTopPadding()), std::max(4, GetRightPadding()), @@ -36,8 +35,8 @@ namespace Wisteria::GraphItems { if (useMaxWidth) { - axisLabel.SetMinimumUserSizeDIPs( - std::nullopt, dc.ToDIP(m_maxLabelWidth)); + axisLabel.SetMinimumUserSizeDIPs(std::nullopt, + DownscaleFromScreenAndCanvas(m_maxLabelWidth)); } axisLabel.SetPadding(std::max(4, GetTopPadding()), std::max(4, GetRightPadding()), @@ -1956,9 +1955,9 @@ namespace Wisteria::GraphItems GetParallelLabelAlignment() == RelativeAlignment::FlushRight) && !(axisPtIter == GetAxisPoints().cend()-1 && GetParallelLabelAlignment() == RelativeAlignment::FlushLeft)) - { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, dc, true); } + { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, true); } else - { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, dc, false); } + { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, false); } if (GetAxisLabelOrientation() == AxisLabelOrientation::Perpendicular) { @@ -2224,9 +2223,9 @@ namespace Wisteria::GraphItems GetParallelLabelAlignment() == RelativeAlignment::FlushRight) && !(axisPtIter == GetAxisPoints().cend()-1 && GetParallelLabelAlignment() == RelativeAlignment::FlushLeft)) - { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, dc, true); } + { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, true); } else - { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, dc, false); } + { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, false); } if (GetAxisLabelOrientation() == AxisLabelOrientation::Parallel) { @@ -2694,7 +2693,7 @@ namespace Wisteria::GraphItems Font(GetFont()).DPIScaling(GetDPIScaleFactor()). Padding(GetTopPadding(), GetRightPadding(), GetBottomPadding(), GetLeftPadding()) ); - AdjustLabelSizeIfUsingBackgroundColor(axisLabel, dc, true); + AdjustLabelSizeIfUsingBackgroundColor(axisLabel, true); for (auto pos = GetAxisPoints().cbegin(); pos != GetAxisPoints().cend(); @@ -3158,9 +3157,9 @@ namespace Wisteria::GraphItems // with the standard padding if (!(axisPos == GetAxisPoints().cbegin() && GetParallelLabelAlignment() == RelativeAlignment::FlushRight)) - { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, dc, true); } + { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, true); } else - { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, dc, false); } + { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, false); } return std::make_pair(axisLabel, axisPos->GetValue()); } } @@ -3187,9 +3186,9 @@ namespace Wisteria::GraphItems // with the standard padding if (!(axisPos == GetAxisPoints().crbegin() && GetParallelLabelAlignment() == RelativeAlignment::FlushLeft)) - { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, dc, true); } + { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, true); } else - { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, dc, false); } + { AdjustLabelSizeIfUsingBackgroundColor(axisLabel, false); } return std::make_pair(axisLabel, axisPos->GetValue()); } } diff --git a/src/base/axis.h b/src/base/axis.h index 8f210591..38d93305 100644 --- a/src/base/axis.h +++ b/src/base/axis.h @@ -1829,7 +1829,7 @@ namespace Wisteria::GraphItems /// @brief If labels have a background color, then make their boxes wide enough /// to fill the entire place available to them. - void AdjustLabelSizeIfUsingBackgroundColor(Label& axisLabel, wxDC& dc, + void AdjustLabelSizeIfUsingBackgroundColor(Label& axisLabel, const bool useMaxWidth) const; /** @brief Retrieves the value along the axis from a physical diff --git a/src/base/canvas.cpp b/src/base/canvas.cpp index 662fdc47..e09b55f5 100644 --- a/src/base/canvas.cpp +++ b/src/base/canvas.cpp @@ -530,7 +530,8 @@ namespace Wisteria title.SetTextOrientation(Orientation::Vertical); title.SetAnchorPoint(wxPoint(leftMarginWidth, GetCanvasRect(dc).GetHeight())); title.SetAnchoring(Anchoring::TopLeftCorner); - title.SetMinimumUserSizeDIPs(std::nullopt, GetCanvasRectDIPs().GetHeight()); + title.SetMinimumUserSizeDIPs( + std::nullopt, safe_divide(GetCanvasRectDIPs().GetHeight(), GetScaling())); title.SetPageVerticalAlignment( (title.GetRelativeAlignment() == RelativeAlignment::Centered) ? PageVerticalAlignment::Centered : @@ -578,7 +579,8 @@ namespace Wisteria title.SetTextOrientation(Orientation::Vertical); title.SetAnchorPoint(wxPoint(position, GetCanvasRect(dc).GetHeight())); title.SetAnchoring(Anchoring::BottomLeftCorner); - title.SetMinimumUserSizeDIPs(std::nullopt, GetCanvasRectDIPs().GetHeight()); + title.SetMinimumUserSizeDIPs( + std::nullopt, safe_divide(GetCanvasRectDIPs().GetHeight(), GetScaling())); title.SetPageVerticalAlignment( (title.GetRelativeAlignment() == RelativeAlignment::Centered) ? PageVerticalAlignment::Centered : @@ -623,7 +625,8 @@ namespace Wisteria title.SetScaling(GetScaling()); title.SetAnchorPoint(wxPoint(0, topMarginHeight)); title.SetAnchoring(Anchoring::TopLeftCorner); - title.SetMinimumUserSizeDIPs(GetCanvasRectDIPs().GetWidth(), std::nullopt); + title.SetMinimumUserSizeDIPs( + safe_divide(GetCanvasRectDIPs().GetWidth(), GetScaling()), std::nullopt); title.SetPageHorizontalAlignment( (title.GetRelativeAlignment() == RelativeAlignment::Centered) ? PageHorizontalAlignment::Centered : @@ -668,7 +671,8 @@ namespace Wisteria title.SetScaling(GetScaling()); title.SetAnchorPoint(wxPoint(0, position)); title.SetAnchoring(Anchoring::BottomLeftCorner); - title.SetMinimumUserSizeDIPs(GetCanvasRectDIPs().GetWidth(), std::nullopt); + title.SetMinimumUserSizeDIPs( + safe_divide(GetCanvasRectDIPs().GetWidth(), GetScaling()), std::nullopt); title.SetPageHorizontalAlignment( (title.GetRelativeAlignment() == RelativeAlignment::Centered) ? PageHorizontalAlignment::Centered : diff --git a/src/base/label.cpp b/src/base/label.cpp index 562872a0..efd28c8c 100644 --- a/src/base/label.cpp +++ b/src/base/label.cpp @@ -102,7 +102,7 @@ namespace Wisteria::GraphItems } //------------------------------------------- - wxCoord Label::CalcPageVerticalOffset(const wxDC& dc) const + wxCoord Label::CalcPageVerticalOffset() const { return !GetMinimumUserHeightDIPs() ? 0 : // if no min height, then no offset needed @@ -120,7 +120,7 @@ namespace Wisteria::GraphItems } //------------------------------------------- - wxCoord Label::CalcPageHorizontalOffset(const wxDC& dc) const + wxCoord Label::CalcPageHorizontalOffset() const { return !GetMinimumUserWidthDIPs() ? 0 : // if no min width, then no offset needed @@ -236,7 +236,8 @@ namespace Wisteria::GraphItems } // used for page alignment - SetMinimumUserSizeDIPs(dc.ToDIP(rect.GetWidth()), dc.ToDIP(rect.GetHeight())); + SetMinimumUserSizeDIPs(DownscaleFromScreenAndCanvas(rect.GetWidth()), + DownscaleFromScreenAndCanvas(rect.GetHeight())); GetSize(dc, measuredWidth, measureHeight); SetCachedContentBoundingBox( @@ -244,8 +245,8 @@ namespace Wisteria::GraphItems // if there is a minimum height that is taller than the text, then center // the text vertically auto contentRect = GetCachedContentBoundingBox(); - contentRect.y += CalcPageVerticalOffset(dc); - contentRect.x += CalcPageHorizontalOffset(dc); + contentRect.y += CalcPageVerticalOffset(); + contentRect.x += CalcPageHorizontalOffset(); SetCachedContentBoundingBox(contentRect); wxRect clippedRect{ rect }; @@ -356,8 +357,8 @@ namespace Wisteria::GraphItems // if there is a minimum height that is taller than the text, then center // the text vertically auto contentRect = GetCachedContentBoundingBox(); - contentRect.y += CalcPageVerticalOffset(dc); - contentRect.x += CalcPageHorizontalOffset(dc); + contentRect.y += CalcPageVerticalOffset(); + contentRect.x += CalcPageHorizontalOffset(); SetCachedContentBoundingBox(contentRect); // wxRect will be 1x1 if created with empty dimensions, so reset that // if this label is empty @@ -1444,7 +1445,7 @@ namespace Wisteria::GraphItems // if drawing outline, then calculate that also in case the pen width is large ((GetPen().IsOk() && GetGraphItemInfo().IsShowingRightOutline()) ? ScaleToScreenAndCanvas(GetPen().GetWidth()) : 0); - const wxCoord leftOffset = CalcPageHorizontalOffset(dc) + + const wxCoord leftOffset = CalcPageHorizontalOffset() + ((GetPen().IsOk() && GetGraphItemInfo().IsShowingTopOutline()) ? ScaleToScreenAndCanvas(GetPen().GetWidth()) : 0); @@ -1647,11 +1648,11 @@ namespace Wisteria::GraphItems const wxCoord spaceBetweenLines = (GetLineCount()-1) * std::ceil(ScaleToScreenAndCanvas(GetLineSpacing())); - pt.y += CalcPageVerticalOffset(dc) + ScaleToScreenAndCanvas(GetTopPadding()) + + pt.y += CalcPageVerticalOffset() + ScaleToScreenAndCanvas(GetTopPadding()) + // if drawing outline, then calculate that also in case the pen width is large ((GetPen().IsOk() && GetGraphItemInfo().IsShowingTopOutline()) ? ScaleToScreenAndCanvas(GetPen().GetWidth()) : 0); - const wxCoord leftOffset = CalcPageHorizontalOffset(dc) + + const wxCoord leftOffset = CalcPageHorizontalOffset() + ((GetPen().IsOk() && GetGraphItemInfo().IsShowingLeftOutline()) ? ScaleToScreenAndCanvas(GetPen().GetWidth()) : 0); diff --git a/src/base/label.h b/src/base/label.h index 282e1d94..a12db868 100644 --- a/src/base/label.h +++ b/src/base/label.h @@ -434,11 +434,11 @@ namespace Wisteria::GraphItems /// @returns The offset from the top if user-defined minimum size is being used it is /// taller than the measured size. [[nodiscard]] - wxCoord CalcPageVerticalOffset(const wxDC& dc) const; + wxCoord CalcPageVerticalOffset() const; /// @returns The offset from the left if user-defined minimum size is being used it is /// wider than the measured size. [[nodiscard]] - wxCoord CalcPageHorizontalOffset(const wxDC& dc) const; + wxCoord CalcPageHorizontalOffset() const; double m_tiltAngle{ 0 }; double m_spacingBetweenLines{ 1 }; diff --git a/src/graphs/heatmap.cpp b/src/graphs/heatmap.cpp index 56a43cf8..ad384342 100644 --- a/src/graphs/heatmap.cpp +++ b/src/graphs/heatmap.cpp @@ -428,8 +428,8 @@ namespace Wisteria::Graphs .Pen(wxNullPen) .Padding(0, labelRightPadding, 0, 0) .LabelPageVerticalAlignment(PageVerticalAlignment::Centered)); - groupRowLabel->SetMinimumUserSizeDIPs(dc.ToDIP(groupLabelWidth), - dc.ToDIP(boxWidth)); + groupRowLabel->SetMinimumUserSizeDIPs(DownscaleFromScreenAndCanvas(groupLabelWidth), + DownscaleFromScreenAndCanvas(boxWidth)); AddObject(std::move(groupRowLabel)); }