Browse Source

Scaling: Ensured that the Slider's PopupDisplayComponent will have the same transform applied as the Slider itself

tags/2021-05-28
hogliux 7 years ago
parent
commit
8377a6406b
2 changed files with 23 additions and 3 deletions
  1. +2
    -1
      modules/juce_gui_basics/misc/juce_BubbleComponent.cpp
  2. +21
    -2
      modules/juce_gui_basics/widgets/juce_Slider.cpp

+ 2
- 1
modules/juce_gui_basics/misc/juce_BubbleComponent.cpp View File

@@ -145,7 +145,8 @@ void BubbleComponent::setPosition (Rectangle<int> rectangleToPointTo,
} }
} }
setBounds (targetX - arrowTip.x, targetY - arrowTip.y, totalW, totalH);
auto origin = Point<int> (targetX - arrowTip.x, targetY - arrowTip.y).transformedBy (getTransform().inverted());
setBounds (origin.getX(), origin.getY(), totalW, totalH);
} }
} // namespace juce } // namespace juce

+ 21
- 2
modules/juce_gui_basics/widgets/juce_Slider.cpp View File

@@ -990,7 +990,7 @@ public:
if (popupDisplay == nullptr) if (popupDisplay == nullptr)
{ {
popupDisplay.reset (new PopupDisplayComponent (owner));
popupDisplay.reset (new PopupDisplayComponent (owner, parentForPopupDisplay == nullptr));
if (parentForPopupDisplay != nullptr) if (parentForPopupDisplay != nullptr)
parentForPopupDisplay->addChildComponent (popupDisplay.get()); parentForPopupDisplay->addChildComponent (popupDisplay.get());
@@ -1275,10 +1275,13 @@ public:
struct PopupDisplayComponent : public BubbleComponent, struct PopupDisplayComponent : public BubbleComponent,
public Timer public Timer
{ {
PopupDisplayComponent (Slider& s)
PopupDisplayComponent (Slider& s, bool isOnDesktop)
: owner (s), : owner (s),
font (s.getLookAndFeel().getSliderPopupFont (s)) font (s.getLookAndFeel().getSliderPopupFont (s))
{ {
if (isOnDesktop)
setTransform (AffineTransform::scale (getApproximateScaleFactor (&s)));
setAlwaysOnTop (true); setAlwaysOnTop (true);
setAllowedPlacement (owner.getLookAndFeel().getSliderPopupPlacement (s)); setAllowedPlacement (owner.getLookAndFeel().getSliderPopupPlacement (s));
setLookAndFeel (&s.getLookAndFeel()); setLookAndFeel (&s.getLookAndFeel());
@@ -1316,6 +1319,22 @@ 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;
String text; String text;


Loading…
Cancel
Save