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