| @@ -1,5 +1,6 @@ | |||
| #pragma once | |||
| #include "event.hpp" | |||
| #include "widgets/Widget.hpp" | |||
| namespace rack { | |||
| @@ -22,6 +23,7 @@ struct WidgetState { | |||
| void handleText(math::Vec pos, int codepoint); | |||
| void handleKey(math::Vec pos, int key, int scancode, int action, int mods); | |||
| void handleDrop(math::Vec pos, std::vector<std::string> paths); | |||
| void handleZoom(); | |||
| /** Prepares a widget for deletion */ | |||
| void finalizeWidget(Widget *w); | |||
| }; | |||
| @@ -136,9 +136,9 @@ struct RackWidget : OpaqueWidget { | |||
| void step() override; | |||
| void draw(NVGcontext *vg) override; | |||
| void on(event::Hover &e) override; | |||
| void on(event::Button &e) override; | |||
| void on(event::Zoom &e) override; | |||
| void onHover(event::Hover &e) override; | |||
| void onButton(event::Button &e) override; | |||
| void onZoom(event::Zoom &e) override; | |||
| }; | |||
| struct RackRail : TransparentWidget { | |||
| @@ -175,8 +175,8 @@ struct ParamWidget : Component, QuantityWidget { | |||
| void fromJson(json_t *rootJ); | |||
| virtual void reset(); | |||
| virtual void randomize(); | |||
| void on(event::Button &e) override; | |||
| void on(event::Change &e) override; | |||
| void onButton(event::Button &e) override; | |||
| void onChange(event::Change &e) override; | |||
| }; | |||
| /** Implements vertical dragging behavior for ParamWidgets */ | |||
| @@ -187,9 +187,9 @@ struct Knob : ParamWidget { | |||
| float speed = 1.0; | |||
| float dragValue; | |||
| Knob(); | |||
| void on(event::DragStart &e) override; | |||
| void on(event::DragMove &e) override; | |||
| void on(event::DragEnd &e) override; | |||
| void onDragStart(event::DragStart &e) override; | |||
| void onDragMove(event::DragMove &e) override; | |||
| void onDragEnd(event::DragEnd &e) override; | |||
| }; | |||
| /** A knob which rotates an SVG and caches it in a framebuffer */ | |||
| @@ -203,7 +203,7 @@ struct SVGKnob : Knob, FramebufferWidget { | |||
| SVGKnob(); | |||
| void setSVG(std::shared_ptr<SVG> svg); | |||
| void step() override; | |||
| void on(event::Change &e) override; | |||
| void onChange(event::Change &e) override; | |||
| }; | |||
| /** Behaves like a knob but linearly moves an SVGWidget between two points. | |||
| @@ -218,7 +218,7 @@ struct SVGSlider : Knob, FramebufferWidget { | |||
| SVGSlider(); | |||
| void setSVGs(std::shared_ptr<SVG> backgroundSVG, std::shared_ptr<SVG> handleSVG); | |||
| void step() override; | |||
| void on(event::Change &e) override; | |||
| void onChange(event::Change &e) override; | |||
| }; | |||
| /** A ParamWidget with multiple frames corresponding to its value */ | |||
| @@ -228,12 +228,12 @@ struct SVGSwitch : virtual ParamWidget, FramebufferWidget { | |||
| SVGSwitch(); | |||
| /** Adds an SVG file to represent the next switch position */ | |||
| void addFrame(std::shared_ptr<SVG> svg); | |||
| void on(event::Change &e) override; | |||
| void onChange(event::Change &e) override; | |||
| }; | |||
| /** A switch that cycles through each mechanical position */ | |||
| struct ToggleSwitch : virtual ParamWidget { | |||
| void on(event::DragStart &e) override; | |||
| void onDragStart(event::DragStart &e) override; | |||
| }; | |||
| /** A switch that is turned on when held and turned off when released. | |||
| @@ -242,8 +242,8 @@ Consider using SVGButton if the switch simply changes the state of your Module w | |||
| struct MomentarySwitch : virtual ParamWidget { | |||
| /** Don't randomize state */ | |||
| void randomize() override {} | |||
| void on(event::DragStart &e) override; | |||
| void on(event::DragEnd &e) override; | |||
| void onDragStart(event::DragStart &e) override; | |||
| void onDragEnd(event::DragEnd &e) override; | |||
| }; | |||
| /** A Component with a default (up) and active (down) state when clicked. | |||
| @@ -257,15 +257,15 @@ struct SVGButton : Component, FramebufferWidget { | |||
| SVGButton(); | |||
| /** If `activeSVG` is NULL, `defaultSVG` is used as the active state instead. */ | |||
| void setSVGs(std::shared_ptr<SVG> defaultSVG, std::shared_ptr<SVG> activeSVG); | |||
| void on(event::DragStart &e) override; | |||
| void on(event::DragEnd &e) override; | |||
| void onDragStart(event::DragStart &e) override; | |||
| void onDragEnd(event::DragEnd &e) override; | |||
| }; | |||
| //////////////////// | |||
| // IO widgets | |||
| //////////////////// | |||
| struct LedDisplay : virtual EventWidget { | |||
| struct LedDisplay : virtual Widget { | |||
| void draw(NVGcontext *vg) override; | |||
| }; | |||
| @@ -281,7 +281,7 @@ struct LedDisplayChoice : TransparentWidget { | |||
| NVGcolor color; | |||
| LedDisplayChoice(); | |||
| void draw(NVGcontext *vg) override; | |||
| void on(event::Button &e) override; | |||
| void onButton(event::Button &e) override; | |||
| }; | |||
| struct LedDisplayTextField : TextField { | |||
| @@ -371,12 +371,12 @@ struct Port : Component { | |||
| ~Port(); | |||
| void step() override; | |||
| void draw(NVGcontext *vg) override; | |||
| void on(event::Button &e) override; | |||
| void on(event::DragStart &e) override; | |||
| void on(event::DragEnd &e) override; | |||
| void on(event::DragDrop &e) override; | |||
| void on(event::DragEnter &e) override; | |||
| void on(event::DragLeave &e) override; | |||
| void onButton(event::Button &e) override; | |||
| void onDragStart(event::DragStart &e) override; | |||
| void onDragEnd(event::DragEnd &e) override; | |||
| void onDragDrop(event::DragDrop &e) override; | |||
| void onDragEnter(event::DragEnter &e) override; | |||
| void onDragLeave(event::DragLeave &e) override; | |||
| }; | |||
| struct SVGPort : Port, FramebufferWidget { | |||
| @@ -409,7 +409,7 @@ struct Toolbar : OpaqueWidget { | |||
| void draw(NVGcontext *vg) override; | |||
| }; | |||
| struct PluginManagerWidget : virtual EventWidget { | |||
| struct PluginManagerWidget : virtual Widget { | |||
| Widget *loginWidget; | |||
| Widget *manageWidget; | |||
| Widget *downloadWidget; | |||
| @@ -428,8 +428,8 @@ struct RackScene : Scene { | |||
| RackScene(); | |||
| void step() override; | |||
| void draw(NVGcontext *vg) override; | |||
| void on(event::HoverKey &e) override; | |||
| void on(event::PathDrop &e) override; | |||
| void onHoverKey(event::HoverKey &e) override; | |||
| void onPathDrop(event::PathDrop &e) override; | |||
| }; | |||
| //////////////////// | |||
| @@ -62,12 +62,12 @@ struct ModuleWidget : OpaqueWidget { | |||
| void drawShadow(NVGcontext *vg); | |||
| math::Vec dragPos; | |||
| void on(event::Hover &e) override; | |||
| void on(event::Button &e) override; | |||
| void on(event::HoverKey &e) override; | |||
| void on(event::DragStart &e) override; | |||
| void on(event::DragEnd &e) override; | |||
| void on(event::DragMove &e) override; | |||
| void onHover(event::Hover &e) override; | |||
| void onButton(event::Button &e) override; | |||
| void onHoverKey(event::HoverKey &e) override; | |||
| void onDragStart(event::DragStart &e) override; | |||
| void onDragEnd(event::DragEnd &e) override; | |||
| void onDragMove(event::DragMove &e) override; | |||
| }; | |||
| @@ -1,12 +1,12 @@ | |||
| #pragma once | |||
| #include "math.hpp" | |||
| #include <vector> | |||
| #include "widgets/Widget.hpp" | |||
| namespace rack { | |||
| struct EventWidget; | |||
| struct Widget; | |||
| namespace event { | |||
| @@ -17,12 +17,6 @@ struct Event { | |||
| This stops propagation of the event if applicable. | |||
| */ | |||
| Widget *target = NULL; | |||
| virtual ~Event() {} | |||
| /** Triggers the event on an EventWidget. | |||
| Calls the appropriate `EventWidget::on()` method. | |||
| */ | |||
| virtual void trigger(EventWidget *w) = 0; | |||
| }; | |||
| @@ -50,10 +44,6 @@ struct Text { | |||
| }; | |||
| #define EVENT_TRIGGER_DECLARATION() void trigger(EventWidget *w) override | |||
| #define EVENT_TRIGGER_DEFINITION(_event) inline void _event::trigger(EventWidget *w) { w->on(*this); } | |||
| /** Occurs every frame when the mouse is hovering over a Widget. | |||
| Recurses until consumed. | |||
| If target is set, other events may occur on that Widget. | |||
| @@ -61,7 +51,6 @@ If target is set, other events may occur on that Widget. | |||
| struct Hover : Event, Position { | |||
| /** Change in mouse position since the last frame. Can be zero. */ | |||
| math::Vec mouseDelta; | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| @@ -76,7 +65,6 @@ struct Button : Event, Position { | |||
| int action; | |||
| /** GLFW_MOD_* */ | |||
| int mods; | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| @@ -84,7 +72,6 @@ struct Button : Event, Position { | |||
| Recurses until consumed. | |||
| */ | |||
| struct HoverKey : Event, Position, Key { | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| @@ -92,7 +79,6 @@ struct HoverKey : Event, Position, Key { | |||
| Recurses until consumed. | |||
| */ | |||
| struct HoverText : Event, Position, Text { | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| @@ -102,49 +88,42 @@ Recurses until consumed. | |||
| struct HoverScroll : Event, Position { | |||
| /** Change of scroll wheel position. */ | |||
| math::Vec scrollDelta; | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| /** Occurs when a Widget begins consuming the Hover event. | |||
| */ | |||
| struct Enter : Event { | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| /** Occurs when a different Widget is entered. | |||
| */ | |||
| struct Leave : Event { | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| /** Occurs when a Widget begins consuming the Button press event. | |||
| */ | |||
| struct Select : Event { | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| /** Occurs when a different Widget is selected. | |||
| */ | |||
| struct Deselect : Event { | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| /** Occurs when a key is pressed while a Widget is selected. | |||
| */ | |||
| struct SelectKey : Event, Key { | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| /** Occurs when text is typed while a Widget is selected. | |||
| */ | |||
| struct SelectText : Event, Text { | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| @@ -152,14 +131,12 @@ struct SelectText : Event, Text { | |||
| Must consume to allow the drag to occur. | |||
| */ | |||
| struct DragStart : Event { | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| /** Occurs when a Widget stops being dragged by releasing the mouse button. | |||
| */ | |||
| struct DragEnd : Event { | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| @@ -168,7 +145,6 @@ Called once per frame, even when mouseDelta is zero. | |||
| */ | |||
| struct DragMove : Event { | |||
| math::Vec mouseDelta; | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| @@ -176,7 +152,6 @@ struct DragMove : Event { | |||
| */ | |||
| struct DragEnter : Event { | |||
| Widget *origin = NULL; | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| @@ -184,7 +159,6 @@ struct DragEnter : Event { | |||
| */ | |||
| struct DragLeave : Event { | |||
| Widget *origin = NULL; | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| @@ -192,7 +166,6 @@ struct DragLeave : Event { | |||
| */ | |||
| struct DragDrop : Event { | |||
| Widget *origin = NULL; | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| @@ -201,21 +174,18 @@ struct DragDrop : Event { | |||
| struct PathDrop : Event, Position { | |||
| /** List of file paths in the dropped selection */ | |||
| std::vector<std::string> paths; | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| /** Occurs when an certain action is triggered on a Widget. | |||
| */ | |||
| struct Action : Event { | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| /** Occurs when the value of a Widget changes. | |||
| */ | |||
| struct Change : Event { | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| @@ -223,7 +193,6 @@ struct Change : Event { | |||
| Recurses. | |||
| */ | |||
| struct Zoom : Event { | |||
| EVENT_TRIGGER_DECLARATION(); | |||
| }; | |||
| @@ -20,26 +20,26 @@ struct Button : OpaqueWidget { | |||
| Widget::draw(vg); | |||
| } | |||
| void on(event::Enter &e) override { | |||
| void onEnter(event::Enter &e) override { | |||
| state = BND_HOVER; | |||
| } | |||
| void on(event::Leave &e) override { | |||
| void onLeave(event::Leave &e) override { | |||
| state = BND_DEFAULT; | |||
| } | |||
| void on(event::DragStart &e) override { | |||
| void onDragStart(event::DragStart &e) override { | |||
| state = BND_ACTIVE; | |||
| } | |||
| void on(event::DragEnd &e) override { | |||
| void onDragEnd(event::DragEnd &e) override { | |||
| state = BND_HOVER; | |||
| } | |||
| void on(event::DragDrop &e) override { | |||
| void onDragDrop(event::DragDrop &e) override { | |||
| if (e.origin == this) { | |||
| event::Action eAction; | |||
| handleEvent(eAction); | |||
| onAction(eAction); | |||
| } | |||
| } | |||
| }; | |||
| @@ -7,7 +7,7 @@ | |||
| namespace rack { | |||
| struct Label : virtual EventWidget { | |||
| struct Label : virtual Widget { | |||
| std::string text; | |||
| float fontSize; | |||
| NVGcolor color; | |||
| @@ -68,7 +68,7 @@ struct Menu : OpaqueWidget { | |||
| Widget::draw(vg); | |||
| } | |||
| void on(event::HoverScroll &e) override { | |||
| void onHoverScroll(event::HoverScroll &e) override { | |||
| if (!parent) | |||
| return; | |||
| if (!parent->box.contains(box)) | |||
| @@ -41,7 +41,7 @@ struct MenuItem : MenuEntry { | |||
| virtual Menu *createChildMenu() {return NULL;} | |||
| void on(event::Enter &e) override { | |||
| void onEnter(event::Enter &e) override { | |||
| Menu *parentMenu = dynamic_cast<Menu*>(parent); | |||
| if (!parentMenu) | |||
| return; | |||
| @@ -57,14 +57,14 @@ struct MenuItem : MenuEntry { | |||
| parentMenu->setChildMenu(childMenu); | |||
| } | |||
| void on(event::DragDrop &e) override { | |||
| void onDragDrop(event::DragDrop &e) override { | |||
| if (e.origin != this) | |||
| return; | |||
| event::Action eAction; | |||
| // Consume event by default, but allow action to un-consume it to prevent the menu from being removed. | |||
| eAction.target = this; | |||
| handleEvent(eAction); | |||
| onAction(eAction); | |||
| if (!eAction.target) | |||
| return; | |||
| @@ -20,8 +20,8 @@ struct MenuOverlay : OpaqueWidget { | |||
| } | |||
| } | |||
| void on(event::Button &e) override { | |||
| EventWidget::on(e); | |||
| void onButton(event::Button &e) override { | |||
| Widget::onButton(e); | |||
| if (!e.target) { | |||
| e.target = this; | |||
| @@ -29,7 +29,7 @@ struct MenuOverlay : OpaqueWidget { | |||
| } | |||
| } | |||
| void on(event::HoverKey &e) override { | |||
| void onHoverKey(event::HoverKey &e) override { | |||
| switch (e.key) { | |||
| case GLFW_KEY_ESCAPE: { | |||
| e.target = this; | |||
| @@ -38,7 +38,7 @@ struct MenuOverlay : OpaqueWidget { | |||
| } break; | |||
| } | |||
| EventWidget::on(e); | |||
| Widget::onHoverKey(e); | |||
| } | |||
| }; | |||
| @@ -18,15 +18,15 @@ struct RadioButton : OpaqueWidget, QuantityWidget { | |||
| bndRadioButton(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, value == 0.0 ? state : BND_ACTIVE, -1, label.c_str()); | |||
| } | |||
| void on(event::Enter &e) override { | |||
| void onEnter(event::Enter &e) override { | |||
| state = BND_HOVER; | |||
| } | |||
| void on(event::Leave &e) override { | |||
| void onLeave(event::Leave &e) override { | |||
| state = BND_DEFAULT; | |||
| } | |||
| void on(event::DragDrop &e) override { | |||
| void onDragDrop(event::DragDrop &e) override { | |||
| if (e.origin == this) { | |||
| if (value) | |||
| setValue(0.0); | |||
| @@ -34,7 +34,7 @@ struct RadioButton : OpaqueWidget, QuantityWidget { | |||
| setValue(1.0); | |||
| event::Action eAction; | |||
| handleEvent(eAction); | |||
| onAction(eAction); | |||
| } | |||
| } | |||
| }; | |||
| @@ -26,14 +26,14 @@ struct ScrollBar : OpaqueWidget { | |||
| bndScrollBar(vg, 0.0, 0.0, box.size.x, box.size.y, state, offset, size); | |||
| } | |||
| void on(event::DragStart &e) override { | |||
| void onDragStart(event::DragStart &e) override { | |||
| state = BND_ACTIVE; | |||
| windowCursorLock(); | |||
| } | |||
| void on(event::DragMove &e) override; | |||
| void onDragMove(event::DragMove &e) override; | |||
| void on(event::DragEnd &e) override { | |||
| void onDragEnd(event::DragEnd &e) override { | |||
| state = BND_DEFAULT; | |||
| windowCursorUnlock(); | |||
| } | |||
| @@ -109,7 +109,7 @@ struct ScrollWidget : OpaqueWidget { | |||
| verticalScrollBar->box.size.y = horizontalScrollBar->visible ? inner.y : box.size.y; | |||
| } | |||
| void on(event::Hover &e) override { | |||
| void onHover(event::Hover &e) override { | |||
| // Scroll with arrow keys | |||
| if (!gWidgetState->selectedWidget) { | |||
| float arrowSpeed = 30.0; | |||
| @@ -134,21 +134,21 @@ struct ScrollWidget : OpaqueWidget { | |||
| } | |||
| } | |||
| OpaqueWidget::on(e); | |||
| OpaqueWidget::onHover(e); | |||
| } | |||
| void on(event::HoverScroll &e) override { | |||
| void onHoverScroll(event::HoverScroll &e) override { | |||
| offset = offset.minus(e.scrollDelta); | |||
| e.target = this; | |||
| } | |||
| void on(event::HoverKey &e) override { | |||
| OpaqueWidget::on(e); | |||
| void onHoverKey(event::HoverKey &e) override { | |||
| OpaqueWidget::onHoverKey(e); | |||
| } | |||
| }; | |||
| inline void ScrollBar::on(event::DragMove &e) { | |||
| inline void ScrollBar::onDragMove(event::DragMove &e) { | |||
| ScrollWidget *scrollWidget = dynamic_cast<ScrollWidget*>(parent); | |||
| assert(scrollWidget); | |||
| if (orientation == HORIZONTAL) | |||
| @@ -7,7 +7,7 @@ namespace rack { | |||
| /** Positions children in a row/column based on their widths/heights */ | |||
| struct SequentialLayout : virtual EventWidget { | |||
| struct SequentialLayout : virtual Widget { | |||
| enum Orientation { | |||
| HORIZONTAL_ORIENTATION, | |||
| VERTICAL_ORIENTATION, | |||
| @@ -22,21 +22,21 @@ struct Slider : OpaqueWidget, QuantityWidget { | |||
| bndSlider(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, getText().c_str(), NULL); | |||
| } | |||
| void on(event::DragStart &e) override { | |||
| void onDragStart(event::DragStart &e) override { | |||
| state = BND_ACTIVE; | |||
| windowCursorLock(); | |||
| } | |||
| void on(event::DragMove &e) override { | |||
| void onDragMove(event::DragMove &e) override { | |||
| setValue(value + SLIDER_SENSITIVITY * (maxValue - minValue) * e.mouseDelta.x); | |||
| } | |||
| void on(event::DragEnd &e) override { | |||
| void onDragEnd(event::DragEnd &e) override { | |||
| state = BND_DEFAULT; | |||
| windowCursorUnlock(); | |||
| } | |||
| void on(event::Button &e) override { | |||
| void onButton(event::Button &e) override { | |||
| if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) { | |||
| setValue(defaultValue); | |||
| } | |||
| @@ -45,28 +45,28 @@ struct TextField : OpaqueWidget { | |||
| nvgResetScissor(vg); | |||
| } | |||
| void on(event::Button &e) override { | |||
| void onButton(event::Button &e) override { | |||
| if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) { | |||
| cursor = selection = getTextPosition(e.pos); | |||
| } | |||
| OpaqueWidget::on(e); | |||
| OpaqueWidget::onButton(e); | |||
| } | |||
| void on(event::Hover &e) override { | |||
| void onHover(event::Hover &e) override { | |||
| if (this == gWidgetState->draggedWidget) { | |||
| int pos = getTextPosition(e.pos); | |||
| if (pos != selection) { | |||
| cursor = pos; | |||
| } | |||
| } | |||
| OpaqueWidget::on(e); | |||
| OpaqueWidget::onHover(e); | |||
| } | |||
| void on(event::Enter &e) override { | |||
| void onEnter(event::Enter &e) override { | |||
| e.target = this; | |||
| } | |||
| void on(event::SelectText &e) override { | |||
| void onSelectText(event::SelectText &e) override { | |||
| if (e.codepoint < 128) { | |||
| std::string newText(1, (char) e.codepoint); | |||
| insertText(newText); | |||
| @@ -74,7 +74,7 @@ struct TextField : OpaqueWidget { | |||
| e.target = this; | |||
| } | |||
| void on(event::SelectKey &e) override { | |||
| void onSelectKey(event::SelectKey &e) override { | |||
| switch (e.key) { | |||
| case GLFW_KEY_BACKSPACE: { | |||
| if (cursor == selection) { | |||
| @@ -82,7 +82,7 @@ struct TextField : OpaqueWidget { | |||
| if (cursor >= 0) { | |||
| text.erase(cursor, 1); | |||
| event::Change eChange; | |||
| handleEvent(eChange); | |||
| onChange(eChange); | |||
| } | |||
| selection = cursor; | |||
| } | |||
| @@ -90,7 +90,7 @@ struct TextField : OpaqueWidget { | |||
| int begin = std::min(cursor, selection); | |||
| text.erase(begin, std::abs(selection - cursor)); | |||
| event::Change eChange; | |||
| handleEvent(eChange); | |||
| onChange(eChange); | |||
| cursor = selection = begin; | |||
| } | |||
| } break; | |||
| @@ -98,13 +98,13 @@ struct TextField : OpaqueWidget { | |||
| if (cursor == selection) { | |||
| text.erase(cursor, 1); | |||
| event::Change eChange; | |||
| handleEvent(eChange); | |||
| onChange(eChange); | |||
| } | |||
| else { | |||
| int begin = std::min(cursor, selection); | |||
| text.erase(begin, std::abs(selection - cursor)); | |||
| event::Change eChange; | |||
| handleEvent(eChange); | |||
| onChange(eChange); | |||
| cursor = selection = begin; | |||
| } | |||
| } break; | |||
| @@ -180,7 +180,7 @@ struct TextField : OpaqueWidget { | |||
| } | |||
| else { | |||
| event::Action eAction; | |||
| handleEvent(eAction); | |||
| onAction(eAction); | |||
| } | |||
| } break; | |||
| } | |||
| @@ -201,7 +201,7 @@ struct TextField : OpaqueWidget { | |||
| cursor += text.size(); | |||
| selection = cursor; | |||
| event::Change eChange; | |||
| handleEvent(eChange); | |||
| onChange(eChange); | |||
| } | |||
| /** Replaces the entire text */ | |||
| @@ -209,7 +209,7 @@ struct TextField : OpaqueWidget { | |||
| this->text = text; | |||
| selection = cursor = text.size(); | |||
| event::Change eChange; | |||
| handleEvent(eChange); | |||
| onChange(eChange); | |||
| } | |||
| virtual int getTextPosition(math::Vec mousePos) { | |||
| @@ -7,7 +7,7 @@ | |||
| namespace rack { | |||
| struct Tooltip : virtual EventWidget { | |||
| struct Tooltip : virtual Widget { | |||
| std::string text; | |||
| void draw(NVGcontext *vg) override { | |||
| @@ -15,7 +15,7 @@ struct WindowWidget : OpaqueWidget { | |||
| Widget::draw(vg); | |||
| } | |||
| void on(event::DragMove &e) override { | |||
| void onDragMove(event::DragMove &e) override { | |||
| box.pos = box.pos.plus(e.mouseDelta); | |||
| } | |||
| }; | |||
| @@ -1,7 +1,6 @@ | |||
| #pragma once | |||
| #include "widgets/Widget.hpp" | |||
| #include "widgets/EventWidget.hpp" | |||
| #include "widgets/TransparentWidget.hpp" | |||
| #include "widgets/OpaqueWidget.hpp" | |||
| #include "widgets/TransformWidget.hpp" | |||
| @@ -1,90 +0,0 @@ | |||
| #pragma once | |||
| #include "widgets/Widget.hpp" | |||
| #include "event.hpp" | |||
| namespace rack { | |||
| /** A widget that responds to events */ | |||
| struct EventWidget : Widget { | |||
| void handleEvent(event::Event &e) override { | |||
| // Call visitor's visit method | |||
| e.trigger(this); | |||
| } | |||
| template <class TEvent> | |||
| void recurseEvent(TEvent &e) { | |||
| for (auto it = children.rbegin(); it != children.rend(); it++) { | |||
| Widget *child = *it; | |||
| if (!child->visible) | |||
| continue; | |||
| if (!child->box.contains(e.pos)) | |||
| continue; | |||
| // Clone event so modifications do not up-propagate | |||
| TEvent e2 = e; | |||
| e2.pos = e.pos.minus(child->box.pos); | |||
| child->handleEvent(e2); | |||
| // Up-propagate target if consumed | |||
| if (e2.target) { | |||
| e.target = e2.target; | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| /** Override these event callbacks to respond to events. | |||
| See events.hpp for a description of each event. | |||
| */ | |||
| virtual void on(event::Hover &e) {recurseEvent(e);} | |||
| virtual void on(event::Button &e) {recurseEvent(e);} | |||
| virtual void on(event::HoverKey &e) {recurseEvent(e);} | |||
| virtual void on(event::HoverText &e) {recurseEvent(e);} | |||
| virtual void on(event::HoverScroll &e) {recurseEvent(e);} | |||
| virtual void on(event::Enter &e) {} | |||
| virtual void on(event::Leave &e) {} | |||
| virtual void on(event::Select &e) {} | |||
| virtual void on(event::Deselect &e) {} | |||
| virtual void on(event::SelectKey &e) {} | |||
| virtual void on(event::SelectText &e) {} | |||
| virtual void on(event::DragStart &e) {} | |||
| virtual void on(event::DragEnd &e) {} | |||
| virtual void on(event::DragMove &e) {} | |||
| virtual void on(event::DragEnter &e) {} | |||
| virtual void on(event::DragLeave &e) {} | |||
| virtual void on(event::DragDrop &e) {} | |||
| virtual void on(event::PathDrop &e) {recurseEvent(e);} | |||
| virtual void on(event::Action &e) {} | |||
| virtual void on(event::Change &e) {} | |||
| virtual void on(event::Zoom &e) {} | |||
| }; | |||
| /** These definitions simply call each `EventWidget::on()` function above. | |||
| They need to be defined here because EventWidget is not defined at the time of each event's definition. | |||
| */ | |||
| EVENT_TRIGGER_DEFINITION(event::Hover) | |||
| EVENT_TRIGGER_DEFINITION(event::Button) | |||
| EVENT_TRIGGER_DEFINITION(event::HoverKey) | |||
| EVENT_TRIGGER_DEFINITION(event::HoverText) | |||
| EVENT_TRIGGER_DEFINITION(event::HoverScroll) | |||
| EVENT_TRIGGER_DEFINITION(event::Enter) | |||
| EVENT_TRIGGER_DEFINITION(event::Leave) | |||
| EVENT_TRIGGER_DEFINITION(event::Select) | |||
| EVENT_TRIGGER_DEFINITION(event::Deselect) | |||
| EVENT_TRIGGER_DEFINITION(event::SelectKey) | |||
| EVENT_TRIGGER_DEFINITION(event::SelectText) | |||
| EVENT_TRIGGER_DEFINITION(event::DragStart) | |||
| EVENT_TRIGGER_DEFINITION(event::DragEnd) | |||
| EVENT_TRIGGER_DEFINITION(event::DragMove) | |||
| EVENT_TRIGGER_DEFINITION(event::DragEnter) | |||
| EVENT_TRIGGER_DEFINITION(event::DragLeave) | |||
| EVENT_TRIGGER_DEFINITION(event::DragDrop) | |||
| EVENT_TRIGGER_DEFINITION(event::PathDrop) | |||
| EVENT_TRIGGER_DEFINITION(event::Action) | |||
| EVENT_TRIGGER_DEFINITION(event::Change) | |||
| EVENT_TRIGGER_DEFINITION(event::Zoom) | |||
| } // namespace rack | |||
| @@ -1,5 +1,5 @@ | |||
| #pragma once | |||
| #include "widgets/EventWidget.hpp" | |||
| #include "widgets/Widget.hpp" | |||
| namespace rack { | |||
| @@ -9,7 +9,7 @@ namespace rack { | |||
| When `dirty` is true, its children will be re-rendered on the next call to step() override. | |||
| Events are not passed to the underlying scene. | |||
| */ | |||
| struct FramebufferWidget : virtual EventWidget { | |||
| struct FramebufferWidget : virtual Widget { | |||
| /** Set this to true to re-render the children to the framebuffer the next time it is drawn */ | |||
| bool dirty = true; | |||
| /** A margin in pixels around the children in the framebuffer | |||
| @@ -27,9 +27,9 @@ struct FramebufferWidget : virtual EventWidget { | |||
| void draw(NVGcontext *vg) override; | |||
| int getImageHandle(); | |||
| void on(event::Zoom &e) override { | |||
| void onZoom(event::Zoom &e) override { | |||
| dirty = true; | |||
| EventWidget::on(e); | |||
| Widget::onZoom(e); | |||
| } | |||
| }; | |||
| @@ -1,5 +1,5 @@ | |||
| #pragma once | |||
| #include "widgets/EventWidget.hpp" | |||
| #include "widgets/Widget.hpp" | |||
| namespace rack { | |||
| @@ -7,23 +7,44 @@ namespace rack { | |||
| /** Widget that consumes recursing events but gives a chance for children to consume first. | |||
| You can of course override the events. | |||
| You may also call OpaqueWidget::on() from the overridden method to continue recursing/consuming the event. | |||
| You may also call OpaqueWidget::on*() from the overridden method to continue recursing/consuming the event. | |||
| */ | |||
| struct OpaqueWidget : virtual EventWidget { | |||
| template <class TEvent> | |||
| void consumeEvent(TEvent &e) { | |||
| EventWidget::on(e); | |||
| if (!e.target) { | |||
| struct OpaqueWidget : virtual Widget { | |||
| void onHover(event::Hover &e) override { | |||
| Widget::onHover(e); | |||
| if (!e.target) | |||
| e.target = this; | |||
| } | |||
| } | |||
| void on(event::Hover &e) override {consumeEvent(e);} | |||
| void on(event::Button &e) override {consumeEvent(e);} | |||
| void on(event::HoverKey &e) override {consumeEvent(e);} | |||
| void on(event::HoverText &e) override {consumeEvent(e);} | |||
| // void on(event::HoverScroll &e) override {consumeEvent(e);} | |||
| void on(event::PathDrop &e) override {consumeEvent(e);} | |||
| void onButton(event::Button &e) override { | |||
| Widget::onButton(e); | |||
| if (!e.target) | |||
| e.target = this; | |||
| } | |||
| void onHoverKey(event::HoverKey &e) override { | |||
| Widget::onHoverKey(e); | |||
| if (!e.target) | |||
| e.target = this; | |||
| } | |||
| void onHoverText(event::HoverText &e) override { | |||
| Widget::onHoverText(e); | |||
| if (!e.target) | |||
| e.target = this; | |||
| } | |||
| // void onHoverScroll(event::HoverScroll &e) override { | |||
| // Widget::onHoverScroll(e); | |||
| // if (!e.target) | |||
| // e.target = this; | |||
| // } | |||
| void onPathDrop(event::PathDrop &e) override { | |||
| Widget::onPathDrop(e); | |||
| if (!e.target) | |||
| e.target = this; | |||
| } | |||
| }; | |||
| @@ -1,12 +1,12 @@ | |||
| #pragma once | |||
| #include "widgets/EventWidget.hpp" | |||
| #include "widgets/Widget.hpp" | |||
| namespace rack { | |||
| /** A Widget representing a float value */ | |||
| struct QuantityWidget : virtual EventWidget { | |||
| struct QuantityWidget : virtual Widget { | |||
| float value = 0.0; | |||
| float minValue = 0.0; | |||
| float maxValue = 1.0; | |||
| @@ -26,7 +26,7 @@ struct QuantityWidget : virtual EventWidget { | |||
| void setValue(float value) { | |||
| this->value = math::clampBetween(value, minValue, maxValue); | |||
| event::Change e; | |||
| on(e); | |||
| onChange(e); | |||
| } | |||
| void setLimits(float minValue, float maxValue) { | |||
| @@ -1,12 +1,12 @@ | |||
| #pragma once | |||
| #include "widgets/EventWidget.hpp" | |||
| #include "widgets/Widget.hpp" | |||
| namespace rack { | |||
| /** Draws an SVG */ | |||
| struct SVGWidget : virtual EventWidget { | |||
| struct SVGWidget : virtual Widget { | |||
| std::shared_ptr<SVG> svg; | |||
| /** Sets the box size to the svg image size */ | |||
| @@ -1,12 +1,12 @@ | |||
| #pragma once | |||
| #include "widgets/EventWidget.hpp" | |||
| #include "widgets/Widget.hpp" | |||
| namespace rack { | |||
| /** Transforms appearance only, not positions of events */ | |||
| struct TransformWidget : virtual EventWidget { | |||
| struct TransformWidget : virtual Widget { | |||
| /** The transformation matrix */ | |||
| float transform[6]; | |||
| @@ -1,19 +1,19 @@ | |||
| #pragma once | |||
| #include "widgets/EventWidget.hpp" | |||
| #include "widgets/Widget.hpp" | |||
| namespace rack { | |||
| /** Widget that does not respond to events and does not pass events to children */ | |||
| struct TransparentWidget : virtual EventWidget { | |||
| struct TransparentWidget : virtual Widget { | |||
| /** Override behavior to do nothing instead. */ | |||
| void on(event::Hover &e) override {} | |||
| void on(event::Button &e) override {} | |||
| void on(event::HoverKey &e) override {} | |||
| void on(event::HoverText &e) override {} | |||
| void on(event::HoverScroll &e) override {} | |||
| void on(event::PathDrop &e) override {} | |||
| void onHover(event::Hover &e) override {} | |||
| void onButton(event::Button &e) override {} | |||
| void onHoverKey(event::HoverKey &e) override {} | |||
| void onHoverText(event::HoverText &e) override {} | |||
| void onHoverScroll(event::HoverScroll &e) override {} | |||
| void onPathDrop(event::PathDrop &e) override {} | |||
| }; | |||
| @@ -4,6 +4,7 @@ | |||
| #include "math.hpp" | |||
| #include "window.hpp" | |||
| #include "color.hpp" | |||
| #include "event.hpp" | |||
| namespace rack { | |||
| @@ -16,7 +17,10 @@ struct Event; | |||
| } // namespace event | |||
| /** A node in the 2D scene graph */ | |||
| /** A node in the 2D scene graph | |||
| It is recommended to inherit virtually from Widget instead of directly. | |||
| e.g. `struct MyWidget : virtual Widget {}` | |||
| */ | |||
| struct Widget { | |||
| /** Stores position and size */ | |||
| math::Rect box = math::Rect(math::Vec(), math::Vec(INFINITY, INFINITY)); | |||
| @@ -75,10 +79,55 @@ struct Widget { | |||
| /** Draws to NanoVG context */ | |||
| virtual void draw(NVGcontext *vg); | |||
| /** Trigger an event on this Widget. */ | |||
| virtual void handleEvent(event::Event &e) { | |||
| // Basic widgets do not handle events, but the EventWidget subclass does. | |||
| // Events | |||
| template <typename TMethod, class TEvent> | |||
| void recursePositionEvent(TMethod f, TEvent &e) { | |||
| for (auto it = children.rbegin(); it != children.rend(); it++) { | |||
| Widget *child = *it; | |||
| // Filter child by visibility and position | |||
| if (!child->visible) | |||
| continue; | |||
| if (!child->box.contains(e.pos)) | |||
| continue; | |||
| // Clone event so modifications do not up-propagate | |||
| TEvent e2 = e; | |||
| e2.pos = e.pos.minus(child->box.pos); | |||
| // Call child event handler | |||
| (child->*f)(e2); | |||
| // Up-propagate target if consumed | |||
| if (e2.target) { | |||
| e.target = e2.target; | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| /** Override these event callbacks to respond to events. | |||
| See events.hpp for a description of each event. | |||
| */ | |||
| virtual void onHover(event::Hover &e) {recursePositionEvent(&Widget::onHover, e);} | |||
| virtual void onButton(event::Button &e) {recursePositionEvent(&Widget::onButton, e);} | |||
| virtual void onHoverKey(event::HoverKey &e) {recursePositionEvent(&Widget::onHoverKey, e);} | |||
| virtual void onHoverText(event::HoverText &e) {recursePositionEvent(&Widget::onHoverText, e);} | |||
| virtual void onHoverScroll(event::HoverScroll &e) {recursePositionEvent(&Widget::onHoverScroll, e);} | |||
| virtual void onEnter(event::Enter &e) {} | |||
| virtual void onLeave(event::Leave &e) {} | |||
| virtual void onSelect(event::Select &e) {} | |||
| virtual void onDeselect(event::Deselect &e) {} | |||
| virtual void onSelectKey(event::SelectKey &e) {} | |||
| virtual void onSelectText(event::SelectText &e) {} | |||
| virtual void onDragStart(event::DragStart &e) {} | |||
| virtual void onDragEnd(event::DragEnd &e) {} | |||
| virtual void onDragMove(event::DragMove &e) {} | |||
| virtual void onDragEnter(event::DragEnter &e) {} | |||
| virtual void onDragLeave(event::DragLeave &e) {} | |||
| virtual void onDragDrop(event::DragDrop &e) {} | |||
| virtual void onPathDrop(event::PathDrop &e) {recursePositionEvent(&Widget::onPathDrop, e);} | |||
| virtual void onAction(event::Action &e) {} | |||
| virtual void onChange(event::Change &e) {} | |||
| virtual void onZoom(event::Zoom &e) {} | |||
| }; | |||
| @@ -1,11 +1,11 @@ | |||
| #pragma once | |||
| #include "widgets/EventWidget.hpp" | |||
| #include "widgets/Widget.hpp" | |||
| namespace rack { | |||
| struct ZoomWidget : virtual EventWidget { | |||
| struct ZoomWidget : virtual Widget { | |||
| float zoom = 1.f; | |||
| math::Vec getRelativeOffset(math::Vec v, Widget *relative) override { | |||
| @@ -24,7 +24,7 @@ struct ZoomWidget : virtual EventWidget { | |||
| void setZoom(float zoom) { | |||
| if (zoom != this->zoom) { | |||
| event::Zoom eZoom; | |||
| EventWidget::on(eZoom); | |||
| Widget::onZoom(eZoom); | |||
| } | |||
| this->zoom = zoom; | |||
| } | |||
| @@ -35,40 +35,40 @@ struct ZoomWidget : virtual EventWidget { | |||
| Widget::draw(vg); | |||
| } | |||
| void on(event::Hover &e) override { | |||
| void onHover(event::Hover &e) override { | |||
| event::Hover e2 = e; | |||
| e2.pos = e.pos.div(zoom); | |||
| EventWidget::on(e2); | |||
| Widget::onHover(e2); | |||
| } | |||
| void on(event::Button &e) override { | |||
| void onButton(event::Button &e) override { | |||
| event::Button e2 = e; | |||
| e2.pos = e.pos.div(zoom); | |||
| EventWidget::on(e2); | |||
| Widget::onButton(e2); | |||
| } | |||
| void on(event::HoverKey &e) override { | |||
| void onHoverKey(event::HoverKey &e) override { | |||
| event::HoverKey e2 = e; | |||
| e2.pos = e.pos.div(zoom); | |||
| EventWidget::on(e2); | |||
| Widget::onHoverKey(e2); | |||
| } | |||
| void on(event::HoverText &e) override { | |||
| void onHoverText(event::HoverText &e) override { | |||
| event::HoverText e2 = e; | |||
| e2.pos = e.pos.div(zoom); | |||
| EventWidget::on(e2); | |||
| Widget::onHoverText(e2); | |||
| } | |||
| void on(event::HoverScroll &e) override { | |||
| void onHoverScroll(event::HoverScroll &e) override { | |||
| event::HoverScroll e2 = e; | |||
| e2.pos = e.pos.div(zoom); | |||
| EventWidget::on(e2); | |||
| Widget::onHoverScroll(e2); | |||
| } | |||
| void on(event::PathDrop &e) override { | |||
| void onPathDrop(event::PathDrop &e) override { | |||
| event::PathDrop e2 = e; | |||
| e2.pos = e.pos.div(zoom); | |||
| EventWidget::on(e2); | |||
| Widget::onPathDrop(e2); | |||
| } | |||
| }; | |||
| @@ -3,25 +3,25 @@ | |||
| using namespace rack; | |||
| struct ModuleResizeHandle : EventWidget { | |||
| struct ModuleResizeHandle : virtual Widget { | |||
| bool right = false; | |||
| float dragX; | |||
| Rect originalBox; | |||
| ModuleResizeHandle() { | |||
| box.size = Vec(RACK_GRID_WIDTH * 1, RACK_GRID_HEIGHT); | |||
| } | |||
| void on(event::Hover &e) override { | |||
| void onHover(event::Hover &e) override { | |||
| // TODO | |||
| // if (e.button == 0) { | |||
| // e.target = this; | |||
| // } | |||
| } | |||
| void on(event::DragStart &e) override { | |||
| void onDragStart(event::DragStart &e) override { | |||
| dragX = gRackWidget->lastMousePos.x; | |||
| ModuleWidget *m = getAncestorOfType<ModuleWidget>(); | |||
| originalBox = m->box; | |||
| } | |||
| void on(event::DragMove &e) override { | |||
| void onDragMove(event::DragMove &e) override { | |||
| ModuleWidget *m = getAncestorOfType<ModuleWidget>(); | |||
| float newDragX = gRackWidget->lastMousePos.x; | |||
| @@ -135,20 +135,20 @@ struct MidiCcChoice : GridChoice { | |||
| } | |||
| } | |||
| void on(event::Select &e) override { | |||
| void onSelect(event::Select &e) override { | |||
| e.target = this; | |||
| module->learningId = id; | |||
| focusCc = -1; | |||
| } | |||
| void on(event::Deselect &e) override { | |||
| void onDeselect(event::Deselect &e) override { | |||
| if (0 <= focusCc && focusCc < 128) { | |||
| module->learnedCcs[id] = focusCc; | |||
| } | |||
| module->learningId = -1; | |||
| } | |||
| void on(event::SelectText &e) override { | |||
| void onSelectText(event::SelectText &e) override { | |||
| char c = e.codepoint; | |||
| if ('0' <= c && c <= '9') { | |||
| if (focusCc < 0) | |||
| @@ -158,11 +158,11 @@ struct MidiCcChoice : GridChoice { | |||
| e.target = this; | |||
| } | |||
| void on(event::SelectKey &e) override { | |||
| void onSelectKey(event::SelectKey &e) override { | |||
| if (gWidgetState->selectedWidget == this) { | |||
| if (e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER) { | |||
| event::Deselect eDeselect; | |||
| handleEvent(eDeselect); | |||
| onDeselect(eDeselect); | |||
| gWidgetState->selectedWidget = NULL; | |||
| e.target = this; | |||
| } | |||
| @@ -292,7 +292,7 @@ struct MIDIToCVInterfaceWidget : ModuleWidget { | |||
| MIDIToCVInterface *module; | |||
| int index; | |||
| int division; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| module->divisions[index] = division; | |||
| } | |||
| }; | |||
| @@ -177,12 +177,12 @@ struct MidiTrigChoice : GridChoice { | |||
| } | |||
| } | |||
| void on(event::Select &e) override { | |||
| void onSelect(event::Select &e) override { | |||
| e.target = this; | |||
| module->learningId = id; | |||
| } | |||
| void on(event::Deselect &e) override { | |||
| void onDeselect(event::Deselect &e) override { | |||
| module->learningId = -1; | |||
| } | |||
| }; | |||
| @@ -237,7 +237,7 @@ struct MIDITriggerToCVInterfaceWidget : ModuleWidget { | |||
| struct VelocityItem : MenuItem { | |||
| MIDITriggerToCVInterface *module; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| module->velocity ^= true; | |||
| } | |||
| }; | |||
| @@ -337,7 +337,7 @@ struct QuadMIDIToCVInterfaceWidget : ModuleWidget { | |||
| struct PolyphonyItem : MenuItem { | |||
| QuadMIDIToCVInterface *module; | |||
| QuadMIDIToCVInterface::PolyMode polyMode; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| module->polyMode = polyMode; | |||
| module->onReset(); | |||
| } | |||
| @@ -11,14 +11,14 @@ void WidgetState::handleButton(math::Vec pos, int button, int action, int mods) | |||
| eButton.button = button; | |||
| eButton.action = action; | |||
| eButton.mods = mods; | |||
| rootWidget->handleEvent(eButton); | |||
| rootWidget->onButton(eButton); | |||
| Widget *clickedWidget = eButton.target; | |||
| if (button == GLFW_MOUSE_BUTTON_LEFT) { | |||
| // Drag events | |||
| if (action == GLFW_PRESS && !draggedWidget && clickedWidget) { | |||
| event::DragStart eDragStart; | |||
| clickedWidget->handleEvent(eDragStart); | |||
| clickedWidget->onDragStart(eDragStart); | |||
| draggedWidget = clickedWidget; | |||
| } | |||
| @@ -26,11 +26,11 @@ void WidgetState::handleButton(math::Vec pos, int button, int action, int mods) | |||
| if (clickedWidget) { | |||
| event::DragDrop eDragDrop; | |||
| eDragDrop.origin = draggedWidget; | |||
| clickedWidget->handleEvent(eDragDrop); | |||
| clickedWidget->onDragDrop(eDragDrop); | |||
| } | |||
| event::DragEnd eDragEnd; | |||
| draggedWidget->handleEvent(eDragEnd); | |||
| draggedWidget->onDragEnd(eDragEnd); | |||
| draggedWidget = NULL; | |||
| } | |||
| @@ -38,14 +38,14 @@ void WidgetState::handleButton(math::Vec pos, int button, int action, int mods) | |||
| if (action == GLFW_PRESS && clickedWidget != selectedWidget) { | |||
| if (selectedWidget) { | |||
| event::Deselect eDeselect; | |||
| selectedWidget->handleEvent(eDeselect); | |||
| selectedWidget->onDeselect(eDeselect); | |||
| } | |||
| selectedWidget = clickedWidget; | |||
| if (selectedWidget) { | |||
| event::Select eSelect; | |||
| selectedWidget->handleEvent(eSelect); | |||
| selectedWidget->onSelect(eSelect); | |||
| } | |||
| } | |||
| } | |||
| @@ -66,7 +66,7 @@ void WidgetState::handleHover(math::Vec pos, math::Vec mouseDelta) { | |||
| if (draggedWidget) { | |||
| event::DragMove eDragMove; | |||
| eDragMove.mouseDelta = mouseDelta; | |||
| draggedWidget->handleEvent(eDragMove); | |||
| draggedWidget->onDragMove(eDragMove); | |||
| return; | |||
| } | |||
| @@ -74,27 +74,27 @@ void WidgetState::handleHover(math::Vec pos, math::Vec mouseDelta) { | |||
| // event::HoverScroll eHoverScroll; | |||
| // eHoverScroll.pos = pos; | |||
| // eHoverScroll.scrollDelta = scrollDelta; | |||
| // rootWidget->handleEvent(eHoverScroll); | |||
| // rootWidget->onHoverScroll(eHoverScroll); | |||
| // } | |||
| // Hover event | |||
| event::Hover eHover; | |||
| eHover.pos = pos; | |||
| eHover.mouseDelta = mouseDelta; | |||
| rootWidget->handleEvent(eHover); | |||
| rootWidget->onHover(eHover); | |||
| Widget *newHoveredWidget = eHover.target; | |||
| if (newHoveredWidget != hoveredWidget) { | |||
| if (hoveredWidget) { | |||
| event::Leave eLeave; | |||
| hoveredWidget->handleEvent(eLeave); | |||
| hoveredWidget->onLeave(eLeave); | |||
| } | |||
| hoveredWidget = newHoveredWidget; | |||
| if (hoveredWidget) { | |||
| event::Enter eEnter; | |||
| hoveredWidget->handleEvent(eEnter); | |||
| hoveredWidget->onEnter(eEnter); | |||
| } | |||
| } | |||
| } | |||
| @@ -103,7 +103,7 @@ void WidgetState::handleLeave() { | |||
| if (hoveredWidget) { | |||
| // Leave event | |||
| event::Leave eLeave; | |||
| hoveredWidget->handleEvent(eLeave); | |||
| hoveredWidget->onLeave(eLeave); | |||
| } | |||
| hoveredWidget = NULL; | |||
| } | |||
| @@ -113,7 +113,7 @@ void WidgetState::handleScroll(math::Vec pos, math::Vec scrollDelta) { | |||
| event::HoverScroll eHoverScroll; | |||
| eHoverScroll.pos = pos; | |||
| eHoverScroll.scrollDelta = scrollDelta; | |||
| rootWidget->handleEvent(eHoverScroll); | |||
| rootWidget->onHoverScroll(eHoverScroll); | |||
| } | |||
| void WidgetState::handleDrop(math::Vec pos, std::vector<std::string> paths) { | |||
| @@ -121,7 +121,7 @@ void WidgetState::handleDrop(math::Vec pos, std::vector<std::string> paths) { | |||
| event::PathDrop ePathDrop; | |||
| ePathDrop.pos = pos; | |||
| ePathDrop.paths = paths; | |||
| rootWidget->handleEvent(ePathDrop); | |||
| rootWidget->onPathDrop(ePathDrop); | |||
| } | |||
| void WidgetState::handleText(math::Vec pos, int codepoint) { | |||
| @@ -129,7 +129,7 @@ void WidgetState::handleText(math::Vec pos, int codepoint) { | |||
| // SelectText event | |||
| event::SelectText eSelectText; | |||
| eSelectText.codepoint = codepoint; | |||
| selectedWidget->handleEvent(eSelectText); | |||
| selectedWidget->onSelectText(eSelectText); | |||
| if (eSelectText.target) | |||
| return; | |||
| } | |||
| @@ -138,7 +138,7 @@ void WidgetState::handleText(math::Vec pos, int codepoint) { | |||
| event::HoverText eHoverText; | |||
| eHoverText.pos = pos; | |||
| eHoverText.codepoint = codepoint; | |||
| rootWidget->handleEvent(eHoverText); | |||
| rootWidget->onHoverText(eHoverText); | |||
| } | |||
| void WidgetState::handleKey(math::Vec pos, int key, int scancode, int action, int mods) { | |||
| @@ -148,7 +148,7 @@ void WidgetState::handleKey(math::Vec pos, int key, int scancode, int action, in | |||
| eSelectKey.scancode = scancode; | |||
| eSelectKey.action = action; | |||
| eSelectKey.mods = mods; | |||
| selectedWidget->handleEvent(eSelectKey); | |||
| selectedWidget->onSelectKey(eSelectKey); | |||
| if (eSelectKey.target) | |||
| return; | |||
| } | |||
| @@ -159,7 +159,7 @@ void WidgetState::handleKey(math::Vec pos, int key, int scancode, int action, in | |||
| eHoverKey.scancode = scancode; | |||
| eHoverKey.action = action; | |||
| eHoverKey.mods = mods; | |||
| rootWidget->handleEvent(eHoverKey); | |||
| rootWidget->onHoverKey(eHoverKey); | |||
| } | |||
| void WidgetState::finalizeWidget(Widget *w) { | |||
| @@ -170,6 +170,10 @@ void WidgetState::finalizeWidget(Widget *w) { | |||
| if (scrollWidget == w) scrollWidget = NULL; | |||
| } | |||
| void WidgetState::handleZoom() { | |||
| event::Zoom eZoom; | |||
| rootWidget->onZoom(eZoom); | |||
| } | |||
| // TODO Move this elsewhere | |||
| @@ -9,14 +9,14 @@ namespace rack { | |||
| struct AudioDriverItem : MenuItem { | |||
| AudioIO *audioIO; | |||
| int driver; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| audioIO->setDriver(driver); | |||
| } | |||
| }; | |||
| struct AudioDriverChoice : LedDisplayChoice { | |||
| AudioWidget *audioWidget; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| Menu *menu = createMenu(); | |||
| menu->addChild(createMenuLabel("Audio driver")); | |||
| for (int driver : audioWidget->audioIO->getDrivers()) { | |||
| @@ -38,7 +38,7 @@ struct AudioDeviceItem : MenuItem { | |||
| AudioIO *audioIO; | |||
| int device; | |||
| int offset; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| audioIO->setDevice(device, offset); | |||
| } | |||
| }; | |||
| @@ -48,7 +48,7 @@ struct AudioDeviceChoice : LedDisplayChoice { | |||
| /** Prevents devices with a ridiculous number of channels from being displayed */ | |||
| int maxTotalChannels = 128; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| Menu *menu = createMenu(); | |||
| menu->addChild(createMenuLabel("Audio device")); | |||
| int deviceCount = audioWidget->audioIO->getDeviceCount(); | |||
| @@ -89,14 +89,14 @@ struct AudioDeviceChoice : LedDisplayChoice { | |||
| struct AudioSampleRateItem : MenuItem { | |||
| AudioIO *audioIO; | |||
| int sampleRate; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| audioIO->setSampleRate(sampleRate); | |||
| } | |||
| }; | |||
| struct AudioSampleRateChoice : LedDisplayChoice { | |||
| AudioWidget *audioWidget; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| Menu *menu = createMenu(); | |||
| menu->addChild(createMenuLabel("Sample rate")); | |||
| std::vector<int> sampleRates = audioWidget->audioIO->getSampleRates(); | |||
| @@ -121,14 +121,14 @@ struct AudioSampleRateChoice : LedDisplayChoice { | |||
| struct AudioBlockSizeItem : MenuItem { | |||
| AudioIO *audioIO; | |||
| int blockSize; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| audioIO->setBlockSize(blockSize); | |||
| } | |||
| }; | |||
| struct AudioBlockSizeChoice : LedDisplayChoice { | |||
| AudioWidget *audioWidget; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| Menu *menu = createMenu(); | |||
| menu->addChild(createMenuLabel("Block size")); | |||
| std::vector<int> blockSizes = audioWidget->audioIO->getBlockSizes(); | |||
| @@ -15,13 +15,13 @@ Knob::Knob() { | |||
| smooth = true; | |||
| } | |||
| void Knob::on(event::DragStart &e) { | |||
| void Knob::onDragStart(event::DragStart &e) { | |||
| windowCursorLock(); | |||
| dragValue = value; | |||
| randomizable = false; | |||
| } | |||
| void Knob::on(event::DragMove &e) { | |||
| void Knob::onDragMove(event::DragMove &e) { | |||
| float range; | |||
| if (std::isfinite(minValue) && std::isfinite(maxValue)) { | |||
| range = maxValue - minValue; | |||
| @@ -43,7 +43,7 @@ void Knob::on(event::DragMove &e) { | |||
| setValue(dragValue); | |||
| } | |||
| void Knob::on(event::DragEnd &e) { | |||
| void Knob::onDragEnd(event::DragEnd &e) { | |||
| windowCursorUnlock(); | |||
| randomizable = true; | |||
| } | |||
| @@ -53,10 +53,10 @@ void LedDisplayChoice::draw(NVGcontext *vg) { | |||
| nvgResetScissor(vg); | |||
| } | |||
| void LedDisplayChoice::on(event::Button &e) { | |||
| void LedDisplayChoice::onButton(event::Button &e) { | |||
| if (e.action == GLFW_PRESS && (e.button == GLFW_MOUSE_BUTTON_LEFT || e.button == GLFW_MOUSE_BUTTON_RIGHT)) { | |||
| event::Action eAction; | |||
| handleEvent(eAction); | |||
| onAction(eAction); | |||
| e.target = this; | |||
| } | |||
| } | |||
| @@ -9,14 +9,14 @@ namespace rack { | |||
| struct MidiDriverItem : MenuItem { | |||
| MidiIO *midiIO; | |||
| int driverId; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| midiIO->setDriverId(driverId); | |||
| } | |||
| }; | |||
| struct MidiDriverChoice : LedDisplayChoice { | |||
| MidiWidget *midiWidget; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| Menu *menu = createMenu(); | |||
| menu->addChild(createMenuLabel("MIDI driver")); | |||
| for (int driverId : midiWidget->midiIO->getDriverIds()) { | |||
| @@ -43,14 +43,14 @@ struct MidiDriverChoice : LedDisplayChoice { | |||
| struct MidiDeviceItem : MenuItem { | |||
| MidiIO *midiIO; | |||
| int deviceId; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| midiIO->setDeviceId(deviceId); | |||
| } | |||
| }; | |||
| struct MidiDeviceChoice : LedDisplayChoice { | |||
| MidiWidget *midiWidget; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| Menu *menu = createMenu(); | |||
| menu->addChild(createMenuLabel("MIDI device")); | |||
| { | |||
| @@ -85,14 +85,14 @@ struct MidiDeviceChoice : LedDisplayChoice { | |||
| struct MidiChannelItem : MenuItem { | |||
| MidiIO *midiIO; | |||
| int channel; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| midiIO->channel = channel; | |||
| } | |||
| }; | |||
| struct MidiChannelChoice : LedDisplayChoice { | |||
| MidiWidget *midiWidget; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| Menu *menu = createMenu(); | |||
| menu->addChild(createMenuLabel("MIDI channel")); | |||
| for (int channel = -1; channel < 16; channel++) { | |||
| @@ -47,7 +47,7 @@ static bool isModelMatch(Model *model, std::string search) { | |||
| struct FavoriteRadioButton : RadioButton { | |||
| Model *model = NULL; | |||
| void on(event::Action &e) override; | |||
| void onAction(event::Action &e) override; | |||
| }; | |||
| @@ -80,9 +80,9 @@ struct BrowserListItem : OpaqueWidget { | |||
| Widget::draw(vg); | |||
| } | |||
| void on(event::DragStart &e) override; | |||
| void onDragStart(event::DragStart &e) override; | |||
| void on(event::DragDrop &e) override { | |||
| void onDragDrop(event::DragDrop &e) override { | |||
| if (e.origin != this) | |||
| return; | |||
| doAction(); | |||
| @@ -91,7 +91,7 @@ struct BrowserListItem : OpaqueWidget { | |||
| void doAction() { | |||
| event::Action eAction; | |||
| eAction.target = this; | |||
| handleEvent(eAction); | |||
| onAction(eAction); | |||
| if (eAction.target) { | |||
| MenuOverlay *overlay = getAncestorOfType<MenuOverlay>(); | |||
| overlay->requestedDelete = true; | |||
| @@ -137,7 +137,7 @@ struct ModelItem : BrowserListItem { | |||
| pluginLabel->box.size.x = box.size.x - BND_SCROLLBAR_WIDTH; | |||
| } | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| ModuleWidget *moduleWidget = model->createModuleWidget(); | |||
| if (!moduleWidget) | |||
| return; | |||
| @@ -163,7 +163,7 @@ struct AuthorItem : BrowserListItem { | |||
| addChild(authorLabel); | |||
| } | |||
| void on(event::Action &e) override; | |||
| void onAction(event::Action &e) override; | |||
| }; | |||
| @@ -181,7 +181,7 @@ struct TagItem : BrowserListItem { | |||
| addChild(tagLabel); | |||
| } | |||
| void on(event::Action &e) override; | |||
| void onAction(event::Action &e) override; | |||
| }; | |||
| @@ -192,7 +192,7 @@ struct ClearFilterItem : BrowserListItem { | |||
| addChild(label); | |||
| } | |||
| void on(event::Action &e) override; | |||
| void onAction(event::Action &e) override; | |||
| }; | |||
| @@ -272,8 +272,8 @@ struct ModuleBrowser; | |||
| struct SearchModuleField : TextField { | |||
| ModuleBrowser *moduleBrowser; | |||
| void on(event::Change &e) override; | |||
| void on(event::SelectKey &e) override; | |||
| void onChange(event::Change &e) override; | |||
| void onSelectKey(event::SelectKey &e) override; | |||
| }; | |||
| @@ -438,7 +438,7 @@ struct ModuleBrowser : OpaqueWidget { | |||
| // Implementations of inline methods above | |||
| void AuthorItem::on(event::Action &e) { | |||
| void AuthorItem::onAction(event::Action &e) { | |||
| ModuleBrowser *moduleBrowser = getAncestorOfType<ModuleBrowser>(); | |||
| sAuthorFilter = author; | |||
| moduleBrowser->clearSearch(); | |||
| @@ -446,7 +446,7 @@ void AuthorItem::on(event::Action &e) { | |||
| e.target = this; | |||
| } | |||
| void TagItem::on(event::Action &e) { | |||
| void TagItem::onAction(event::Action &e) { | |||
| ModuleBrowser *moduleBrowser = getAncestorOfType<ModuleBrowser>(); | |||
| sTagFilter = tag; | |||
| moduleBrowser->clearSearch(); | |||
| @@ -454,7 +454,7 @@ void TagItem::on(event::Action &e) { | |||
| e.target = this; | |||
| } | |||
| void ClearFilterItem::on(event::Action &e) { | |||
| void ClearFilterItem::onAction(event::Action &e) { | |||
| ModuleBrowser *moduleBrowser = getAncestorOfType<ModuleBrowser>(); | |||
| sAuthorFilter = ""; | |||
| sTagFilter = NO_TAG; | |||
| @@ -462,7 +462,7 @@ void ClearFilterItem::on(event::Action &e) { | |||
| e.target = this; | |||
| } | |||
| void FavoriteRadioButton::on(event::Action &e) { | |||
| void FavoriteRadioButton::onAction(event::Action &e) { | |||
| if (!model) | |||
| return; | |||
| if (value) { | |||
| @@ -479,18 +479,18 @@ void FavoriteRadioButton::on(event::Action &e) { | |||
| moduleBrowser->refreshSearch(); | |||
| } | |||
| void BrowserListItem::on(event::DragStart &e) { | |||
| void BrowserListItem::onDragStart(event::DragStart &e) { | |||
| BrowserList *list = dynamic_cast<BrowserList*>(parent); | |||
| if (list) { | |||
| list->selectItem(this); | |||
| } | |||
| } | |||
| void SearchModuleField::on(event::Change &e) { | |||
| void SearchModuleField::onChange(event::Change &e) { | |||
| moduleBrowser->refreshSearch(); | |||
| } | |||
| void SearchModuleField::on(event::SelectKey &e) { | |||
| void SearchModuleField::onSelectKey(event::SelectKey &e) { | |||
| switch (e.key) { | |||
| case GLFW_KEY_ESCAPE: { | |||
| MenuOverlay *overlay = getAncestorOfType<MenuOverlay>(); | |||
| @@ -529,7 +529,7 @@ void SearchModuleField::on(event::SelectKey &e) { | |||
| } | |||
| if (!e.target) { | |||
| TextField::on(e); | |||
| TextField::onSelectKey(e); | |||
| } | |||
| } | |||
| @@ -330,8 +330,8 @@ void ModuleWidget::drawShadow(NVGcontext *vg) { | |||
| nvgFill(vg); | |||
| } | |||
| void ModuleWidget::on(event::Hover &e) { | |||
| OpaqueWidget::on(e); | |||
| void ModuleWidget::onHover(event::Hover &e) { | |||
| OpaqueWidget::onHover(e); | |||
| // Instead of checking key-down events, delete the module even if key-repeat hasn't fired yet and the cursor is hovering over the widget. | |||
| if (glfwGetKey(gWindow, GLFW_KEY_DELETE) == GLFW_PRESS || glfwGetKey(gWindow, GLFW_KEY_BACKSPACE) == GLFW_PRESS) { | |||
| @@ -344,8 +344,8 @@ void ModuleWidget::on(event::Hover &e) { | |||
| } | |||
| } | |||
| void ModuleWidget::on(event::Button &e) { | |||
| OpaqueWidget::on(e); | |||
| void ModuleWidget::onButton(event::Button &e) { | |||
| OpaqueWidget::onButton(e); | |||
| if (e.target == this) { | |||
| if (e.button == 1) { | |||
| createContextMenu(); | |||
| @@ -353,7 +353,7 @@ void ModuleWidget::on(event::Button &e) { | |||
| } | |||
| } | |||
| void ModuleWidget::on(event::HoverKey &e) { | |||
| void ModuleWidget::onHoverKey(event::HoverKey &e) { | |||
| switch (e.key) { | |||
| case GLFW_KEY_I: { | |||
| if (windowIsModPressed() && !windowIsShiftPressed()) { | |||
| @@ -399,17 +399,17 @@ void ModuleWidget::on(event::HoverKey &e) { | |||
| } break; | |||
| } | |||
| OpaqueWidget::on(e); | |||
| OpaqueWidget::onHoverKey(e); | |||
| } | |||
| void ModuleWidget::on(event::DragStart &e) { | |||
| void ModuleWidget::onDragStart(event::DragStart &e) { | |||
| dragPos = gRackWidget->lastMousePos.minus(box.pos); | |||
| } | |||
| void ModuleWidget::on(event::DragEnd &e) { | |||
| void ModuleWidget::onDragEnd(event::DragEnd &e) { | |||
| } | |||
| void ModuleWidget::on(event::DragMove &e) { | |||
| void ModuleWidget::onDragMove(event::DragMove &e) { | |||
| if (!gRackWidget->lockModules) { | |||
| math::Rect newBox = box; | |||
| newBox.pos = gRackWidget->lastMousePos.minus(dragPos); | |||
| @@ -420,63 +420,63 @@ void ModuleWidget::on(event::DragMove &e) { | |||
| struct ModuleDisconnectItem : MenuItem { | |||
| ModuleWidget *moduleWidget; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| moduleWidget->disconnect(); | |||
| } | |||
| }; | |||
| struct ModuleResetItem : MenuItem { | |||
| ModuleWidget *moduleWidget; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| moduleWidget->reset(); | |||
| } | |||
| }; | |||
| struct ModuleRandomizeItem : MenuItem { | |||
| ModuleWidget *moduleWidget; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| moduleWidget->randomize(); | |||
| } | |||
| }; | |||
| struct ModuleCopyItem : MenuItem { | |||
| ModuleWidget *moduleWidget; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| moduleWidget->copyClipboard(); | |||
| } | |||
| }; | |||
| struct ModulePasteItem : MenuItem { | |||
| ModuleWidget *moduleWidget; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| moduleWidget->pasteClipboard(); | |||
| } | |||
| }; | |||
| struct ModuleSaveItem : MenuItem { | |||
| ModuleWidget *moduleWidget; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| moduleWidget->saveDialog(); | |||
| } | |||
| }; | |||
| struct ModuleLoadItem : MenuItem { | |||
| ModuleWidget *moduleWidget; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| moduleWidget->loadDialog(); | |||
| } | |||
| }; | |||
| struct ModuleCloneItem : MenuItem { | |||
| ModuleWidget *moduleWidget; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| gRackWidget->cloneModule(moduleWidget); | |||
| } | |||
| }; | |||
| struct ModuleDeleteItem : MenuItem { | |||
| ModuleWidget *moduleWidget; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| gRackWidget->deleteModule(moduleWidget); | |||
| delete moduleWidget; | |||
| } | |||
| @@ -4,11 +4,11 @@ | |||
| namespace rack { | |||
| void MomentarySwitch::on(event::DragStart &e) { | |||
| void MomentarySwitch::onDragStart(event::DragStart &e) { | |||
| setValue(maxValue); | |||
| } | |||
| void MomentarySwitch::on(event::DragEnd &e) { | |||
| void MomentarySwitch::onDragEnd(event::DragEnd &e) { | |||
| setValue(minValue); | |||
| } | |||
| @@ -36,8 +36,8 @@ void ParamWidget::randomize() { | |||
| } | |||
| } | |||
| void ParamWidget::on(event::Button &e) { | |||
| OpaqueWidget::on(e); | |||
| void ParamWidget::onButton(event::Button &e) { | |||
| OpaqueWidget::onButton(e); | |||
| if (e.target == this) { | |||
| if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) { | |||
| reset(); | |||
| @@ -45,7 +45,7 @@ void ParamWidget::on(event::Button &e) { | |||
| } | |||
| } | |||
| void ParamWidget::on(event::Change &e) { | |||
| void ParamWidget::onChange(event::Change &e) { | |||
| if (!module) | |||
| return; | |||
| @@ -11,7 +11,7 @@ namespace rack { | |||
| struct RegisterButton : Button { | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| std::thread t([&]() { | |||
| system::openBrowser("https://vcvrack.com/"); | |||
| }); | |||
| @@ -23,7 +23,7 @@ struct RegisterButton : Button { | |||
| struct LogInButton : Button { | |||
| TextField *emailField; | |||
| TextField *passwordField; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| std::thread t(pluginLogIn, emailField->text, passwordField->text); | |||
| t.detach(); | |||
| passwordField->text = ""; | |||
| @@ -39,7 +39,7 @@ struct StatusLabel : Label { | |||
| struct ManageButton : Button { | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| std::thread t([&]() { | |||
| system::openBrowser("https://vcvrack.com/plugins.html"); | |||
| }); | |||
| @@ -85,7 +85,7 @@ struct SyncButton : Button { | |||
| nvgStroke(vg); | |||
| } | |||
| } | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| available = false; | |||
| std::thread t([this]() { | |||
| if (pluginSync(false)) | |||
| @@ -97,7 +97,7 @@ struct SyncButton : Button { | |||
| struct LogOutButton : Button { | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| pluginLogOut(); | |||
| } | |||
| }; | |||
| @@ -115,7 +115,7 @@ struct DownloadProgressBar : ProgressBar { | |||
| struct CancelButton : Button { | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| pluginCancelDownload(); | |||
| } | |||
| }; | |||
| @@ -49,19 +49,19 @@ void Port::draw(NVGcontext *vg) { | |||
| } | |||
| } | |||
| void Port::on(event::Button &e) { | |||
| void Port::onButton(event::Button &e) { | |||
| if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) { | |||
| gRackWidget->wireContainer->removeTopWire(this); | |||
| // HACK | |||
| // Update hovered*Port of active wire if applicable | |||
| event::DragEnter eDragEnter; | |||
| on(eDragEnter); | |||
| onDragEnter(eDragEnter); | |||
| } | |||
| e.target = this; | |||
| } | |||
| void Port::on(event::DragStart &e) { | |||
| void Port::onDragStart(event::DragStart &e) { | |||
| // Try to grab wire on top of stack | |||
| WireWidget *wire = gRackWidget->wireContainer->getTopWire(this); | |||
| if (type == OUTPUT && windowIsModPressed()) { | |||
| @@ -87,16 +87,16 @@ void Port::on(event::DragStart &e) { | |||
| gRackWidget->wireContainer->setActiveWire(wire); | |||
| } | |||
| void Port::on(event::DragEnd &e) { | |||
| void Port::onDragEnd(event::DragEnd &e) { | |||
| // FIXME | |||
| // If the source Port is deleted, this will be called, removing the cable | |||
| gRackWidget->wireContainer->commitActiveWire(); | |||
| } | |||
| void Port::on(event::DragDrop &e) { | |||
| void Port::onDragDrop(event::DragDrop &e) { | |||
| } | |||
| void Port::on(event::DragEnter &e) { | |||
| void Port::onDragEnter(event::DragEnter &e) { | |||
| // Reject ports if this is an input port and something is already plugged into it | |||
| if (type == INPUT) { | |||
| WireWidget *topWire = gRackWidget->wireContainer->getTopWire(this); | |||
| @@ -113,7 +113,7 @@ void Port::on(event::DragEnter &e) { | |||
| } | |||
| } | |||
| void Port::on(event::DragLeave &e) { | |||
| void Port::onDragLeave(event::DragLeave &e) { | |||
| WireWidget *activeWire = gRackWidget->wireContainer->activeWire; | |||
| if (activeWire) { | |||
| if (type == INPUT) | |||
| @@ -55,8 +55,8 @@ void RackScene::draw(NVGcontext *vg) { | |||
| Scene::draw(vg); | |||
| } | |||
| void RackScene::on(event::HoverKey &e) { | |||
| Scene::on(e); | |||
| void RackScene::onHoverKey(event::HoverKey &e) { | |||
| Scene::onHoverKey(e); | |||
| if (!e.target) { | |||
| switch (e.key) { | |||
| @@ -110,7 +110,7 @@ void RackScene::on(event::HoverKey &e) { | |||
| } | |||
| } | |||
| void RackScene::on(event::PathDrop &e) { | |||
| void RackScene::onPathDrop(event::PathDrop &e) { | |||
| if (e.paths.size() >= 1) { | |||
| const std::string &path = e.paths[0]; | |||
| if (string::extension(path) == "vcv") { | |||
| @@ -120,7 +120,7 @@ void RackScene::on(event::PathDrop &e) { | |||
| } | |||
| if (!e.target) | |||
| Scene::on(e); | |||
| Scene::onPathDrop(e); | |||
| } | |||
| @@ -497,14 +497,14 @@ void RackWidget::draw(NVGcontext *vg) { | |||
| Widget::draw(vg); | |||
| } | |||
| void RackWidget::on(event::Hover &e) { | |||
| OpaqueWidget::on(e); | |||
| void RackWidget::onHover(event::Hover &e) { | |||
| OpaqueWidget::onHover(e); | |||
| lastMousePos = e.pos; | |||
| } | |||
| void RackWidget::on(event::Button &e) { | |||
| void RackWidget::onButton(event::Button &e) { | |||
| DEBUG("1"); | |||
| OpaqueWidget::on(e); | |||
| OpaqueWidget::onButton(e); | |||
| DEBUG("2"); | |||
| if (e.target == this) { | |||
| DEBUG("3"); | |||
| @@ -515,9 +515,9 @@ void RackWidget::on(event::Button &e) { | |||
| } | |||
| } | |||
| void RackWidget::on(event::Zoom &e) { | |||
| void RackWidget::onZoom(event::Zoom &e) { | |||
| rails->box.size = math::Vec(); | |||
| EventWidget::on(e); | |||
| OpaqueWidget::onZoom(e); | |||
| } | |||
| @@ -16,14 +16,14 @@ void SVGButton::setSVGs(std::shared_ptr<SVG> defaultSVG, std::shared_ptr<SVG> ac | |||
| this->activeSVG = activeSVG ? activeSVG : defaultSVG; | |||
| } | |||
| void SVGButton::on(event::DragStart &e) { | |||
| void SVGButton::onDragStart(event::DragStart &e) { | |||
| event::Action eAction; | |||
| handleEvent(eAction); | |||
| onAction(eAction); | |||
| sw->setSVG(activeSVG); | |||
| dirty = true; | |||
| } | |||
| void SVGButton::on(event::DragEnd &e) { | |||
| void SVGButton::onDragEnd(event::DragEnd &e) { | |||
| sw->setSVG(defaultSVG); | |||
| dirty = true; | |||
| } | |||
| @@ -46,9 +46,9 @@ void SVGKnob::step() { | |||
| FramebufferWidget::step(); | |||
| } | |||
| void SVGKnob::on(event::Change &e) { | |||
| void SVGKnob::onChange(event::Change &e) { | |||
| dirty = true; | |||
| ParamWidget::on(e); | |||
| ParamWidget::onChange(e); | |||
| } | |||
| @@ -30,9 +30,9 @@ void SVGSlider::step() { | |||
| FramebufferWidget::step(); | |||
| } | |||
| void SVGSlider::on(event::Change &e) { | |||
| void SVGSlider::onChange(event::Change &e) { | |||
| dirty = true; | |||
| ParamWidget::on(e); | |||
| ParamWidget::onChange(e); | |||
| } | |||
| @@ -18,13 +18,13 @@ void SVGSwitch::addFrame(std::shared_ptr<SVG> svg) { | |||
| } | |||
| } | |||
| void SVGSwitch::on(event::Change &e) { | |||
| void SVGSwitch::onChange(event::Change &e) { | |||
| assert(frames.size() > 0); | |||
| float valueScaled = math::rescale(value, minValue, maxValue, 0, frames.size() - 1); | |||
| int index = math::clamp((int) roundf(valueScaled), 0, (int) frames.size() - 1); | |||
| sw->setSVG(frames[index]); | |||
| dirty = true; | |||
| ParamWidget::on(e); | |||
| ParamWidget::onChange(e); | |||
| } | |||
| @@ -4,7 +4,7 @@ | |||
| namespace rack { | |||
| void ToggleSwitch::on(event::DragStart &e) { | |||
| void ToggleSwitch::onDragStart(event::DragStart &e) { | |||
| // Cycle through values | |||
| // e.g. a range of [0.0, 3.0] would have modes 0, 1, 2, and 3. | |||
| if (value >= maxValue) | |||
| @@ -11,22 +11,22 @@ namespace rack { | |||
| struct TooltipIconButton : IconButton { | |||
| Tooltip *tooltip = NULL; | |||
| std::string tooltipText; | |||
| void on(event::Enter &e) override { | |||
| void onEnter(event::Enter &e) override { | |||
| if (!tooltip) { | |||
| tooltip = new Tooltip; | |||
| tooltip->box.pos = getAbsoluteOffset(math::Vec(0, BND_WIDGET_HEIGHT)); | |||
| tooltip->text = tooltipText; | |||
| gRackScene->addChild(tooltip); | |||
| } | |||
| IconButton::on(e); | |||
| IconButton::onEnter(e); | |||
| } | |||
| void on(event::Leave &e) override { | |||
| void onLeave(event::Leave &e) override { | |||
| if (tooltip) { | |||
| gRackScene->removeChild(tooltip); | |||
| delete tooltip; | |||
| tooltip = NULL; | |||
| } | |||
| IconButton::on(e); | |||
| IconButton::onLeave(e); | |||
| } | |||
| }; | |||
| @@ -35,7 +35,7 @@ struct NewButton : TooltipIconButton { | |||
| setSVG(SVG::load(asset::global("res/icons/noun_146097_cc.svg"))); | |||
| tooltipText = "New patch (" WINDOW_MOD_KEY_NAME "+N)"; | |||
| } | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| gRackWidget->reset(); | |||
| } | |||
| }; | |||
| @@ -45,7 +45,7 @@ struct OpenButton : TooltipIconButton { | |||
| setSVG(SVG::load(asset::global("res/icons/noun_31859_cc.svg"))); | |||
| tooltipText = "Open patch (" WINDOW_MOD_KEY_NAME "+O)"; | |||
| } | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| gRackWidget->loadDialog(); | |||
| } | |||
| }; | |||
| @@ -55,7 +55,7 @@ struct SaveButton : TooltipIconButton { | |||
| setSVG(SVG::load(asset::global("res/icons/noun_1343816_cc.svg"))); | |||
| tooltipText = "Save patch (" WINDOW_MOD_KEY_NAME "+S)"; | |||
| } | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| gRackWidget->saveDialog(); | |||
| } | |||
| }; | |||
| @@ -65,7 +65,7 @@ struct SaveAsButton : TooltipIconButton { | |||
| setSVG(SVG::load(asset::global("res/icons/noun_1343811_cc.svg"))); | |||
| tooltipText = "Save patch as (" WINDOW_MOD_KEY_NAME "+Shift+S)"; | |||
| } | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| gRackWidget->saveAsDialog(); | |||
| } | |||
| }; | |||
| @@ -75,7 +75,7 @@ struct RevertButton : TooltipIconButton { | |||
| setSVG(SVG::load(asset::global("res/icons/noun_1084369_cc.svg"))); | |||
| tooltipText = "Revert patch"; | |||
| } | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| gRackWidget->revert(); | |||
| } | |||
| }; | |||
| @@ -85,7 +85,7 @@ struct DisconnectCablesButton : TooltipIconButton { | |||
| setSVG(SVG::load(asset::global("res/icons/noun_1745061_cc.svg"))); | |||
| tooltipText = "Disconnect cables"; | |||
| } | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| gRackWidget->disconnect(); | |||
| } | |||
| }; | |||
| @@ -95,20 +95,20 @@ struct PowerMeterButton : TooltipIconButton { | |||
| setSVG(SVG::load(asset::global("res/icons/noun_305536_cc.svg"))); | |||
| tooltipText = "Toggle power meter (see manual for explanation)"; | |||
| } | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| gPowerMeter ^= true; | |||
| } | |||
| }; | |||
| struct EnginePauseItem : MenuItem { | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| gPaused ^= true; | |||
| } | |||
| }; | |||
| struct SampleRateItem : MenuItem { | |||
| float sampleRate; | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| engineSetSampleRate(sampleRate); | |||
| gPaused = false; | |||
| } | |||
| @@ -119,7 +119,7 @@ struct SampleRateButton : TooltipIconButton { | |||
| setSVG(SVG::load(asset::global("res/icons/noun_1240789_cc.svg"))); | |||
| tooltipText = "Engine sample rate"; | |||
| } | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| Menu *menu = createMenu(); | |||
| menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); | |||
| menu->box.size.x = box.size.x; | |||
| @@ -146,14 +146,14 @@ struct RackLockButton : TooltipIconButton { | |||
| setSVG(SVG::load(asset::global("res/icons/noun_468341_cc.svg"))); | |||
| tooltipText = "Lock modules"; | |||
| } | |||
| void on(event::Action &e) override { | |||
| void onAction(event::Action &e) override { | |||
| gRackWidget->lockModules ^= true; | |||
| } | |||
| }; | |||
| struct ZoomSlider : Slider { | |||
| void on(event::Action &e) override { | |||
| EventWidget::on(e); | |||
| void onAction(event::Action &e) override { | |||
| Slider::onAction(e); | |||
| gRackScene->zoomWidget->setZoom(std::round(value) / 100.0); | |||
| } | |||
| }; | |||
| @@ -319,8 +319,7 @@ void windowRun() { | |||
| glfwGetWindowContentScale(gWindow, &pixelRatio, NULL); | |||
| pixelRatio = roundf(pixelRatio); | |||
| if (pixelRatio != gPixelRatio) { | |||
| event::Zoom eZoom; | |||
| gWidgetState->rootWidget->handleEvent(eZoom); | |||
| gWidgetState->handleZoom(); | |||
| gPixelRatio = pixelRatio; | |||
| } | |||