mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
DRY-ed some code by adding a static Component::getApproximateScaleFactorForComponent() method
This commit is contained in:
parent
717be11eac
commit
2539f4d24f
4 changed files with 22 additions and 33 deletions
|
|
@ -1288,6 +1288,21 @@ AffineTransform Component::getTransform() const
|
|||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -590,6 +590,11 @@ public:
|
|||
*/
|
||||
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.
|
||||
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 (auto* targetComponent = options.getTargetComponent())
|
||||
scaleFactor = getApproximateScaleFactorForTargetComponent (targetComponent);
|
||||
scaleFactor = Component::getApproximateScaleFactorForComponent (targetComponent);
|
||||
|
||||
setOpaque (lf.findColour (PopupMenu::backgroundColourId).isOpaque()
|
||||
|| ! Desktop::canUseSemiTransparentWindows());
|
||||
|
|
@ -969,22 +969,6 @@ struct MenuWindow : public Component
|
|||
bool isTopScrollZoneActive() const noexcept { return canScroll() && childYOffset > 0; }
|
||||
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;
|
||||
const Options options;
|
||||
|
|
|
|||
|
|
@ -1298,7 +1298,7 @@ public:
|
|||
font (s.getLookAndFeel().getSliderPopupFont (s))
|
||||
{
|
||||
if (isOnDesktop)
|
||||
setTransform (AffineTransform::scale (getApproximateScaleFactor (&s)));
|
||||
setTransform (AffineTransform::scale (Component::getApproximateScaleFactorForComponent (&s)));
|
||||
|
||||
setAlwaysOnTop (true);
|
||||
setAllowedPlacement (owner.getLookAndFeel().getSliderPopupPlacement (s));
|
||||
|
|
@ -1338,21 +1338,6 @@ public:
|
|||
}
|
||||
|
||||
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;
|
||||
Font font;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue