diff --git a/extras/audio plugins/wrapper/Standalone/juce_StandaloneFilterWindow.cpp b/extras/audio plugins/wrapper/Standalone/juce_StandaloneFilterWindow.cpp index cee09e2d08..3e37fadbcf 100644 --- a/extras/audio plugins/wrapper/Standalone/juce_StandaloneFilterWindow.cpp +++ b/extras/audio plugins/wrapper/Standalone/juce_StandaloneFilterWindow.cpp @@ -90,7 +90,7 @@ StandaloneFilterWindow::StandaloneFilterWindow (const String& title, const int y = globalSettings->getIntValue (T("windowY"), -100); if (x != -100 && y != -100) - setBoundsConstrained (x, y, getWidth(), getHeight()); + setBoundsConstrained (Rectangle (x, y, getWidth(), getHeight())); else centreWithSize (getWidth(), getHeight()); } diff --git a/extras/the jucer/src/model/paintelements/jucer_PaintElement.cpp b/extras/the jucer/src/model/paintelements/jucer_PaintElement.cpp index 60f077c339..4f87f1e9f4 100644 --- a/extras/the jucer/src/model/paintelements/jucer_PaintElement.cpp +++ b/extras/the jucer/src/model/paintelements/jucer_PaintElement.cpp @@ -336,7 +336,7 @@ void PaintElement::resizeEnd() { } -void PaintElement::checkBounds (int& x, int& y, int& w, int& h, +void PaintElement::checkBounds (Rectangle& bounds, const Rectangle& previousBounds, const Rectangle& limits, const bool isStretchingTop, @@ -349,7 +349,7 @@ void PaintElement::checkBounds (int& x, int& y, int& w, int& h, else setFixedAspectRatio (0.0); - ComponentBoundsConstrainer::checkBounds (x, y, w, h, previousBounds, limits, isStretchingTop, isStretchingLeft, isStretchingBottom, isStretchingRight); + ComponentBoundsConstrainer::checkBounds (bounds, previousBounds, limits, isStretchingTop, isStretchingLeft, isStretchingBottom, isStretchingRight); JucerDocument* document = getDocument(); @@ -358,6 +358,11 @@ void PaintElement::checkBounds (int& x, int& y, int& w, int& h, jassert (getParentComponent() != 0); const Rectangle area (((PaintRoutineEditor*) getParentComponent())->getComponentArea()); + int x = bounds.getX(); + int y = bounds.getY(); + int w = bounds.getWidth(); + int h = bounds.getHeight(); + x += borderThickness - area.getX(); y += borderThickness - area.getY(); w -= borderThickness * 2; @@ -382,19 +387,20 @@ void PaintElement::checkBounds (int& x, int& y, int& w, int& h, h = (bottom - y) + borderThickness * 2; x -= borderThickness - area.getX(); y -= borderThickness - area.getY(); + + bounds = Rectangle (x, y, w, h); } } -void PaintElement::applyBoundsToComponent (Component* component, int x, int y, int w, int h) +void PaintElement::applyBoundsToComponent (Component* component, const Rectangle& bounds) { - if (getBounds() != Rectangle (x, y, w, h)) + if (getBounds() != bounds) { getDocument()->getUndoManager().undoCurrentTransactionOnly(); jassert (dynamic_cast (getParentComponent()) != 0); - setCurrentBounds (Rectangle (x, y, w, h) - .expanded (-borderThickness, -borderThickness), + setCurrentBounds (bounds.expanded (-borderThickness, -borderThickness), ((PaintRoutineEditor*) getParentComponent())->getComponentArea(), true); } diff --git a/extras/the jucer/src/model/paintelements/jucer_PaintElement.h b/extras/the jucer/src/model/paintelements/jucer_PaintElement.h index aa0cd4f45a..b72fa2c366 100644 --- a/extras/the jucer/src/model/paintelements/jucer_PaintElement.h +++ b/extras/the jucer/src/model/paintelements/jucer_PaintElement.h @@ -102,7 +102,7 @@ protected: void resizeStart(); void resizeEnd(); - void checkBounds (int& x, int& y, int& w, int& h, + void checkBounds (Rectangle& bounds, const Rectangle& previousBounds, const Rectangle& limits, const bool isStretchingTop, @@ -110,7 +110,7 @@ protected: const bool isStretchingBottom, const bool isStretchingRight); - void applyBoundsToComponent (Component* component, int x, int y, int w, int h); + void applyBoundsToComponent (Component* component, const Rectangle& bounds); const Rectangle getCurrentAbsoluteBounds() const; void getCurrentAbsoluteBoundsDouble (double& x, double& y, double& w, double& h) const; diff --git a/extras/the jucer/src/ui/jucer_ComponentOverlayComponent.cpp b/extras/the jucer/src/ui/jucer_ComponentOverlayComponent.cpp index 925c713b99..f31ee0e150 100644 --- a/extras/the jucer/src/ui/jucer_ComponentOverlayComponent.cpp +++ b/extras/the jucer/src/ui/jucer_ComponentOverlayComponent.cpp @@ -179,7 +179,7 @@ void ComponentOverlayComponent::resizeEnd() layout.getDocument()->getUndoManager().beginNewTransaction(); } -void ComponentOverlayComponent::checkBounds (int& x, int& y, int& w, int& h, +void ComponentOverlayComponent::checkBounds (Rectangle& bounds, const Rectangle& previousBounds, const Rectangle& limits, const bool isStretchingTop, @@ -192,7 +192,7 @@ void ComponentOverlayComponent::checkBounds (int& x, int& y, int& w, int& h, else setFixedAspectRatio (0.0); - ComponentBoundsConstrainer::checkBounds (x, y, w, h, previousBounds, limits, isStretchingTop, isStretchingLeft, isStretchingBottom, isStretchingRight); + ComponentBoundsConstrainer::checkBounds (bounds, previousBounds, limits, isStretchingTop, isStretchingLeft, isStretchingBottom, isStretchingRight); if (layout.getDocument()->isSnapActive (true)) { @@ -204,6 +204,11 @@ void ComponentOverlayComponent::checkBounds (int& x, int& y, int& w, int& h, const int dx = parent->getX(); const int dy = parent->getY(); + int x = bounds.getX(); + int y = bounds.getY(); + int w = bounds.getWidth(); + int h = bounds.getHeight(); + x += borderThickness - dx; y += borderThickness - dy; w -= borderThickness * 2; @@ -228,27 +233,29 @@ void ComponentOverlayComponent::checkBounds (int& x, int& y, int& w, int& h, h = (bottom - y) + borderThickness * 2; x -= borderThickness - dx; y -= borderThickness - dy; + + bounds = Rectangle (x, y, w, h); } } } -void ComponentOverlayComponent::applyBoundsToComponent (Component* component, int x, int y, int w, int h) +void ComponentOverlayComponent::applyBoundsToComponent (Component* component, const Rectangle& bounds) { - if (component->getBounds() != Rectangle (x, y, w, h)) + if (component->getBounds() != bounds) { layout.getDocument()->getUndoManager().undoCurrentTransactionOnly(); - component->setBounds (x, y, w, h); + component->setBounds (bounds); Component* const parent = target->getParentComponent(); jassert (parent != 0); if (parent != 0) { - target->setBounds (x + borderThickness - parent->getX(), - y + borderThickness - parent->getY(), - w - borderThickness * 2, - h - borderThickness * 2); + target->setBounds (bounds.getX() + borderThickness - parent->getX(), + bounds.getY() + borderThickness - parent->getY(), + bounds.getWidth() - borderThickness * 2, + bounds.getHeight() - borderThickness * 2); } layout.updateStoredComponentPosition (target, true); diff --git a/extras/the jucer/src/ui/jucer_ComponentOverlayComponent.h b/extras/the jucer/src/ui/jucer_ComponentOverlayComponent.h index b658f9584e..f70c16b1ef 100644 --- a/extras/the jucer/src/ui/jucer_ComponentOverlayComponent.h +++ b/extras/the jucer/src/ui/jucer_ComponentOverlayComponent.h @@ -64,7 +64,7 @@ public: void updateBoundsToMatchTarget(); - void checkBounds (int& x, int& y, int& w, int& h, + void checkBounds (Rectangle& bounds, const Rectangle& previousBounds, const Rectangle& limits, const bool isStretchingTop, @@ -72,7 +72,7 @@ public: const bool isStretchingBottom, const bool isStretchingRight); - void applyBoundsToComponent (Component* component, int x, int y, int w, int h); + void applyBoundsToComponent (Component* component, const Rectangle& bounds); //============================================================================== Component* const target; diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index d6427648af..0b34b40ef8 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -60780,7 +60780,7 @@ double ComponentBoundsConstrainer::getFixedAspectRatio() const throw() } void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component, - int x, int y, int w, int h, + const Rectangle& targetBounds, const bool isStretchingTop, const bool isStretchingLeft, const bool isStretchingBottom, @@ -60788,57 +60788,47 @@ void ComponentBoundsConstrainer::setBoundsForComponent (Component* const compone { jassert (component != 0); - Rectangle limits; - Component* const p = component->getParentComponent(); + Rectangle limits, bounds (targetBounds); + BorderSize border; - if (p == 0) - limits = Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(); - else - limits.setSize (p->getWidth(), p->getHeight()); + Component* const parent = component->getParentComponent(); - if (component->isOnDesktop()) + if (parent == 0) { - ComponentPeer* const peer = component->getPeer(); - const BorderSize border (peer->getFrameSize()); - - x -= border.getLeft(); - y -= border.getTop(); - w += border.getLeftAndRight(); - h += border.getTopAndBottom(); - - checkBounds (x, y, w, h, - border.addedTo (component->getBounds()), limits, - isStretchingTop, isStretchingLeft, - isStretchingBottom, isStretchingRight); + ComponentPeer* peer = component->getPeer(); + if (peer != 0) + border = peer->getFrameSize(); - x += border.getLeft(); - y += border.getTop(); - w -= border.getLeftAndRight(); - h -= border.getTopAndBottom(); + limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentreX(), + bounds.getCentreY()); } else { - checkBounds (x, y, w, h, - component->getBounds(), limits, - isStretchingTop, isStretchingLeft, - isStretchingBottom, isStretchingRight); + limits.setSize (parent->getWidth(), parent->getHeight()); } - applyBoundsToComponent (component, x, y, w, h); + border.addTo (bounds); + + checkBounds (bounds, + border.addedTo (component->getBounds()), limits, + isStretchingTop, isStretchingLeft, + isStretchingBottom, isStretchingRight); + + border.subtractFrom (bounds); + + applyBoundsToComponent (component, bounds); } void ComponentBoundsConstrainer::checkComponentBounds (Component* component) { - setBoundsForComponent (component, - component->getX(), component->getY(), - component->getWidth(), component->getHeight(), + setBoundsForComponent (component, component->getBounds(), false, false, false, false); } void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component, - int x, int y, int w, int h) + const Rectangle& bounds) { - component->setBounds (x, y, w, h); + component->setBounds (bounds); } void ComponentBoundsConstrainer::resizeStart() @@ -60849,7 +60839,7 @@ void ComponentBoundsConstrainer::resizeEnd() { } -void ComponentBoundsConstrainer::checkBounds (int& x, int& y, int& w, int& h, +void ComponentBoundsConstrainer::checkBounds (Rectangle& bounds, const Rectangle& old, const Rectangle& limits, const bool isStretchingTop, @@ -60857,6 +60847,11 @@ void ComponentBoundsConstrainer::checkBounds (int& x, int& y, int& w, int& h, const bool isStretchingBottom, const bool isStretchingRight) { + int x = bounds.getX(); + int y = bounds.getY(); + int w = bounds.getWidth(); + int h = bounds.getHeight(); + // constrain the size if it's being stretched.. if (isStretchingLeft) { @@ -60997,7 +60992,7 @@ void ComponentBoundsConstrainer::checkBounds (int& x, int& y, int& w, int& h, } jassert (w >= 0 && h >= 0); - + bounds = Rectangle (x, y, w, h); } END_JUCE_NAMESPACE @@ -61775,7 +61770,7 @@ void ResizableBorderComponent::mouseDrag (const MouseEvent& e) if (constrainer != 0) constrainer->setBoundsForComponent (component, - x, y, w, h, + Rectangle (x, y, w, h), (mouseZone & zoneT) != 0, (mouseZone & zoneL) != 0, (mouseZone & zoneB) != 0, @@ -61945,7 +61940,7 @@ void ResizableCornerComponent::mouseDrag (const MouseEvent& e) int h = originalH + e.getDistanceFromDragStartY(); if (constrainer != 0) - constrainer->setBoundsForComponent (component, x, y, w, h, + constrainer->setBoundsForComponent (component, Rectangle (x, y, w, h), false, false, true, true); else component->setBounds (x, y, w, h); @@ -69884,7 +69879,7 @@ void ComponentDragger::dragComponent (Component* const componentToDrag, const Mo y += e.getDistanceFromDragStartY(); if (constrainer != 0) - constrainer->setBoundsForComponent (componentToDrag, x, y, w, h, + constrainer->setBoundsForComponent (componentToDrag, Rectangle (x, y, w, h), false, false, false, false); else componentToDrag->setBounds (x, y, w, h); @@ -77538,7 +77533,7 @@ void ResizableWindow::setResizeLimits (const int newMinimumWidth, defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight, newMaximumWidth, newMaximumHeight); - setBoundsConstrained (getX(), getY(), getWidth(), getHeight()); + setBoundsConstrained (getBounds()); } void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer) @@ -77561,12 +77556,12 @@ void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer } } -void ResizableWindow::setBoundsConstrained (int x, int y, int w, int h) +void ResizableWindow::setBoundsConstrained (const Rectangle& bounds) { if (constrainer != 0) - constrainer->setBoundsForComponent (this, x, y, w, h, false, false, false, false); + constrainer->setBoundsForComponent (this, bounds, false, false, false, false); else - setBounds (x, y, w, h); + setBounds (bounds); } void ResizableWindow::paint (Graphics& g) @@ -77721,18 +77716,7 @@ void ResizableWindow::parentSizeChanged() const String ResizableWindow::getWindowStateAsString() { updateLastPos(); - - String s; - - if (isFullScreen()) - s << "fs "; - - s << lastNonFullScreenPos.getX() << T(' ') - << lastNonFullScreenPos.getY() << T(' ') - << lastNonFullScreenPos.getWidth() << T(' ') - << lastNonFullScreenPos.getHeight(); - - return s; + return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString(); } bool ResizableWindow::restoreWindowStateFromString (const String& s) @@ -77743,47 +77727,46 @@ bool ResizableWindow::restoreWindowStateFromString (const String& s) tokens.trim(); const bool fs = tokens[0].startsWithIgnoreCase (T("fs")); - const int n = fs ? 1 : 0; + const int firstCoord = fs ? 1 : 0; - if (tokens.size() != 4 + n) + if (tokens.size() != firstCoord + 4) return false; - Rectangle r (tokens[n].getIntValue(), - tokens[n + 1].getIntValue(), - tokens[n + 2].getIntValue(), - tokens[n + 3].getIntValue()); + Rectangle newPos (tokens[firstCoord].getIntValue(), + tokens[firstCoord + 1].getIntValue(), + tokens[firstCoord + 2].getIntValue(), + tokens[firstCoord + 3].getIntValue()); - if (r.isEmpty()) + if (newPos.isEmpty()) return false; - const Rectangle screen (Desktop::getInstance().getMonitorAreaContaining (r.getX(), r.getY())); + const Rectangle screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentreX(), + newPos.getCentreY())); - if (! screen.contains (r)) + ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0; + if (peer != 0) + peer->getFrameSize().addTo (newPos); + + if (! screen.contains (newPos)) { - r.setSize (jmin (r.getWidth(), screen.getWidth()), - jmin (r.getHeight(), screen.getHeight())); + newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()), + jmin (newPos.getHeight(), screen.getHeight())); - r.setPosition (jlimit (screen.getX(), screen.getRight() - r.getWidth(), r.getX()), - jlimit (screen.getY(), screen.getBottom() - r.getHeight(), r.getY())); + newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()), + jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY())); } - lastNonFullScreenPos = r; - - if (isOnDesktop()) + if (peer != 0) { - ComponentPeer* const peer = getPeer(); - - if (peer != 0) - peer->setNonFullScreenBounds (r); + peer->getFrameSize().subtractFrom (newPos); + peer->setNonFullScreenBounds (newPos); } + lastNonFullScreenPos = newPos; setFullScreen (fs); if (! fs) - setBoundsConstrained (r.getX(), - r.getY(), - r.getWidth(), - r.getHeight()); + setBoundsConstrained (newPos); return true; } @@ -216197,13 +216180,18 @@ private: component->getWidth() + windowBorder.getLeftAndRight(), component->getHeight() + windowBorder.getTopAndBottom()); - constrainer->checkBounds (wp->x, wp->y, wp->cx, wp->cy, - current, + Rectangle pos (wp->x, wp->y, wp->cx, wp->cy); + + constrainer->checkBounds (pos, current, Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(), - wp->y != current.getY() && wp->y + wp->cy == current.getBottom(), - wp->x != current.getX() && wp->x + wp->cx == current.getRight(), - wp->y == current.getY() && wp->y + wp->cy != current.getBottom(), - wp->x == current.getX() && wp->x + wp->cx != current.getRight()); + pos.getY() != current.getY() && pos.getBottom() == current.getBottom(), + pos.getX() != current.getX() && pos.getRight() == current.getRight(), + pos.getY() == current.getY() && pos.getBottom() != current.getBottom(), + pos.getX() == current.getX() && pos.getRight() != current.getRight()); + wp->x = pos.getX(); + wp->y = pos.getY(); + wp->cx = pos.getWidth(); + wp->cy = pos.getHeight(); } } } @@ -241267,26 +241255,23 @@ CGRect UIViewComponentPeer::constrainRect (CGRect r) r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height; - int x = (int) r.origin.x; - int y = (int) r.origin.y; - int w = (int) r.size.width; - int h = (int) r.size.height; + Rectangle pos ((int) r.origin.x, (int) r.origin.y, + (int) r.size.width, (int) r.size.height); Rectangle original ((int) current.origin.x, (int) current.origin.y, (int) current.size.width, (int) current.size.height); - constrainer->checkBounds (x, y, w, h, - original, + constrainer->checkBounds (pos, original, Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(), - y != original.getY() && y + h == original.getBottom(), - x != original.getX() && x + w == original.getRight(), - y == original.getY() && y + h != original.getBottom(), - x == original.getX() && x + w != original.getRight()); + pos.getY() != original.getY() && pos.getBottom() == original.getBottom(), + pos.getX() != original.getX() && pos.getRight() == original.getRight(), + pos.getY() == original.getY() && pos.getBottom() != original.getBottom(), + pos.getX() == original.getX() && pos.getRight() != original.getRight()); - r.origin.x = x; - r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - y; - r.size.width = w; - r.size.height = h; + r.origin.x = pos.getX(); + r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY(); + r.size.width = pos.getWidth(); + r.size.height = pos.getHeight(); } return r; @@ -246061,26 +246046,23 @@ NSRect NSViewComponentPeer::constrainRect (NSRect r) r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height; - int x = (int) r.origin.x; - int y = (int) r.origin.y; - int w = (int) r.size.width; - int h = (int) r.size.height; + Rectangle pos ((int) r.origin.x, (int) r.origin.y, + (int) r.size.width, (int) r.size.height); Rectangle original ((int) current.origin.x, (int) current.origin.y, (int) current.size.width, (int) current.size.height); - constrainer->checkBounds (x, y, w, h, - original, + constrainer->checkBounds (pos, original, Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(), - y != original.getY() && y + h == original.getBottom(), - x != original.getX() && x + w == original.getRight(), - y == original.getY() && y + h != original.getBottom(), - x == original.getX() && x + w != original.getRight()); - - r.origin.x = x; - r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - y; - r.size.width = w; - r.size.height = h; + pos.getY() != original.getY() && pos.getBottom() == original.getBottom(), + pos.getX() != original.getX() && pos.getRight() == original.getRight(), + pos.getY() == original.getY() && pos.getBottom() != original.getBottom(), + pos.getX() == original.getX() && pos.getRight() != original.getRight()); + + r.origin.x = pos.getX(); + r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY(); + r.size.width = pos.getWidth(); + r.size.height = pos.getHeight(); } return r; diff --git a/juce_amalgamated.h b/juce_amalgamated.h index ffe59966fc..290aaf54db 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -22637,7 +22637,7 @@ public: double getFixedAspectRatio() const throw(); - virtual void checkBounds (int& x, int& y, int& w, int& h, + virtual void checkBounds (Rectangle& bounds, const Rectangle& previousBounds, const Rectangle& limits, const bool isStretchingTop, @@ -22650,7 +22650,7 @@ public: virtual void resizeEnd(); void setBoundsForComponent (Component* const component, - int x, int y, int w, int h, + const Rectangle& bounds, const bool isStretchingTop, const bool isStretchingLeft, const bool isStretchingBottom, @@ -22659,7 +22659,7 @@ public: void checkComponentBounds (Component* component); virtual void applyBoundsToComponent (Component* component, - int x, int y, int w, int h); + const Rectangle& bounds); juce_UseDebuggingNewOperator @@ -22811,7 +22811,7 @@ public: void setConstrainer (ComponentBoundsConstrainer* newConstrainer); - void setBoundsConstrained (int x, int y, int width, int height); + void setBoundsConstrained (const Rectangle& bounds); bool isFullScreen() const; diff --git a/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp b/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp index 98eb9e8985..03c02ea4ca 100644 --- a/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp +++ b/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp @@ -134,7 +134,7 @@ double ComponentBoundsConstrainer::getFixedAspectRatio() const throw() } void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component, - int x, int y, int w, int h, + const Rectangle& targetBounds, const bool isStretchingTop, const bool isStretchingLeft, const bool isStretchingBottom, @@ -142,57 +142,47 @@ void ComponentBoundsConstrainer::setBoundsForComponent (Component* const compone { jassert (component != 0); - Rectangle limits; - Component* const p = component->getParentComponent(); + Rectangle limits, bounds (targetBounds); + BorderSize border; - if (p == 0) - limits = Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(); - else - limits.setSize (p->getWidth(), p->getHeight()); + Component* const parent = component->getParentComponent(); - if (component->isOnDesktop()) + if (parent == 0) { - ComponentPeer* const peer = component->getPeer(); - const BorderSize border (peer->getFrameSize()); - - x -= border.getLeft(); - y -= border.getTop(); - w += border.getLeftAndRight(); - h += border.getTopAndBottom(); - - checkBounds (x, y, w, h, - border.addedTo (component->getBounds()), limits, - isStretchingTop, isStretchingLeft, - isStretchingBottom, isStretchingRight); - - x += border.getLeft(); - y += border.getTop(); - w -= border.getLeftAndRight(); - h -= border.getTopAndBottom(); + ComponentPeer* peer = component->getPeer(); + if (peer != 0) + border = peer->getFrameSize(); + + limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentreX(), + bounds.getCentreY()); } else { - checkBounds (x, y, w, h, - component->getBounds(), limits, - isStretchingTop, isStretchingLeft, - isStretchingBottom, isStretchingRight); + limits.setSize (parent->getWidth(), parent->getHeight()); } - applyBoundsToComponent (component, x, y, w, h); + border.addTo (bounds); + + checkBounds (bounds, + border.addedTo (component->getBounds()), limits, + isStretchingTop, isStretchingLeft, + isStretchingBottom, isStretchingRight); + + border.subtractFrom (bounds); + + applyBoundsToComponent (component, bounds); } void ComponentBoundsConstrainer::checkComponentBounds (Component* component) { - setBoundsForComponent (component, - component->getX(), component->getY(), - component->getWidth(), component->getHeight(), + setBoundsForComponent (component, component->getBounds(), false, false, false, false); } void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component, - int x, int y, int w, int h) + const Rectangle& bounds) { - component->setBounds (x, y, w, h); + component->setBounds (bounds); } //============================================================================== @@ -205,7 +195,7 @@ void ComponentBoundsConstrainer::resizeEnd() } //============================================================================== -void ComponentBoundsConstrainer::checkBounds (int& x, int& y, int& w, int& h, +void ComponentBoundsConstrainer::checkBounds (Rectangle& bounds, const Rectangle& old, const Rectangle& limits, const bool isStretchingTop, @@ -213,6 +203,11 @@ void ComponentBoundsConstrainer::checkBounds (int& x, int& y, int& w, int& h, const bool isStretchingBottom, const bool isStretchingRight) { + int x = bounds.getX(); + int y = bounds.getY(); + int w = bounds.getWidth(); + int h = bounds.getHeight(); + // constrain the size if it's being stretched.. if (isStretchingLeft) { @@ -353,7 +348,7 @@ void ComponentBoundsConstrainer::checkBounds (int& x, int& y, int& w, int& h, } jassert (w >= 0 && h >= 0); - + bounds = Rectangle (x, y, w, h); } diff --git a/src/gui/components/layout/juce_ComponentBoundsConstrainer.h b/src/gui/components/layout/juce_ComponentBoundsConstrainer.h index 89ea4d0881..b1a304bc65 100644 --- a/src/gui/components/layout/juce_ComponentBoundsConstrainer.h +++ b/src/gui/components/layout/juce_ComponentBoundsConstrainer.h @@ -133,18 +133,15 @@ public: /** This callback changes the given co-ordinates to impose whatever the current constraints are set to be. - @param x the x position that should be examined and adjusted - @param y the y position that should be examined and adjusted - @param w the width that should be examined and adjusted - @param h the height that should be examined and adjusted - @param previousBounds the component's current size - @param limits the region in which the component can be positioned + @param bounds the target position that should be examined and adjusted + @param previousBounds the component's current size + @param limits the region in which the component can be positioned @param isStretchingTop whether the top edge of the component is being resized @param isStretchingLeft whether the left edge of the component is being resized @param isStretchingBottom whether the bottom edge of the component is being resized @param isStretchingRight whether the right edge of the component is being resized */ - virtual void checkBounds (int& x, int& y, int& w, int& h, + virtual void checkBounds (Rectangle& bounds, const Rectangle& previousBounds, const Rectangle& limits, const bool isStretchingTop, @@ -160,7 +157,7 @@ public: /** Checks the given bounds, and then sets the component to the corrected size. */ void setBoundsForComponent (Component* const component, - int x, int y, int w, int h, + const Rectangle& bounds, const bool isStretchingTop, const bool isStretchingLeft, const bool isStretchingBottom, @@ -178,7 +175,7 @@ public: extremely cunning purposes. */ virtual void applyBoundsToComponent (Component* component, - int x, int y, int w, int h); + const Rectangle& bounds); //============================================================================== juce_UseDebuggingNewOperator diff --git a/src/gui/components/layout/juce_ResizableBorderComponent.cpp b/src/gui/components/layout/juce_ResizableBorderComponent.cpp index e1af1e85c6..de3d982e43 100644 --- a/src/gui/components/layout/juce_ResizableBorderComponent.cpp +++ b/src/gui/components/layout/juce_ResizableBorderComponent.cpp @@ -124,7 +124,7 @@ void ResizableBorderComponent::mouseDrag (const MouseEvent& e) if (constrainer != 0) constrainer->setBoundsForComponent (component, - x, y, w, h, + Rectangle (x, y, w, h), (mouseZone & zoneT) != 0, (mouseZone & zoneL) != 0, (mouseZone & zoneB) != 0, diff --git a/src/gui/components/layout/juce_ResizableCornerComponent.cpp b/src/gui/components/layout/juce_ResizableCornerComponent.cpp index b04e7d8846..d439a4f160 100644 --- a/src/gui/components/layout/juce_ResizableCornerComponent.cpp +++ b/src/gui/components/layout/juce_ResizableCornerComponent.cpp @@ -88,7 +88,7 @@ void ResizableCornerComponent::mouseDrag (const MouseEvent& e) int h = originalH + e.getDistanceFromDragStartY(); if (constrainer != 0) - constrainer->setBoundsForComponent (component, x, y, w, h, + constrainer->setBoundsForComponent (component, Rectangle (x, y, w, h), false, false, true, true); else component->setBounds (x, y, w, h); diff --git a/src/gui/components/mouse/juce_ComponentDragger.cpp b/src/gui/components/mouse/juce_ComponentDragger.cpp index deb1cb41ba..9e312a8e45 100644 --- a/src/gui/components/mouse/juce_ComponentDragger.cpp +++ b/src/gui/components/mouse/juce_ComponentDragger.cpp @@ -78,7 +78,7 @@ void ComponentDragger::dragComponent (Component* const componentToDrag, const Mo y += e.getDistanceFromDragStartY(); if (constrainer != 0) - constrainer->setBoundsForComponent (componentToDrag, x, y, w, h, + constrainer->setBoundsForComponent (componentToDrag, Rectangle (x, y, w, h), false, false, false, false); else componentToDrag->setBounds (x, y, w, h); diff --git a/src/gui/components/windows/juce_ResizableWindow.cpp b/src/gui/components/windows/juce_ResizableWindow.cpp index d29fb2b1e9..f8f88cadb7 100644 --- a/src/gui/components/windows/juce_ResizableWindow.cpp +++ b/src/gui/components/windows/juce_ResizableWindow.cpp @@ -265,7 +265,7 @@ void ResizableWindow::setResizeLimits (const int newMinimumWidth, defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight, newMaximumWidth, newMaximumHeight); - setBoundsConstrained (getX(), getY(), getWidth(), getHeight()); + setBoundsConstrained (getBounds()); } void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer) @@ -288,12 +288,12 @@ void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer } } -void ResizableWindow::setBoundsConstrained (int x, int y, int w, int h) +void ResizableWindow::setBoundsConstrained (const Rectangle& bounds) { if (constrainer != 0) - constrainer->setBoundsForComponent (this, x, y, w, h, false, false, false, false); + constrainer->setBoundsForComponent (this, bounds, false, false, false, false); else - setBounds (x, y, w, h); + setBounds (bounds); } //============================================================================== @@ -451,18 +451,7 @@ void ResizableWindow::parentSizeChanged() const String ResizableWindow::getWindowStateAsString() { updateLastPos(); - - String s; - - if (isFullScreen()) - s << "fs "; - - s << lastNonFullScreenPos.getX() << T(' ') - << lastNonFullScreenPos.getY() << T(' ') - << lastNonFullScreenPos.getWidth() << T(' ') - << lastNonFullScreenPos.getHeight(); - - return s; + return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString(); } bool ResizableWindow::restoreWindowStateFromString (const String& s) @@ -473,47 +462,46 @@ bool ResizableWindow::restoreWindowStateFromString (const String& s) tokens.trim(); const bool fs = tokens[0].startsWithIgnoreCase (T("fs")); - const int n = fs ? 1 : 0; + const int firstCoord = fs ? 1 : 0; - if (tokens.size() != 4 + n) + if (tokens.size() != firstCoord + 4) return false; - Rectangle r (tokens[n].getIntValue(), - tokens[n + 1].getIntValue(), - tokens[n + 2].getIntValue(), - tokens[n + 3].getIntValue()); + Rectangle newPos (tokens[firstCoord].getIntValue(), + tokens[firstCoord + 1].getIntValue(), + tokens[firstCoord + 2].getIntValue(), + tokens[firstCoord + 3].getIntValue()); - if (r.isEmpty()) + if (newPos.isEmpty()) return false; - const Rectangle screen (Desktop::getInstance().getMonitorAreaContaining (r.getX(), r.getY())); + const Rectangle screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentreX(), + newPos.getCentreY())); + + ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0; + if (peer != 0) + peer->getFrameSize().addTo (newPos); - if (! screen.contains (r)) + if (! screen.contains (newPos)) { - r.setSize (jmin (r.getWidth(), screen.getWidth()), - jmin (r.getHeight(), screen.getHeight())); + newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()), + jmin (newPos.getHeight(), screen.getHeight())); - r.setPosition (jlimit (screen.getX(), screen.getRight() - r.getWidth(), r.getX()), - jlimit (screen.getY(), screen.getBottom() - r.getHeight(), r.getY())); + newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()), + jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY())); } - lastNonFullScreenPos = r; - - if (isOnDesktop()) + if (peer != 0) { - ComponentPeer* const peer = getPeer(); - - if (peer != 0) - peer->setNonFullScreenBounds (r); + peer->getFrameSize().subtractFrom (newPos); + peer->setNonFullScreenBounds (newPos); } + lastNonFullScreenPos = newPos; setFullScreen (fs); if (! fs) - setBoundsConstrained (r.getX(), - r.getY(), - r.getWidth(), - r.getHeight()); + setBoundsConstrained (newPos); return true; } diff --git a/src/gui/components/windows/juce_ResizableWindow.h b/src/gui/components/windows/juce_ResizableWindow.h index 77d6e03b16..5bd04bf6bc 100644 --- a/src/gui/components/windows/juce_ResizableWindow.h +++ b/src/gui/components/windows/juce_ResizableWindow.h @@ -168,7 +168,7 @@ public: @see setConstrainer */ - void setBoundsConstrained (int x, int y, int width, int height); + void setBoundsConstrained (const Rectangle& bounds); //============================================================================== diff --git a/src/native/mac/juce_iphone_UIViewComponentPeer.mm b/src/native/mac/juce_iphone_UIViewComponentPeer.mm index 7f948bf8c1..af48cde17d 100644 --- a/src/native/mac/juce_iphone_UIViewComponentPeer.mm +++ b/src/native/mac/juce_iphone_UIViewComponentPeer.mm @@ -528,26 +528,23 @@ CGRect UIViewComponentPeer::constrainRect (CGRect r) r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height; - int x = (int) r.origin.x; - int y = (int) r.origin.y; - int w = (int) r.size.width; - int h = (int) r.size.height; + Rectangle pos ((int) r.origin.x, (int) r.origin.y, + (int) r.size.width, (int) r.size.height); Rectangle original ((int) current.origin.x, (int) current.origin.y, (int) current.size.width, (int) current.size.height); - constrainer->checkBounds (x, y, w, h, - original, + constrainer->checkBounds (pos, original, Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(), - y != original.getY() && y + h == original.getBottom(), - x != original.getX() && x + w == original.getRight(), - y == original.getY() && y + h != original.getBottom(), - x == original.getX() && x + w != original.getRight()); - - r.origin.x = x; - r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - y; - r.size.width = w; - r.size.height = h; + pos.getY() != original.getY() && pos.getBottom() == original.getBottom(), + pos.getX() != original.getX() && pos.getRight() == original.getRight(), + pos.getY() == original.getY() && pos.getBottom() != original.getBottom(), + pos.getX() == original.getX() && pos.getRight() != original.getRight()); + + r.origin.x = pos.getX(); + r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY(); + r.size.width = pos.getWidth(); + r.size.height = pos.getHeight(); } return r; diff --git a/src/native/mac/juce_mac_NSViewComponentPeer.mm b/src/native/mac/juce_mac_NSViewComponentPeer.mm index 6e57bdcb3b..6d264aca9c 100644 --- a/src/native/mac/juce_mac_NSViewComponentPeer.mm +++ b/src/native/mac/juce_mac_NSViewComponentPeer.mm @@ -897,26 +897,23 @@ NSRect NSViewComponentPeer::constrainRect (NSRect r) r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height; - int x = (int) r.origin.x; - int y = (int) r.origin.y; - int w = (int) r.size.width; - int h = (int) r.size.height; + Rectangle pos ((int) r.origin.x, (int) r.origin.y, + (int) r.size.width, (int) r.size.height); Rectangle original ((int) current.origin.x, (int) current.origin.y, (int) current.size.width, (int) current.size.height); - constrainer->checkBounds (x, y, w, h, - original, + constrainer->checkBounds (pos, original, Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(), - y != original.getY() && y + h == original.getBottom(), - x != original.getX() && x + w == original.getRight(), - y == original.getY() && y + h != original.getBottom(), - x == original.getX() && x + w != original.getRight()); - - r.origin.x = x; - r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - y; - r.size.width = w; - r.size.height = h; + pos.getY() != original.getY() && pos.getBottom() == original.getBottom(), + pos.getX() != original.getX() && pos.getRight() == original.getRight(), + pos.getY() == original.getY() && pos.getBottom() != original.getBottom(), + pos.getX() == original.getX() && pos.getRight() != original.getRight()); + + r.origin.x = pos.getX(); + r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY(); + r.size.width = pos.getWidth(); + r.size.height = pos.getHeight(); } return r; diff --git a/src/native/windows/juce_win32_Windowing.cpp b/src/native/windows/juce_win32_Windowing.cpp index f9de485d26..e8914670f6 100644 --- a/src/native/windows/juce_win32_Windowing.cpp +++ b/src/native/windows/juce_win32_Windowing.cpp @@ -1902,13 +1902,18 @@ private: component->getWidth() + windowBorder.getLeftAndRight(), component->getHeight() + windowBorder.getTopAndBottom()); - constrainer->checkBounds (wp->x, wp->y, wp->cx, wp->cy, - current, + Rectangle pos (wp->x, wp->y, wp->cx, wp->cy); + + constrainer->checkBounds (pos, current, Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(), - wp->y != current.getY() && wp->y + wp->cy == current.getBottom(), - wp->x != current.getX() && wp->x + wp->cx == current.getRight(), - wp->y == current.getY() && wp->y + wp->cy != current.getBottom(), - wp->x == current.getX() && wp->x + wp->cx != current.getRight()); + pos.getY() != current.getY() && pos.getBottom() == current.getBottom(), + pos.getX() != current.getX() && pos.getRight() == current.getRight(), + pos.getY() == current.getY() && pos.getBottom() != current.getBottom(), + pos.getX() == current.getX() && pos.getRight() != current.getRight()); + wp->x = pos.getX(); + wp->y = pos.getY(); + wp->cx = pos.getWidth(); + wp->cy = pos.getHeight(); } } }