From 9cbf65f48c4f2534ad124ea03bcece4ef18c9ff4 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 4 Aug 2021 14:10:22 -0400 Subject: [PATCH] Don't propagate Hover and DragHover events on ModuleWidget if selected. --- include/app/ModuleWidget.hpp | 2 ++ src/app/ModuleWidget.cpp | 35 +++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/include/app/ModuleWidget.hpp b/include/app/ModuleWidget.hpp index c6d4aa74..fa5658e9 100644 --- a/include/app/ModuleWidget.hpp +++ b/include/app/ModuleWidget.hpp @@ -70,11 +70,13 @@ struct ModuleWidget : widget::OpaqueWidget { */ virtual void appendContextMenu(ui::Menu* menu) {} + void onHover(const HoverEvent& e) override; void onHoverKey(const HoverKeyEvent& e) override; void onButton(const ButtonEvent& e) override; void onDragStart(const DragStartEvent& e) override; void onDragEnd(const DragEndEvent& e) override; void onDragMove(const DragMoveEvent& e) override; + void onDragHover(const DragHoverEvent& e) override; json_t* toJson(); void fromJson(json_t* rootJ); diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index de839607..7386b371 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -309,6 +309,14 @@ void ModuleWidget::drawShadow(const DrawArgs& args) { nvgFill(args.vg); } +void ModuleWidget::onHover(const HoverEvent& e) { + if (internal->selected) { + e.consume(this); + } + + OpaqueWidget::onHover(e); +} + void ModuleWidget::onHoverKey(const HoverKeyEvent& e) { OpaqueWidget::onHoverKey(e); if (e.isConsumed()) @@ -372,6 +380,15 @@ void ModuleWidget::onHoverKey(const HoverKeyEvent& e) { } void ModuleWidget::onButton(const ButtonEvent& e) { + if (internal->selected) { + if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) { + ui::Menu* menu = createMenu(); + APP->scene->rack->appendSelectionContextMenu(menu); + } + + e.consume(this); + } + OpaqueWidget::onButton(e); if (e.getTarget() == this) { @@ -385,16 +402,10 @@ void ModuleWidget::onButton(const ButtonEvent& e) { } } - if (!e.isConsumed()) { + if (!e.isConsumed() && !internal->selected) { // Open context menu on right-click if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) { - if (internal->selected) { - ui::Menu* menu = createMenu(); - APP->scene->rack->appendSelectionContextMenu(menu); - } - else { - createContextMenu(); - } + createContextMenu(); e.consume(this); } } @@ -465,6 +476,14 @@ void ModuleWidget::onDragMove(const DragMoveEvent& e) { } } +void ModuleWidget::onDragHover(const DragHoverEvent& e) { + if (internal->selected) { + e.consume(this); + } + + OpaqueWidget::onDragHover(e); +} + json_t* ModuleWidget::toJson() { json_t* moduleJ = APP->engine->moduleToJson(module); return moduleJ;