| @@ -1288,6 +1288,21 @@ AffineTransform Component::getTransform() const | |||||
| return affineTransform != nullptr ? *affineTransform : AffineTransform(); | return affineTransform != nullptr ? *affineTransform : AffineTransform(); | ||||
| } | } | ||||
| float Component::getApproximateScaleFactorForComponent (Component* targetComponent) | |||||
| { | |||||
| AffineTransform transform; | |||||
| for (auto* target = targetComponent; target != nullptr; target = target->getParentComponent()) | |||||
| { | |||||
| transform = transform.followedBy (target->getTransform()); | |||||
| if (target->isOnDesktop()) | |||||
| transform = transform.scaled (target->getDesktopScaleFactor()); | |||||
| } | |||||
| return (transform.getScaleFactor() / Desktop::getInstance().getGlobalScaleFactor()); | |||||
| } | |||||
| //============================================================================== | //============================================================================== | ||||
| bool Component::hitTest (int x, int y) | bool Component::hitTest (int x, int y) | ||||
| { | { | ||||
| @@ -590,6 +590,11 @@ public: | |||||
| */ | */ | ||||
| bool isTransformed() const noexcept; | bool isTransformed() const noexcept; | ||||
| /** Returns the approximate scale factor for a given component by traversing its parent hierarchy | |||||
| and applying each transform and finally scaling this by the global scale factor. | |||||
| */ | |||||
| static float JUCE_CALLTYPE getApproximateScaleFactorForComponent (Component* targetComponent); | |||||
| //============================================================================== | //============================================================================== | ||||
| /** Returns a proportion of the component's width. | /** Returns a proportion of the component's width. | ||||
| This is a handy equivalent of (getWidth() * proportion). | This is a handy equivalent of (getWidth() * proportion). | ||||
| @@ -218,7 +218,7 @@ struct MenuWindow : public Component | |||||
| if (parentComponent == nullptr && parentWindow == nullptr && lf.shouldPopupMenuScaleWithTargetComponent (options)) | if (parentComponent == nullptr && parentWindow == nullptr && lf.shouldPopupMenuScaleWithTargetComponent (options)) | ||||
| if (auto* targetComponent = options.getTargetComponent()) | if (auto* targetComponent = options.getTargetComponent()) | ||||
| scaleFactor = getApproximateScaleFactorForTargetComponent (targetComponent); | |||||
| scaleFactor = Component::getApproximateScaleFactorForComponent (targetComponent); | |||||
| setOpaque (lf.findColour (PopupMenu::backgroundColourId).isOpaque() | setOpaque (lf.findColour (PopupMenu::backgroundColourId).isOpaque() | ||||
| || ! Desktop::canUseSemiTransparentWindows()); | || ! Desktop::canUseSemiTransparentWindows()); | ||||
| @@ -969,22 +969,6 @@ struct MenuWindow : public Component | |||||
| bool isTopScrollZoneActive() const noexcept { return canScroll() && childYOffset > 0; } | bool isTopScrollZoneActive() const noexcept { return canScroll() && childYOffset > 0; } | ||||
| bool isBottomScrollZoneActive() const noexcept { return canScroll() && childYOffset < contentHeight - windowPos.getHeight(); } | bool isBottomScrollZoneActive() const noexcept { return canScroll() && childYOffset < contentHeight - windowPos.getHeight(); } | ||||
| //============================================================================== | |||||
| static float getApproximateScaleFactorForTargetComponent (Component* targetComponent) | |||||
| { | |||||
| AffineTransform transform; | |||||
| for (auto* target = targetComponent; target != nullptr; target = target->getParentComponent()) | |||||
| { | |||||
| transform = transform.followedBy (target->getTransform()); | |||||
| if (target->isOnDesktop()) | |||||
| transform = transform.scaled (target->getDesktopScaleFactor()); | |||||
| } | |||||
| return (transform.getScaleFactor() / Desktop::getInstance().getGlobalScaleFactor()); | |||||
| } | |||||
| //============================================================================== | //============================================================================== | ||||
| MenuWindow* parent; | MenuWindow* parent; | ||||
| const Options options; | const Options options; | ||||
| @@ -1298,7 +1298,7 @@ public: | |||||
| font (s.getLookAndFeel().getSliderPopupFont (s)) | font (s.getLookAndFeel().getSliderPopupFont (s)) | ||||
| { | { | ||||
| if (isOnDesktop) | if (isOnDesktop) | ||||
| setTransform (AffineTransform::scale (getApproximateScaleFactor (&s))); | |||||
| setTransform (AffineTransform::scale (Component::getApproximateScaleFactorForComponent (&s))); | |||||
| setAlwaysOnTop (true); | setAlwaysOnTop (true); | ||||
| setAllowedPlacement (owner.getLookAndFeel().getSliderPopupPlacement (s)); | setAllowedPlacement (owner.getLookAndFeel().getSliderPopupPlacement (s)); | ||||
| @@ -1338,21 +1338,6 @@ public: | |||||
| } | } | ||||
| private: | private: | ||||
| static float getApproximateScaleFactor (Component* targetComponent) | |||||
| { | |||||
| AffineTransform transform; | |||||
| for (Component* target = targetComponent; target != nullptr; target = target->getParentComponent()) | |||||
| { | |||||
| transform = transform.followedBy (target->getTransform()); | |||||
| if (target->isOnDesktop()) | |||||
| transform = transform.scaled (target->getDesktopScaleFactor()); | |||||
| } | |||||
| return (transform.getScaleFactor() / Desktop::getInstance().getGlobalScaleFactor()); | |||||
| } | |||||
| //============================================================================== | //============================================================================== | ||||
| Slider& owner; | Slider& owner; | ||||
| Font font; | Font font; | ||||