1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-09 04:30:09 +00:00

Fix for transformed Components not being centred correctly

This commit is contained in:
ed 2017-03-03 13:01:24 +00:00
parent 182b0e4cb0
commit 6d356423e2

View file

@ -434,9 +434,9 @@ struct Component::ComponentHelpers
static Rectangle<int> getParentOrMainMonitorBounds (const Component& comp) static Rectangle<int> getParentOrMainMonitorBounds (const Component& comp)
{ {
if (Component* p = comp.getParentComponent()) 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) static void releaseAllCachedImageResources (Component& c)
@ -1250,8 +1250,10 @@ void Component::setBounds (const String& newBoundsExpression)
void Component::setBoundsRelative (const float x, const float y, void Component::setBoundsRelative (const float x, const float y,
const float w, const float h) const float w, const float h)
{ {
const int pw = getParentWidth(); const Rectangle<int> parentArea (ComponentHelpers::getParentOrMainMonitorBounds (*this));
const int ph = getParentHeight();
const int pw = parentArea.getWidth();
const int ph = parentArea.getHeight();
setBounds (roundToInt (x * pw), setBounds (roundToInt (x * pw),
roundToInt (y * ph), 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) void Component::setCentrePosition (const int x, const int y)
{ {
setTopLeftPosition (x - getWidth() / 2, setTopLeftPosition (ComponentHelpers::convertFromParentSpace (*this, Point<int> (x, y))
y - getHeight() / 2); .translated (getWidth() / -2, getHeight() / -2));
} }
void Component::setCentreRelative (const float x, const float y) void Component::setCentreRelative (const float x, const float y)