From 99b1f0b97e1017bd5ae0e9b4fe131a3eeaf33a9c Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 10 Oct 2021 16:55:25 -0400 Subject: [PATCH] MSEG and Formula can Tear Out (#5232) 1. Address the scale issue so zoom works 2. Handle the fact that these are swapable single views so the right thing generally happens when you change from an mseg to a formula Closes #5219 --- src/surge-xt/gui/SurgeGUIEditor.h | 1 + src/surge-xt/gui/SurgeGUIEditorOverlays.cpp | 13 ++++++ .../gui/SurgeGUIEditorValueCallbacks.cpp | 42 ++++++++++++++----- src/surge-xt/gui/overlays/LuaEditors.cpp | 9 +++- src/surge-xt/gui/overlays/MSEGEditor.cpp | 9 +++- src/surge-xt/gui/overlays/OverlayWrapper.cpp | 12 +++++- src/surge-xt/gui/overlays/OverlayWrapper.h | 3 +- src/surge-xt/gui/overlays/TuningOverlays.cpp | 1 - 8 files changed, 74 insertions(+), 16 deletions(-) diff --git a/src/surge-xt/gui/SurgeGUIEditor.h b/src/surge-xt/gui/SurgeGUIEditor.h index 93f95b4a665..5e0dc9086d9 100644 --- a/src/surge-xt/gui/SurgeGUIEditor.h +++ b/src/surge-xt/gui/SurgeGUIEditor.h @@ -407,6 +407,7 @@ class SurgeGUIEditor : public Surge::GUI::IComponentTagValue::Listener, } bool isAnyOverlayOpenAtAll() { return !juceOverlays.empty(); } juce::Component *getOverlayIfOpen(OverlayTags tag); + Surge::Overlays::OverlayWrapper *getOverlayWrapperIfOpen(OverlayTags tag); void updateWaveshaperOverlay(); // this is the only overlay which updates from patch values diff --git a/src/surge-xt/gui/SurgeGUIEditorOverlays.cpp b/src/surge-xt/gui/SurgeGUIEditorOverlays.cpp index be28bb60f5b..e974f7153bc 100644 --- a/src/surge-xt/gui/SurgeGUIEditorOverlays.cpp +++ b/src/surge-xt/gui/SurgeGUIEditorOverlays.cpp @@ -165,6 +165,7 @@ std::unique_ptr SurgeGUIEditor::createOverlay Surge::Storage::findReplaceSubstring(title, std::string("LFO"), std::string("MSEG")); mse->setEnclosingParentTitle(title); + mse->setCanTearOut(true); locationForMSFR(mse.get()); return mse; } @@ -184,6 +185,7 @@ std::unique_ptr SurgeGUIEditor::createOverlay Surge::Storage::findReplaceSubstring(title, std::string("LFO"), std::string("Formula")); pt->setEnclosingParentTitle(title); + pt->setCanTearOut(true); locationForMSFR(pt.get()); return pt; } @@ -487,6 +489,17 @@ juce::Component *SurgeGUIEditor::getOverlayIfOpen(OverlayTags tag) return juceOverlays[tag]->primaryChild.get(); } +Surge::Overlays::OverlayWrapper *SurgeGUIEditor::getOverlayWrapperIfOpen(OverlayTags tag) +{ + if (juceOverlays.find(tag) == juceOverlays.end()) + return nullptr; + + if (!juceOverlays[tag]) + return nullptr; + + return dynamic_cast(juceOverlays[tag].get()); +} + void SurgeGUIEditor::updateWaveshaperOverlay() { auto wso = diff --git a/src/surge-xt/gui/SurgeGUIEditorValueCallbacks.cpp b/src/surge-xt/gui/SurgeGUIEditorValueCallbacks.cpp index 19df7443ec7..f2af9337f44 100644 --- a/src/surge-xt/gui/SurgeGUIEditorValueCallbacks.cpp +++ b/src/surge-xt/gui/SurgeGUIEditorValueCallbacks.cpp @@ -2553,27 +2553,49 @@ void SurgeGUIEditor::valueChanged(Surge::GUI::IComponentTagValue *control) } bool hadExtendedOverlay = false; - if (isAnyOverlayPresent(MSEG_EDITOR)) + bool wasTornOut = false; + juce::Point tearOutLoc; + for (auto otag : {MSEG_EDITOR, FORMULA_EDITOR}) { - closeOverlay(SurgeGUIEditor::MSEG_EDITOR); - hadExtendedOverlay = true; - } - if (isAnyOverlayPresent(FORMULA_EDITOR)) - { - closeOverlay(FORMULA_EDITOR); - hadExtendedOverlay = true; + if (isAnyOverlayPresent(otag)) + { + auto c = getOverlayWrapperIfOpen(otag); + if (c) + { + wasTornOut = c->isTornOut(); + tearOutLoc = c->currentTearOutLocation(); + } + closeOverlay(otag); + hadExtendedOverlay = true; + } } + if (hadExtendedOverlay) { auto ld = &(synth->storage.getPatch().scene[current_scene].lfo[newsource - ms_lfo1]); + auto tag = MSEG_EDITOR; + bool go = false; if (ld->shape.val.i == lt_mseg) { - showOverlay(SurgeGUIEditor::MSEG_EDITOR); + go = true; } if (ld->shape.val.i == lt_formula) { - showOverlay(FORMULA_EDITOR); + tag = FORMULA_EDITOR; + go = true; + } + if (go) + { + showOverlay(tag); + if (wasTornOut) + { + auto c = getOverlayWrapperIfOpen(tag); + if (c) + { + c->doTearOut(tearOutLoc); + } + } } } diff --git a/src/surge-xt/gui/overlays/LuaEditors.cpp b/src/surge-xt/gui/overlays/LuaEditors.cpp index 70e60873b7e..13517988687 100644 --- a/src/surge-xt/gui/overlays/LuaEditors.cpp +++ b/src/surge-xt/gui/overlays/LuaEditors.cpp @@ -313,16 +313,21 @@ void FormulaModulatorEditor::applyCode() void FormulaModulatorEditor::resized() { + auto t = getTransform().inverted(); + auto h = getHeight(); + auto w = getWidth(); + t.transformPoint(w, h); + int efdWidth = 14; if (efd->isOpen) { efdWidth = 200; } tabs->setTabBarDepth(14); - tabs->setBounds(2, 2, getWidth() - 8 - efdWidth, getHeight() - 4); + tabs->setBounds(2, 2, w - 8 - efdWidth, h - 4); auto b = tabs->getTabbedButtonBar().getLocalBounds(); applyButton->setBounds(b.getWidth() - 80, 2, 80 - 2, b.getHeight() - 4); - efd->setBounds(getWidth() - 4 - efdWidth, 2, efdWidth, getHeight() - 4); + efd->setBounds(w - 4 - efdWidth, 2, efdWidth, h - 4); } struct WavetablePreviewComponent : juce::Component diff --git a/src/surge-xt/gui/overlays/MSEGEditor.cpp b/src/surge-xt/gui/overlays/MSEGEditor.cpp index bf9d0e018c2..376139360f6 100644 --- a/src/surge-xt/gui/overlays/MSEGEditor.cpp +++ b/src/surge-xt/gui/overlays/MSEGEditor.cpp @@ -3257,11 +3257,18 @@ void MSEGEditor::paint(juce::Graphics &g) { g.fillAll(juce::Colours::orchid); } void MSEGEditor::resized() { int controlHeight = 35; - auto r = getLocalBounds(); + + auto t = getTransform().inverted(); + auto h = getHeight(); + auto w = getWidth(); + t.transformPoint(w, h); + auto r = getLocalBounds().withWidth(w).withHeight(h); + auto cvr = r.withTrimmedBottom(controlHeight); auto ctr = r.withTop(cvr.getBottom()); canvas->setBounds(cvr); + canvas->recalcHotZones(juce::Point(0, 0)); controls->setBounds(ctr); // mained setbounds } diff --git a/src/surge-xt/gui/overlays/OverlayWrapper.cpp b/src/surge-xt/gui/overlays/OverlayWrapper.cpp index 1dceaf38712..bcc833f7e77 100644 --- a/src/surge-xt/gui/overlays/OverlayWrapper.cpp +++ b/src/surge-xt/gui/overlays/OverlayWrapper.cpp @@ -157,7 +157,7 @@ void OverlayWrapper::supressInteriorDecoration() primaryChild->setBounds(getLocalBounds()); } -void OverlayWrapper::doTearOut() +void OverlayWrapper::doTearOut(const juce::Point &showAt) { parentBeforeTearOut = getParentComponent(); locationBeforeTearOut = getBoundsInParent(); @@ -187,12 +187,22 @@ void OverlayWrapper::doTearOut() dw->setContentNonOwned(this, false); dw->setContentComponentSize(w, h); dw->setVisible(true); + if (showAt.x >= 0 && showAt.y >= 0) + dw->setTopLeftPosition(showAt.x, showAt.y); dw->toFront(true); dw->wrapping = this; supressInteriorDecoration(); tearOutParent = std::move(dw); } +juce::Point OverlayWrapper::currentTearOutLocation() +{ + if (!isTornOut()) + return juce::Point(-1, -1); + + return tearOutParent->getPosition(); +} + void OverlayWrapper::doTearIn() { if (!isTornOut() || !parentBeforeTearOut) diff --git a/src/surge-xt/gui/overlays/OverlayWrapper.h b/src/surge-xt/gui/overlays/OverlayWrapper.h index b69e8427a75..414099cd3d1 100644 --- a/src/surge-xt/gui/overlays/OverlayWrapper.h +++ b/src/surge-xt/gui/overlays/OverlayWrapper.h @@ -68,9 +68,10 @@ struct OverlayWrapper : public juce::Component, bool canTearOut{false}; void setCanTearOut(bool b) { canTearOut = b; } - void doTearOut(); + void doTearOut(const juce::Point &showAt = juce::Point(-1, -1)); void doTearIn(); bool isTornOut(); + juce::Point currentTearOutLocation(); juce::Rectangle locationBeforeTearOut, childLocationBeforeTearOut; juce::Component *parentBeforeTearOut{nullptr}; diff --git a/src/surge-xt/gui/overlays/TuningOverlays.cpp b/src/surge-xt/gui/overlays/TuningOverlays.cpp index 430d86532f2..7861f3c624e 100644 --- a/src/surge-xt/gui/overlays/TuningOverlays.cpp +++ b/src/surge-xt/gui/overlays/TuningOverlays.cpp @@ -692,7 +692,6 @@ struct IntervalMatrix : public juce::Component void resized() override { - std::cout << "IM Resized " << getLocalBounds().toString() << std::endl; viewport->setBounds(getLocalBounds().reduced(2).withTrimmedBottom(20)); intervalPainter->setSizeFromTuning();