Skip to content

Commit

Permalink
Redo CLFOGui context menu in JUCE
Browse files Browse the repository at this point in the history
  • Loading branch information
mkruselj committed May 20, 2021
1 parent 13d161a commit 6b43776
Showing 1 changed file with 42 additions and 45 deletions.
87 changes: 42 additions & 45 deletions src/gui/CLFOGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,11 +1235,7 @@ 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 contextMenu = juce::PopupMenu();

auto addCb = [](COptionMenu *p, const std::string &l,
std::function<void()> op) -> std::shared_ptr<CCommandMenuItem> {
Expand All @@ -1253,57 +1249,58 @@ void CLFOGui::openPopup(CPoint &where)
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

0 comments on commit 6b43776

Please sign in to comment.