Skip to content

Commit

Permalink
Fix TearOut objections
Browse files Browse the repository at this point in the history
Closes surge-synthesizer#5247

- Center initial position
- Handle close and reskin and swap type closes
- Pink line in mseg gone
- Mouse drag at correct speed
- Positions remember as defaults keys
  • Loading branch information
baconpaul committed Oct 21, 2021
1 parent db686fc commit 673a527
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 29 deletions.
9 changes: 9 additions & 0 deletions src/common/UserDefaults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ void initMaps()
case WSAnalysisOverlayLocation:
r = "wsAnalysisOverlayLocation";
break;
case TuningOverlayLocationTearOut:
r = "tuningOverlayLocationTearOut";
break;
case ModlistOverlayLocationTearOut:
r = "modlistOverlayLocationTearOut";
break;
case MSEGFormulaOverlayLocationTearOut:
r = "msegFormulaOverlayLocationTearOut";
break;
case nKeys:
break;
}
Expand Down
4 changes: 4 additions & 0 deletions src/common/UserDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ enum DefaultKey // streamed as strings so feel free to change the order to whate
MSEGFormulaOverlayLocation,
WSAnalysisOverlayLocation,

TuningOverlayLocationTearOut,
ModlistOverlayLocationTearOut,
MSEGFormulaOverlayLocationTearOut,

