From 6b437763b6ea495ff09f1813b39db1580a09169b Mon Sep 17 00:00:00 2001 From: Mario Kruselj Date: Thu, 20 May 2021 11:18:28 +0200 Subject: [PATCH] Redo CLFOGui context menu in JUCE Addresses #4341 --- src/gui/CLFOGui.cpp | 87 ++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 45 deletions(-) diff --git a/src/gui/CLFOGui.cpp b/src/gui/CLFOGui.cpp index 222df317fea..105c183c53b 100644 --- a/src/gui/CLFOGui.cpp +++ b/src/gui/CLFOGui.cpp @@ -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 op) -> std::shared_ptr { @@ -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(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)