From 6d356423e22d1ea263cf80c45e12fb07302f0801 Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 3 Mar 2017 13:01:24 +0000 Subject: [PATCH] Fix for transformed Components not being centred correctly --- .../juce_gui_basics/components/juce_Component.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index 52bcaf1582..8bb0df2339 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -434,9 +434,9 @@ struct Component::ComponentHelpers static Rectangle getParentOrMainMonitorBounds (const Component& comp) { if (Component* p = comp.getParentComponent()) - return p->getLocalBounds(); + return comp.getLocalArea (p, p->getLocalBounds()); - return Desktop::getInstance().getDisplays().getMainDisplay().userArea; + return convertFromParentSpace (comp, Desktop::getInstance().getDisplays().getMainDisplay().userArea); } static void releaseAllCachedImageResources (Component& c) @@ -1250,8 +1250,10 @@ void Component::setBounds (const String& newBoundsExpression) void Component::setBoundsRelative (const float x, const float y, const float w, const float h) { - const int pw = getParentWidth(); - const int ph = getParentHeight(); + const Rectangle parentArea (ComponentHelpers::getParentOrMainMonitorBounds (*this)); + + const int pw = parentArea.getWidth(); + const int ph = parentArea.getHeight(); setBounds (roundToInt (x * pw), roundToInt (y * ph), @@ -1261,8 +1263,8 @@ void Component::setBoundsRelative (const float x, const float y, void Component::setCentrePosition (const int x, const int y) { - setTopLeftPosition (x - getWidth() / 2, - y - getHeight() / 2); + setTopLeftPosition (ComponentHelpers::convertFromParentSpace (*this, Point (x, y)) + .translated (getWidth() / -2, getHeight() / -2)); } void Component::setCentreRelative (const float x, const float y)