nKeys
};
/**
Expand Down
40 changes: 40 additions & 0 deletions src/surge-xt/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3649,7 +3649,21 @@ void SurgeGUIEditor::reloadFromSkin()
// update overlays, if opened
if (isAnyOverlayPresent(MSEG_EDITOR))
{
bool tornOut = false;
juce::Point<int> tearOutPos;
auto olw = getOverlayWrapperIfOpen(MSEG_EDITOR);
if (olw && olw->isTornOut())
{
tornOut = true;
tearOutPos = olw->currentTearOutLocation();
}
showOverlay(SurgeGUIEditor::MSEG_EDITOR);
if (tornOut)
{
auto olw = getOverlayWrapperIfOpen(MSEG_EDITOR);
if (olw)
olw->doTearOut(tearOutPos);
}
}

// update waveshaper analyzer if opened
Expand Down Expand Up @@ -5243,13 +5257,27 @@ void SurgeGUIEditor::lfoShapeChanged(int prior, int curr)
}

bool hadExtendedEditor = false;
bool isTornOut = false;
juce::Point<int> tearOutPos;
if (isAnyOverlayPresent(MSEG_EDITOR))
{
auto olw = getOverlayWrapperIfOpen(MSEG_EDITOR);
if (olw && olw->isTornOut())
{
isTornOut = true;
tearOutPos = olw->currentTearOutLocation();
}
closeOverlay(SurgeGUIEditor::MSEG_EDITOR);
hadExtendedEditor = true;
}
if (isAnyOverlayPresent(FORMULA_EDITOR))
{
auto olw = getOverlayWrapperIfOpen(FORMULA_EDITOR);
if (olw && olw->isTornOut())
{
isTornOut = true;
tearOutPos = olw->currentTearOutLocation();
}
closeOverlay(FORMULA_EDITOR);
hadExtendedEditor = true;
}
Expand All @@ -5259,10 +5287,22 @@ void SurgeGUIEditor::lfoShapeChanged(int prior, int curr)
if (curr == lt_mseg)
{
showOverlay(SurgeGUIEditor::MSEG_EDITOR);
if (isTornOut)
{
auto olw = getOverlayWrapperIfOpen(MSEG_EDITOR);
if (olw)
olw->doTearOut(tearOutPos);
}
}
if (curr == lt_formula)
{
showOverlay(FORMULA_EDITOR);
if (isTornOut)
{
auto olw = getOverlayWrapperIfOpen(FORMULA_EDITOR);
if (olw)
olw->doTearOut(tearOutPos);
}
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/surge-xt/gui/SurgeGUIEditorOverlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "overlays/OverlayWrapper.h"
#include "widgets/MainFrame.h"
#include "widgets/WaveShaperSelector.h"
#include "UserDefaults.h"

std::unique_ptr<Surge::Overlays::OverlayComponent> SurgeGUIEditor::makeStorePatchDialog()
{
Expand Down Expand Up @@ -138,7 +139,8 @@ std::unique_ptr<Surge::Overlays::OverlayComponent> SurgeGUIEditor::createOverlay
auto h = getWindowSizeY() - yPos - xBuf;
pt->setEnclosingParentPosition(juce::Rectangle<int>(xBuf, yPos, w, h));
pt->setEnclosingParentTitle("Patch Database");
pt->setCanTearOut(true);
jassert(false); // Make a key for me please!
pt->setCanTearOut({true, Surge::Storage::nKeys});
return pt;
}
break;
Expand Down Expand Up @@ -187,7 +189,7 @@ std::unique_ptr<Surge::Overlays::OverlayComponent> SurgeGUIEditor::createOverlay
Surge::Storage::findReplaceSubstring(title, std::string("LFO"), std::string("MSEG"));

mse->setEnclosingParentTitle(title);
mse->setCanTearOut(true);
mse->setCanTearOut({true, Surge::Storage::MSEGFormulaOverlayLocationTearOut});
locationForMSFR(mse.get());
return mse;
}
Expand Down Expand Up @@ -230,7 +232,7 @@ std::unique_ptr<Surge::Overlays::OverlayComponent> SurgeGUIEditor::createOverlay
Surge::Storage::findReplaceSubstring(title, std::string("LFO"), std::string("Formula"));

pt->setEnclosingParentTitle(title);
pt->setCanTearOut(true);
pt->setCanTearOut({true, Surge::Storage::MSEGFormulaOverlayLocationTearOut});
locationForMSFR(pt.get());
return pt;
}
Expand Down Expand Up @@ -263,7 +265,7 @@ std::unique_ptr<Surge::Overlays::OverlayComponent> SurgeGUIEditor::createOverlay
pt->setTuning(synth->storage.currentTuning);
pt->setEnclosingParentPosition(juce::Rectangle<int>(px, py, w, h));
pt->setEnclosingParentTitle("Tuning Editor");
pt->setCanTearOut(true);
pt->setCanTearOut({true, Surge::Storage::TuningOverlayLocationTearOut});
pt->defaultLocation = dl;
pt->setCanMoveAround(std::make_pair(true, Surge::Storage::TuningOverlayLocation));
return pt;
Expand Down Expand Up @@ -346,7 +348,7 @@ std::unique_ptr<Surge::Overlays::OverlayComponent> SurgeGUIEditor::createOverlay
pt->setEnclosingParentTitle("Modulation List");
pt->setEnclosingParentPosition(r);
pt->setCanMoveAround(std::make_pair(true, Surge::Storage::ModlistOverlayLocation));
pt->setCanTearOut(true);
pt->setCanTearOut({true, Surge::Storage::ModlistOverlayLocationTearOut});
pt->defaultLocation = dl;
return pt;
}
Expand Down
2 changes: 1 addition & 1 deletion src/surge-xt/gui/overlays/MSEGEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3259,7 +3259,7 @@ void MSEGEditor::forceRefresh()
}
}

void MSEGEditor::paint(juce::Graphics &g) { g.fillAll(juce::Colours::orchid); }
void MSEGEditor::paint(juce::Graphics &g) { g.fillAll(juce::Colours::black); }

void MSEGEditor::resized()
{
Expand Down
6 changes: 3 additions & 3 deletions src/surge-xt/gui/overlays/OverlayComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ struct OverlayComponent : juce::Component
void setHasIndependentClose(bool b) { hasIndependentClose = b; }
bool getHasIndependentClose() { return hasIndependentClose; }

bool canTearOut{false};
void setCanTearOut(bool b) { canTearOut = b; }
bool getCanTearOut() { return canTearOut; }
std::pair<bool, Surge::Storage::DefaultKey> canTearOut{false, Surge::Storage::nKeys};
void setCanTearOut(std::pair<bool, Surge::Storage::DefaultKey> b) { canTearOut = b; }
std::pair<bool, Surge::Storage::DefaultKey> getCanTearOut() { return canTearOut; }
virtual void onTearOutChanged(bool isTornOut) {}

std::pair<bool, Surge::Storage::DefaultKey> canMoveAround{false, Surge::Storage::nKeys};
Expand Down
64 changes: 47 additions & 17 deletions src/surge-xt/gui/overlays/OverlayWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "SurgeImage.h"
#include "SurgeGUIEditor.h"
#include "OverlayComponent.h"
#include "widgets/MainFrame.h"

namespace Surge
{
Expand Down Expand Up @@ -133,20 +134,38 @@ struct TearOutWindow : public juce::DocumentWindow
}

OverlayWrapper *wrapping{nullptr};
void closeButtonPressed()
void closeButtonPressed() override
{
if (wrapping)
{
wrapping->onClose();
}
}
void minimiseButtonPressed()
void minimiseButtonPressed() override
{
if (wrapping)
{
wrapping->doTearIn();
}
}

int outstandingMoves = 0;
void moved() override
{
outstandingMoves++;
// writing every move would be "bad". Add a 1 second delay.
juce::Timer::callAfterDelay(1000, [this]() { this->moveUpdate(); });
}
void moveUpdate()
{
outstandingMoves--;
if (outstandingMoves == 0 && wrapping->storage)
{
auto tl = getBounds().getTopLeft();
Surge::Storage::updateUserDefaultValue(
wrapping->storage, wrapping->canTearOutPair.second, std::make_pair(tl.x, tl.y));
}
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TearOutWindow);
};

Expand Down Expand Up @@ -190,6 +209,24 @@ void OverlayWrapper::doTearOut(const juce::Point<int> &showAt)
dw->setVisible(true);
if (showAt.x >= 0 && showAt.y >= 0)
dw->setTopLeftPosition(showAt.x, showAt.y);
else
{
auto pt = std::make_pair(-1, -1);
if (storage)
pt = Surge::Storage::getUserDefaultValue(storage, canTearOutPair.second, pt);
auto dt = juce::Desktop::getInstance()
.getDisplays()
.getDisplayForPoint(editor->frame->getBounds().getTopLeft())
->userArea;
auto dtp = juce::Point<int>((dt.getWidth() - w) / 2, (dt.getHeight() - h) / 2);
if (pt.first > 0 && pt.second > 0 && pt.first < dt.getWidth() - w / 2 &&
pt.second < dt.getHeight() - h / 2)
{
dtp.x = pt.first;
dtp.y = pt.second;
}
dw->setTopLeftPosition(dtp);
}
dw->toFront(true);
dw->wrapping = this;
supressInteriorDecoration();
Expand Down Expand Up @@ -236,8 +273,9 @@ void OverlayWrapper::mouseDown(const juce::MouseEvent &e)
if (c && c->getCanMoveAround())
{
isDragging = true;
distanceFromCornerToMouseDown =
localPointToGlobal(e.position) - getBounds().getTopLeft().toFloat();

// This is borrowed from juce::ComponentDragger
mouseDownWithinTarget = e.getEventRelativeTo(this).getMouseDownPosition();
repaint();
}
}
Expand Down Expand Up @@ -283,19 +321,11 @@ void OverlayWrapper::mouseDrag(const juce::MouseEvent &e)
auto c = getPrimaryChildAsOverlayComponent();
if (c && c->getCanMoveAround())
{
auto gp = localPointToGlobal(e.position);
auto newTopLeft = gp - distanceFromCornerToMouseDown;
newTopLeft.x = std::max(0.f, newTopLeft.x);
newTopLeft.y = std::max(0.f, newTopLeft.y);

auto pw = 1.f * getParentComponent()->getWidth();
auto ph = 1.f * getParentComponent()->getHeight();
newTopLeft.x = std::min(newTopLeft.x, pw - getWidth());
newTopLeft.y = std::min(newTopLeft.y, ph - getHeight());

auto b = getBounds();
auto q = juce::Rectangle<int>(newTopLeft.x, newTopLeft.y, b.getWidth(), b.getHeight());
setBounds(q);
// Borrowed from juce::ComponentDragger
auto bounds = getBounds();
bounds += getLocalPoint(nullptr, e.source.getScreenPosition()).roundToInt() -
mouseDownWithinTarget;
setBounds(bounds);
}
}

Expand Down
13 changes: 10 additions & 3 deletions src/surge-xt/gui/overlays/OverlayWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define SURGE_XT_OVERLAYWRAPPER_H

#include "SkinSupport.h"
#include "UserDefaults.h"

#include "juce_gui_basics/juce_gui_basics.h"

Expand Down Expand Up @@ -55,7 +56,8 @@ struct OverlayWrapper : public juce::Component,
std::unique_ptr<juce::TextButton> closeButton, tearOutButton;
void buttonClicked(juce::Button *button) override;

juce::Point<float> distanceFromCornerToMouseDown;
juce::Point<int> mouseDownWithinTarget;

bool isDragging{false};
bool allowDrag{true};
void mouseDown(const juce::MouseEvent &) override;
Expand All @@ -66,8 +68,13 @@ struct OverlayWrapper : public juce::Component,
SurgeImage *icon{nullptr};
void setIcon(SurgeImage *d) { icon = d; }

bool canTearOut{false};
void setCanTearOut(bool b) { canTearOut = b; }
std::pair<bool, Surge::Storage::DefaultKey> canTearOutPair{false, Surge::Storage::nKeys};
bool canTearOut;
void setCanTearOut(std::pair<bool, Surge::Storage::DefaultKey> b)
{
canTearOutPair = b;
canTearOut = b.first;
}
void doTearOut(const juce::Point<int> &showAt = juce::Point<int>(-1, -1));
void doTearIn();
bool isTornOut();
Expand Down

0 comments on commit 673a527

Please sign in to comment.