Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redo CLFOGui context menu in JUCE #4567

Merged
merged 2 commits into from
May 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 42 additions & 53 deletions src/gui/CLFOGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,75 +1235,64 @@ void CLFOGui::openPopup(CPoint &where)
{
CPoint w = where;

printf("%.2f %.2f\n", w.x, w.y);

COptionMenu *contextMenu = new COptionMenu(CRect(w, CPoint(0, 0)), 0, 0, 0, 0,
VSTGUI::COptionMenu::kNoDrawStyle |
VSTGUI::COptionMenu::kMultipleCheckStyle);

auto addCb = [](COptionMenu *p, const std::string &l,
std::function<void()> op) -> std::shared_ptr<CCommandMenuItem> {
auto m = std::make_shared<CCommandMenuItem>(CCommandMenuItem::Desc(l.c_str()));
m->setActions([op](CCommandMenuItem *m) { op(); });
p->addEntry(m);
return m;
};
auto contextMenu = juce::PopupMenu();

auto msurl =
storage ? SurgeGUIEditor::helpURLForSpecial(storage, "mseg-editor") : std::string();
auto hurl = SurgeGUIEditor::fullyResolvedHelpURL(msurl);

addCb(contextMenu, "[?] MSEG Segment", [hurl]() { juce::URL(hurl).launchInDefaultBrowser(); });
contextMenu.addItem("[?] MSEG Segment", [hurl]() { juce::URL(hurl).launchInDefaultBrowser(); });

contextMenu->addSeparator();
contextMenu.addSeparator();

auto sge = dynamic_cast<SurgeGUIEditor *>(listener);
std::string openname = (sge && sge->isAnyOverlayPresent(SurgeGUIEditor::MSEG_EDITOR))
? "Open MSEG Editor"
: "Close MSEG Editor";
addCb(contextMenu, Surge::GUI::toOSCaseForMenu(openname), [this, sge]() {
if (sge)
sge->toggleMSEGEditor();
});

contextMenu->addSeparator();

auto lpoff = addCb(contextMenu, Surge::GUI::toOSCaseForMenu("No Looping"), [this, sge]() {
ms->loopMode = MSEGStorage::LoopMode::ONESHOT;
if (sge && sge->isAnyOverlayPresent(SurgeGUIEditor::MSEG_EDITOR))
{
sge->closeMSEGEditor();
sge->showMSEGEditor();
}
invalid();
});
lpoff->setChecked(ms->loopMode == MSEGStorage::LoopMode::ONESHOT);

auto lpon = addCb(contextMenu, Surge::GUI::toOSCaseForMenu("Loop Always"), [this, sge]() {
ms->loopMode = MSEGStorage::LoopMode::LOOP;
if (sge && sge->isAnyOverlayPresent(SurgeGUIEditor::MSEG_EDITOR))
contextMenu.addItem(Surge::GUI::toOSCaseForMenu(openname), [this, sge]() {
if (sge)
{
sge->closeMSEGEditor();
sge->showMSEGEditor();
sge->toggleMSEGEditor();
}
invalid();
});
lpon->setChecked(ms->loopMode == MSEGStorage::LoopMode::LOOP);

auto lpgate =
addCb(contextMenu, Surge::GUI::toOSCaseForMenu("Loop Until Release"), [this, sge]() {
ms->loopMode = MSEGStorage::LoopMode::GATED_LOOP;
if (sge && sge->isAnyOverlayPresent(SurgeGUIEditor::MSEG_EDITOR))
{
sge->closeMSEGEditor();
sge->showMSEGEditor();
}
invalid();
});
lpgate->setChecked(ms->loopMode == MSEGStorage::LoopMode::GATED_LOOP);

getFrame()->addView(contextMenu);
contextMenu->popup();
contextMenu.addSeparator();

contextMenu.addItem(Surge::GUI::toOSCaseForMenu("No Looping"), true,
(ms->loopMode == MSEGStorage::LoopMode::ONESHOT), [this, sge]() {
ms->loopMode = MSEGStorage::LoopMode::ONESHOT;
if (sge && sge->isAnyOverlayPresent(SurgeGUIEditor::MSEG_EDITOR))
{
sge->closeMSEGEditor();
sge->showMSEGEditor();
}
invalid();
});

contextMenu.addItem(Surge::GUI::toOSCaseForMenu("Loop Always"), true,
(ms->loopMode == MSEGStorage::LoopMode::LOOP), [this, sge]() {
ms->loopMode = MSEGStorage::LoopMode::LOOP;
if (sge && sge->isAnyOverlayPresent(SurgeGUIEditor::MSEG_EDITOR))
{
sge->closeMSEGEditor();
sge->showMSEGEditor();
}
invalid();
});

contextMenu.addItem(Surge::GUI::toOSCaseForMenu("Loop Until Release"), true,
(ms->loopMode == MSEGStorage::LoopMode::GATED_LOOP), [this, sge]() {
ms->loopMode = MSEGStorage::LoopMode::GATED_LOOP;
if (sge && sge->isAnyOverlayPresent(SurgeGUIEditor::MSEG_EDITOR))
{
sge->closeMSEGEditor();
sge->showMSEGEditor();
}
invalid();
});

contextMenu.showMenuAsync(juce::PopupMenu::Options());
}

CMouseEventResult CLFOGui::onMouseDown(CPoint &where, const CButtonState &buttons)
Expand Down