From a93ebf8e2891dc53ed15fcf786bcd8b2027007b1 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sun, 13 Dec 2020 22:08:39 -0500 Subject: [PATCH] Enable MenuOverlay darkening again. Use MenuOverlay subclass for ModuleBrowser. Consume all keys/buttons in MenuOverlay. --- include/ui/MenuOverlay.hpp | 1 + src/app/ModuleBrowser.cpp | 21 +++++++-------------- src/ui/MenuOverlay.cpp | 31 +++++++++++++++++++++++-------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/include/ui/MenuOverlay.hpp b/include/ui/MenuOverlay.hpp index c70863cc..e49ce995 100644 --- a/include/ui/MenuOverlay.hpp +++ b/include/ui/MenuOverlay.hpp @@ -13,6 +13,7 @@ struct MenuOverlay : widget::OpaqueWidget { void step() override; void onButton(const event::Button& e) override; void onHoverKey(const event::HoverKey& e) override; + void onAction(const event::Action& e) override; }; diff --git a/src/app/ModuleBrowser.cpp b/src/app/ModuleBrowser.cpp index 9dd53839..722bf2e0 100644 --- a/src/app/ModuleBrowser.cpp +++ b/src/app/ModuleBrowser.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -101,23 +102,15 @@ static ModuleWidget* chooseModel(plugin::Model* model) { // Widgets -struct BrowserOverlay : widget::OpaqueWidget { +struct BrowserOverlay : ui::MenuOverlay { void step() override { - box = parent->box.zeroPos(); // Only step if visible, since there are potentially thousands of descendants that don't need to be stepped. - if (visible) - OpaqueWidget::step(); + if (isVisible()) + MenuOverlay::step(); } - void onButton(const event::Button& e) override { - OpaqueWidget::onButton(e); - if (e.getTarget() != this) - return; - - if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) { - hide(); - e.consume(this); - } + void onAction(const event::Action& e) override { + hide(); } }; @@ -447,7 +440,7 @@ struct ModuleBrowser : widget::OpaqueWidget { } void step() override { - box = parent->box.zeroPos().grow(math::Vec(-70, -70)); + box = parent->box.zeroPos().grow(math::Vec(-40, -40)); sidebar->box.size.y = box.size.y; diff --git a/src/ui/MenuOverlay.cpp b/src/ui/MenuOverlay.cpp index f7902683..74ed3f68 100644 --- a/src/ui/MenuOverlay.cpp +++ b/src/ui/MenuOverlay.cpp @@ -7,40 +7,55 @@ namespace ui { void MenuOverlay::draw(const DrawArgs& args) { // Possible translucent background - // nvgRect(args.vg, 0, 0, VEC_ARGS(box.size)); - // nvgFillColor(args.vg, nvgRGBAf(0, 0, 0, 0.25)); - // nvgFill(args.vg); + nvgRect(args.vg, 0, 0, VEC_ARGS(box.size)); + nvgFillColor(args.vg, nvgRGBAf(0, 0, 0, 0.333)); + nvgFill(args.vg); OpaqueWidget::draw(args); } + void MenuOverlay::step() { // Adopt parent's size - box.size = parent->box.size; + box = parent->box.zeroPos(); Widget::step(); } + void MenuOverlay::onButton(const event::Button& e) { OpaqueWidget::onButton(e); if (e.isConsumed() && e.getTarget() != this) return; if (e.action == GLFW_PRESS) { - requestDelete(); - e.consume(this); + event::Action eAction; + onAction(eAction); } + + // Consume all buttons. + e.consume(this); } + void MenuOverlay::onHoverKey(const event::HoverKey& e) { OpaqueWidget::onHoverKey(e); if (e.isConsumed()) return; if (e.action == GLFW_PRESS && e.key == GLFW_KEY_ESCAPE) { - requestDelete(); - e.consume(this); + event::Action eAction; + onAction(eAction); } + + // Consume all keys. + // Unfortunately this prevents MIDI computer keyboard from playing while a menu is open, but that might be a good thing for safety. + e.consume(this); +} + + +void MenuOverlay::onAction(const event::Action& e) { + requestDelete(); }