From 71f6e36b10221fc05514ba708869f444714e3906 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 7 Oct 2021 16:32:40 -0400 Subject: [PATCH] Add a "Tear-In" to the "Tear-Out" (#5228) You can return them to the urge window if you want Closes #5220 --- src/surge-xt/gui/overlays/OverlayWrapper.cpp | 31 +++++++++++++++++++- src/surge-xt/gui/overlays/OverlayWrapper.h | 3 ++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/surge-xt/gui/overlays/OverlayWrapper.cpp b/src/surge-xt/gui/overlays/OverlayWrapper.cpp index bbbd99f0a1f..98c20756cc8 100644 --- a/src/surge-xt/gui/overlays/OverlayWrapper.cpp +++ b/src/surge-xt/gui/overlays/OverlayWrapper.cpp @@ -139,6 +139,13 @@ struct TearOutWindow : public juce::DocumentWindow wrapping->onClose(); } } + void minimiseButtonPressed() + { + if (wrapping) + { + wrapping->doTearIn(); + } + } JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TearOutWindow); }; @@ -151,6 +158,9 @@ void OverlayWrapper::supressInteriorDecoration() void OverlayWrapper::doTearOut() { + parentBeforeTearOut = getParentComponent(); + locationBeforeTearOut = getBoundsInParent(); + childLocationBeforeTearOut = primaryChild->getBounds(); getParentComponent()->removeChildComponent(this); auto w = getWidth(); @@ -171,7 +181,8 @@ void OverlayWrapper::doTearOut() { t = oc->getEnclosingParentTitle(); } - auto dw = std::make_unique(t, juce::DocumentWindow::closeButton); + auto dw = std::make_unique(t, juce::DocumentWindow::closeButton | + juce::DocumentWindow::minimiseButton); dw->setContentNonOwned(this, false); dw->setContentComponentSize(w, h); dw->setVisible(true); @@ -180,5 +191,23 @@ void OverlayWrapper::doTearOut() supressInteriorDecoration(); tearOutParent = std::move(dw); } + +void OverlayWrapper::doTearIn() +{ + if (!isTornOut() || !parentBeforeTearOut) + { + // Should never happen but if it does + onClose(); + return; + } + tearOutParent.reset(nullptr); + hasInteriorDec = true; + + primaryChild->setTransform(juce::AffineTransform()); + primaryChild->setBounds(childLocationBeforeTearOut); + setBounds(locationBeforeTearOut); + parentBeforeTearOut->addAndMakeVisible(*this); + parentBeforeTearOut = nullptr; +} } // namespace Overlays } // namespace Surge diff --git a/src/surge-xt/gui/overlays/OverlayWrapper.h b/src/surge-xt/gui/overlays/OverlayWrapper.h index e7060e76cd6..251fdfb7d78 100644 --- a/src/surge-xt/gui/overlays/OverlayWrapper.h +++ b/src/surge-xt/gui/overlays/OverlayWrapper.h @@ -55,7 +55,10 @@ struct OverlayWrapper : public juce::Component, bool canTearOut{false}; void setCanTearOut(bool b) { canTearOut = b; } void doTearOut(); + void doTearIn(); bool isTornOut(); + juce::Rectangle locationBeforeTearOut, childLocationBeforeTearOut; + juce::Component *parentBeforeTearOut{nullptr}; bool hasInteriorDec{true}; void supressInteriorDecoration();