| @@ -1,5 +1,5 @@ | |||||
| #pragma once | #pragma once | ||||
| #include "widget/OpaqueWidget.hpp" | |||||
| #include "widget/OverlayWidget.hpp" | |||||
| #include "ui/common.hpp" | #include "ui/common.hpp" | ||||
| @@ -8,7 +8,7 @@ namespace ui { | |||||
| /** Deletes itself from parent when clicked */ | /** Deletes itself from parent when clicked */ | ||||
| struct MenuOverlay : widget::OpaqueWidget { | |||||
| struct MenuOverlay : widget::OverlayWidget { | |||||
| void step() override; | void step() override; | ||||
| void onButton(const widget::ButtonEvent &e) override; | void onButton(const widget::ButtonEvent &e) override; | ||||
| void onHoverKey(const widget::HoverKeyEvent &e) override; | void onHoverKey(const widget::HoverKeyEvent &e) override; | ||||
| @@ -0,0 +1,25 @@ | |||||
| #pragma once | |||||
| #include "widget/OpaqueWidget.hpp" | |||||
| namespace rack { | |||||
| namespace widget { | |||||
| /** Like OpaqueWidget but consumes even more events. */ | |||||
| struct OverlayWidget : OpaqueWidget { | |||||
| void onHoverScroll(const HoverScrollEvent &e) override { | |||||
| Widget::onHoverScroll(e); | |||||
| if (!e.getConsumed()) | |||||
| e.consume(this); | |||||
| } | |||||
| void onPathDrop(const PathDropEvent &e) override { | |||||
| Widget::onPathDrop(e); | |||||
| if (!e.getConsumed()) | |||||
| e.consume(this); | |||||
| } | |||||
| }; | |||||
| } // namespace widget | |||||
| } // namespace rack | |||||
| @@ -11,6 +11,7 @@ namespace widget { | |||||
| struct Widget; | struct Widget; | ||||
| /** A per-event state shared and writable by all widgets that recursively handle an event. */ | |||||
| struct EventContext { | struct EventContext { | ||||
| /** The Widget that consumes the event. | /** The Widget that consumes the event. | ||||
| This stops propagation of the event if applicable. | This stops propagation of the event if applicable. | ||||
| @@ -19,7 +20,7 @@ struct EventContext { | |||||
| }; | }; | ||||
| /** Base event class */ | |||||
| /** Base class for all events. */ | |||||
| struct Event { | struct Event { | ||||
| EventContext *context = NULL; | EventContext *context = NULL; | ||||
| @@ -33,12 +34,14 @@ struct Event { | |||||
| }; | }; | ||||
| /** An Event prototype with a vector position. */ | |||||
| struct PositionEvent { | struct PositionEvent { | ||||
| /** The pixel coordinate where the event occurred, relative to the Widget it is called on. */ | /** The pixel coordinate where the event occurred, relative to the Widget it is called on. */ | ||||
| math::Vec pos; | math::Vec pos; | ||||
| }; | }; | ||||
| /** An Event prototype with a GLFW key. */ | |||||
| struct KeyEvent { | struct KeyEvent { | ||||
| /** GLFW_KEY_* */ | /** GLFW_KEY_* */ | ||||
| int key; | int key; | ||||
| @@ -50,14 +53,17 @@ struct KeyEvent { | |||||
| int mods; | int mods; | ||||
| }; | }; | ||||
| // Events | |||||
| /** An Event prototype with a Unicode character. */ | |||||
| struct TextEvent { | struct TextEvent { | ||||
| /** Unicode code point of the character */ | /** Unicode code point of the character */ | ||||
| int codepoint; | int codepoint; | ||||
| }; | }; | ||||
| // Concrete events | |||||
| /** Occurs every frame when the mouse is hovering over a Widget. | /** Occurs every frame when the mouse is hovering over a Widget. | ||||
| Recurses until consumed. | Recurses until consumed. | ||||
| If `target` is set, other events may occur on that Widget. | If `target` is set, other events may occur on that Widget. | ||||
| @@ -1,5 +1,6 @@ | |||||
| #include "app/ModuleBrowser.hpp" | #include "app/ModuleBrowser.hpp" | ||||
| #include "widget/OpaqueWidget.hpp" | #include "widget/OpaqueWidget.hpp" | ||||
| #include "widget/OverlayWidget.hpp" | |||||
| #include "widget/TransparentWidget.hpp" | #include "widget/TransparentWidget.hpp" | ||||
| #include "widget/ZoomWidget.hpp" | #include "widget/ZoomWidget.hpp" | ||||
| #include "ui/ScrollWidget.hpp" | #include "ui/ScrollWidget.hpp" | ||||
| @@ -53,16 +54,16 @@ static float modelScore(plugin::Model *model, const std::string &search) { | |||||
| } | } | ||||
| struct BrowserOverlay : widget::OpaqueWidget { | |||||
| struct BrowserOverlay : widget::OverlayWidget { | |||||
| void step() override { | void step() override { | ||||
| box = parent->box.zeroPos(); | box = parent->box.zeroPos(); | ||||
| // Only step if visible, since there are potentially thousands of descendants that don't need to be stepped. | // Only step if visible, since there are potentially thousands of descendants that don't need to be stepped. | ||||
| if (visible) | if (visible) | ||||
| OpaqueWidget::step(); | |||||
| OverlayWidget::step(); | |||||
| } | } | ||||
| void onButton(const widget::ButtonEvent &e) override { | void onButton(const widget::ButtonEvent &e) override { | ||||
| OpaqueWidget::onButton(e); | |||||
| OverlayWidget::onButton(e); | |||||
| if (e.getConsumed() != this) | if (e.getConsumed() != this) | ||||
| return; | return; | ||||