Browse Source

Merge event:: namespace with widget:: namespace. Rename event::* to widget::*Event.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
b84e2f57fa
68 changed files with 670 additions and 676 deletions
  1. +6
    -6
      include/app.hpp
  2. +5
    -5
      include/app/Knob.hpp
  3. +1
    -1
      include/app/LedDisplay.hpp
  4. +6
    -6
      include/app/ModuleWidget.hpp
  5. +4
    -4
      include/app/ParamWidget.hpp
  6. +8
    -8
      include/app/PortWidget.hpp
  7. +5
    -5
      include/app/RackWidget.hpp
  8. +2
    -2
      include/app/Scene.hpp
  9. +2
    -2
      include/app/SliderKnob.hpp
  10. +3
    -3
      include/app/SvgButton.hpp
  11. +1
    -1
      include/app/SvgKnob.hpp
  12. +1
    -1
      include/app/SvgSlider.hpp
  13. +1
    -1
      include/app/SvgSwitch.hpp
  14. +3
    -3
      include/app/Switch.hpp
  15. +5
    -5
      include/ui/Button.hpp
  16. +1
    -1
      include/ui/Menu.hpp
  17. +3
    -3
      include/ui/MenuItem.hpp
  18. +2
    -2
      include/ui/MenuOverlay.hpp
  19. +3
    -3
      include/ui/RadioButton.hpp
  20. +3
    -3
      include/ui/ScrollBar.hpp
  21. +2
    -2
      include/ui/ScrollWidget.hpp
  22. +4
    -4
      include/ui/Slider.hpp
  23. +7
    -7
      include/ui/TextField.hpp
  24. +5
    -5
      include/widget/ObstructWidget.hpp
  25. +5
    -5
      include/widget/OpaqueWidget.hpp
  26. +7
    -7
      include/widget/TransparentWidget.hpp
  27. +30
    -30
      include/widget/Widget.hpp
  28. +14
    -14
      include/widget/ZoomWidget.hpp
  29. +56
    -62
      include/widget/event.hpp
  30. +3
    -3
      src/Core/Blank.cpp
  31. +2
    -2
      src/Core/CV_Gate.cpp
  32. +1
    -1
      src/Core/CV_MIDI.cpp
  33. +4
    -4
      src/Core/MIDI_CV.cpp
  34. +2
    -2
      src/Core/MIDI_Gate.cpp
  35. +3
    -3
      src/Core/MIDI_Map.cpp
  36. +7
    -7
      src/Core/plugin.hpp
  37. +2
    -2
      src/app.cpp
  38. +8
    -8
      src/app/AudioWidget.cpp
  39. +1
    -1
      src/app/CableWidget.cpp
  40. +5
    -5
      src/app/Knob.cpp
  41. +3
    -3
      src/app/LedDisplay.cpp
  42. +6
    -6
      src/app/MidiWidget.cpp
  43. +10
    -10
      src/app/ModuleBrowser.cpp
  44. +19
    -19
      src/app/ModuleWidget.cpp
  45. +8
    -8
      src/app/ParamWidget.cpp
  46. +8
    -8
      src/app/PortWidget.cpp
  47. +5
    -5
      src/app/RackWidget.cpp
  48. +2
    -2
      src/app/Scene.cpp
  49. +4
    -4
      src/app/SvgButton.cpp
  50. +1
    -1
      src/app/SvgKnob.cpp
  51. +1
    -1
      src/app/SvgSlider.cpp
  52. +1
    -1
      src/app/SvgSwitch.cpp
  53. +3
    -3
      src/app/Switch.cpp
  54. +34
    -34
      src/app/Toolbar.cpp
  55. +0
    -267
      src/event.cpp
  56. +6
    -6
      src/ui/Button.cpp
  57. +1
    -1
      src/ui/Menu.cpp
  58. +7
    -7
      src/ui/MenuItem.cpp
  59. +2
    -2
      src/ui/MenuOverlay.cpp
  60. +4
    -4
      src/ui/RadioButton.cpp
  61. +3
    -3
      src/ui/ScrollBar.cpp
  62. +3
    -3
      src/ui/ScrollWidget.cpp
  63. +4
    -4
      src/ui/Slider.cpp
  64. +14
    -14
      src/ui/TextField.cpp
  65. +17
    -17
      src/widget/Widget.cpp
  66. +3
    -3
      src/widget/ZoomWidget.cpp
  67. +267
    -0
      src/widget/event.cpp
  68. +1
    -1
      src/window.cpp

+ 6
- 6
include/app.hpp View File

@@ -9,11 +9,6 @@
namespace rack {


namespace event {
struct State;
} // namespace event


namespace history {
struct State;
} // namespace history
@@ -28,6 +23,11 @@ struct Window;
struct PatchManager;


namespace widget {
struct EventState;
};


namespace app {
struct Scene;
} // namespace app
@@ -35,7 +35,7 @@ namespace app {

/** Contains the application state */
struct App {
event::State *event = NULL;
widget::EventState *event = NULL;
app::Scene *scene = NULL;
engine::Engine *engine = NULL;
Window *window = NULL;


+ 5
- 5
include/app/Knob.hpp View File

@@ -20,11 +20,11 @@ struct Knob : ParamWidget {
/** Drag horizontally instead of vertically */
bool horizontal = false;

void onHover(const event::Hover &e) override;
void onButton(const event::Button &e) override;
void onDragStart(const event::DragStart &e) override;
void onDragEnd(const event::DragEnd &e) override;
void onDragMove(const event::DragMove &e) override;
void onHover(const widget::HoverEvent &e) override;
void onButton(const widget::ButtonEvent &e) override;
void onDragStart(const widget::DragStartEvent &e) override;
void onDragEnd(const widget::DragEndEvent &e) override;
void onDragMove(const widget::DragMoveEvent &e) override;
};




+ 1
- 1
include/app/LedDisplay.hpp View File

@@ -26,7 +26,7 @@ struct LedDisplayChoice : widget::TransparentWidget {
NVGcolor bgColor;
LedDisplayChoice();
void draw(const DrawArgs &args) override;
void onButton(const event::Button &e) override;
void onButton(const widget::ButtonEvent &e) override;
};

struct LedDisplayTextField : ui::TextField {


+ 6
- 6
include/app/ModuleWidget.hpp View File

@@ -35,12 +35,12 @@ struct ModuleWidget : widget::OpaqueWidget {
void draw(const DrawArgs &args) override;
void drawShadow(const DrawArgs &args);

void onHover(const event::Hover &e) override;
void onButton(const event::Button &e) override;
void onHoverKey(const event::HoverKey &e) override;
void onDragStart(const event::DragStart &e) override;
void onDragEnd(const event::DragEnd &e) override;
void onDragMove(const event::DragMove &e) override;
void onHover(const widget::HoverEvent &e) override;
void onButton(const widget::ButtonEvent &e) override;
void onHoverKey(const widget::HoverKeyEvent &e) override;
void onDragStart(const widget::DragStartEvent &e) override;
void onDragEnd(const widget::DragEndEvent &e) override;
void onDragMove(const widget::DragMoveEvent &e) override;

/** Associates this ModuleWidget with the Module
Transfers ownership


+ 4
- 4
include/app/ParamWidget.hpp View File

@@ -19,10 +19,10 @@ struct ParamWidget : widget::OpaqueWidget {
~ParamWidget();
void step() override;
void draw(const DrawArgs &args) override;
void onButton(const event::Button &e) override;
void onDoubleClick(const event::DoubleClick &e) override;
void onEnter(const event::Enter &e) override;
void onLeave(const event::Leave &e) override;
void onButton(const widget::ButtonEvent &e) override;
void onDoubleClick(const widget::DoubleClickEvent &e) override;
void onEnter(const widget::EnterEvent &e) override;
void onLeave(const widget::LeaveEvent &e) override;

/** For legacy patch loading */
void fromJson(json_t *rootJ);


+ 8
- 8
include/app/PortWidget.hpp View File

@@ -28,14 +28,14 @@ struct PortWidget : widget::OpaqueWidget {
void step() override;
void draw(const DrawArgs &args) override;

void onButton(const event::Button &e) override;
void onEnter(const event::Enter &e) override;
void onLeave(const event::Leave &e) override;
void onDragStart(const event::DragStart &e) override;
void onDragEnd(const event::DragEnd &e) override;
void onDragDrop(const event::DragDrop &e) override;
void onDragEnter(const event::DragEnter &e) override;
void onDragLeave(const event::DragLeave &e) override;
void onButton(const widget::ButtonEvent &e) override;
void onEnter(const widget::EnterEvent &e) override;
void onLeave(const widget::LeaveEvent &e) override;
void onDragStart(const widget::DragStartEvent &e) override;
void onDragEnd(const widget::DragEndEvent &e) override;
void onDragDrop(const widget::DragDropEvent &e) override;
void onDragEnter(const widget::DragEnterEvent &e) override;
void onDragLeave(const widget::DragLeaveEvent &e) override;
};




+ 5
- 5
include/app/RackWidget.hpp View File

@@ -28,11 +28,11 @@ struct RackWidget : widget::OpaqueWidget {
void step() override;
void draw(const DrawArgs &args) override;

void onHover(const event::Hover &e) override;
void onHoverKey(const event::HoverKey &e) override;
void onDragHover(const event::DragHover &e) override;
void onButton(const event::Button &e) override;
void onZoom(const event::Zoom &e) override;
void onHover(const widget::HoverEvent &e) override;
void onHoverKey(const widget::HoverKeyEvent &e) override;
void onDragHover(const widget::DragHoverEvent &e) override;
void onButton(const widget::ButtonEvent &e) override;
void onZoom(const widget::ZoomEvent &e) override;

/** Completely clear the rack's modules and cables */
void clear();


+ 2
- 2
include/app/Scene.hpp View File

@@ -31,8 +31,8 @@ struct Scene : widget::OpaqueWidget {
~Scene();
void step() override;
void draw(const DrawArgs &args) override;
void onHoverKey(const event::HoverKey &e) override;
void onPathDrop(const event::PathDrop &e) override;
void onHoverKey(const widget::HoverKeyEvent &e) override;
void onPathDrop(const widget::PathDropEvent &e) override;

void runCheckVersion();
};


+ 2
- 2
include/app/SliderKnob.hpp View File

@@ -9,10 +9,10 @@ namespace app {

struct SliderKnob : Knob {
// Bypass Knob's circular hitbox detection
void onHover(const event::Hover &e) override {
void onHover(const widget::HoverEvent &e) override {
ParamWidget::onHover(e);
}
void onButton(const event::Button &e) override {
void onButton(const widget::ButtonEvent &e) override {
ParamWidget::onButton(e);
}
};


+ 3
- 3
include/app/SvgButton.hpp View File

@@ -16,9 +16,9 @@ struct SvgButton : widget::OpaqueWidget {

SvgButton();
void addFrame(std::shared_ptr<Svg> svg);
void onDragStart(const event::DragStart &e) override;
void onDragEnd(const event::DragEnd &e) override;
void onDragDrop(const event::DragDrop &e) override;
void onDragStart(const widget::DragStartEvent &e) override;
void onDragEnd(const widget::DragEndEvent &e) override;
void onDragDrop(const widget::DragDropEvent &e) override;
};




+ 1
- 1
include/app/SvgKnob.hpp View File

@@ -23,7 +23,7 @@ struct SvgKnob : Knob {
SvgKnob();
void setSvg(std::shared_ptr<Svg> svg);
DEPRECATED void setSVG(std::shared_ptr<Svg> svg) {setSvg(svg);}
void onChange(const event::Change &e) override;
void onChange(const widget::ChangeEvent &e) override;
};




+ 1
- 1
include/app/SvgSlider.hpp View File

@@ -22,7 +22,7 @@ struct SvgSlider : app::SliderKnob {
SvgSlider();
void setBackgroundSvg(std::shared_ptr<Svg> svg);
void setHandleSvg(std::shared_ptr<Svg> svg);
void onChange(const event::Change &e) override;
void onChange(const widget::ChangeEvent &e) override;

DEPRECATED void setBackgroundSVG(std::shared_ptr<Svg> svg) {setBackgroundSvg(svg);}
DEPRECATED void setHandleSVG(std::shared_ptr<Svg> svg) {setBackgroundSvg(svg);}


+ 1
- 1
include/app/SvgSwitch.hpp View File

@@ -18,7 +18,7 @@ struct SvgSwitch : Switch {
SvgSwitch();
/** Adds an SVG file to represent the next switch position */
void addFrame(std::shared_ptr<Svg> svg);
void onChange(const event::Change &e) override;
void onChange(const widget::ChangeEvent &e) override;
};




+ 3
- 3
include/app/Switch.hpp View File

@@ -16,9 +16,9 @@ struct Switch : ParamWidget {
bool momentaryReleased = false;

void step() override;
void onDoubleClick(const event::DoubleClick &e) override;
void onDragStart(const event::DragStart &e) override;
void onDragEnd(const event::DragEnd &e) override;
void onDoubleClick(const widget::DoubleClickEvent &e) override;
void onDragStart(const widget::DragStartEvent &e) override;
void onDragEnd(const widget::DragEndEvent &e) override;
};




+ 5
- 5
include/ui/Button.hpp View File

@@ -17,11 +17,11 @@ struct Button : widget::OpaqueWidget {
Button();
~Button();
void draw(const DrawArgs &args) override;
void onEnter(const event::Enter &e) override;
void onLeave(const event::Leave &e) override;
void onDragStart(const event::DragStart &e) override;
void onDragEnd(const event::DragEnd &e) override;
void onDragDrop(const event::DragDrop &e) override;
void onEnter(const widget::EnterEvent &e) override;
void onLeave(const widget::LeaveEvent &e) override;
void onDragStart(const widget::DragStartEvent &e) override;
void onDragEnd(const widget::DragEndEvent &e) override;
void onDragDrop(const widget::DragDropEvent &e) override;
};




+ 1
- 1
include/ui/Menu.hpp View File

@@ -19,7 +19,7 @@ struct Menu : widget::OpaqueWidget {
void setChildMenu(Menu *menu);
void step() override;
void draw(const DrawArgs &args) override;
void onHoverScroll(const event::HoverScroll &e) override;
void onHoverScroll(const widget::HoverScrollEvent &e) override;
};




+ 3
- 3
include/ui/MenuItem.hpp View File

@@ -16,9 +16,9 @@ struct MenuItem : MenuEntry {

void draw(const DrawArgs &args) override;
void step() override;
void onEnter(const event::Enter &e) override;
void onDragStart(const event::DragStart &e) override;
void onDragDrop(const event::DragDrop &e) override;
void onEnter(const widget::EnterEvent &e) override;
void onDragStart(const widget::DragStartEvent &e) override;
void onDragDrop(const widget::DragDropEvent &e) override;
void doAction();
virtual Menu *createChildMenu() {return NULL;}
};


+ 2
- 2
include/ui/MenuOverlay.hpp View File

@@ -10,8 +10,8 @@ namespace ui {
/** Deletes itself from parent when clicked */
struct MenuOverlay : widget::OpaqueWidget {
void step() override;
void onButton(const event::Button &e) override;
void onHoverKey(const event::HoverKey &e) override;
void onButton(const widget::ButtonEvent &e) override;
void onHoverKey(const widget::HoverKeyEvent &e) override;
};




+ 3
- 3
include/ui/RadioButton.hpp View File

@@ -15,9 +15,9 @@ struct RadioButton : widget::OpaqueWidget {
RadioButton();
~RadioButton();
void draw(const DrawArgs &args) override;
void onEnter(const event::Enter &e) override;
void onLeave(const event::Leave &e) override;
void onDragDrop(const event::DragDrop &e) override;
void onEnter(const widget::EnterEvent &e) override;
void onLeave(const widget::LeaveEvent &e) override;
void onDragDrop(const widget::DragDropEvent &e) override;
};




+ 3
- 3
include/ui/ScrollBar.hpp View File

@@ -20,9 +20,9 @@ struct ScrollBar : widget::OpaqueWidget {

ScrollBar();
void draw(const DrawArgs &args) override;
void onDragStart(const event::DragStart &e) override;
void onDragMove(const event::DragMove &e) override;
void onDragEnd(const event::DragEnd &e) override;
void onDragStart(const widget::DragStartEvent &e) override;
void onDragMove(const widget::DragMoveEvent &e) override;
void onDragEnd(const widget::DragEndEvent &e) override;
};




+ 2
- 2
include/ui/ScrollWidget.hpp View File

@@ -19,8 +19,8 @@ struct ScrollWidget : widget::Widget {
void scrollTo(math::Rect r);
void draw(const DrawArgs &args) override;
void step() override;
void onHover(const event::Hover &e) override;
void onHoverScroll(const event::HoverScroll &e) override;
void onHover(const widget::HoverEvent &e) override;
void onHoverScroll(const widget::HoverScrollEvent &e) override;
};




+ 4
- 4
include/ui/Slider.hpp View File

@@ -16,10 +16,10 @@ struct Slider : widget::OpaqueWidget {
Slider();
~Slider();
void draw(const DrawArgs &args) override;
void onDragStart(const event::DragStart &e) override;
void onDragMove(const event::DragMove &e) override;
void onDragEnd(const event::DragEnd &e) override;
void onDoubleClick(const event::DoubleClick &e) override;
void onDragStart(const widget::DragStartEvent &e) override;
void onDragMove(const widget::DragMoveEvent &e) override;
void onDragEnd(const widget::DragEndEvent &e) override;
void onDoubleClick(const widget::DoubleClickEvent &e) override;
};




+ 7
- 7
include/ui/TextField.hpp View File

@@ -1,7 +1,7 @@
#pragma once
#include "widget/OpaqueWidget.hpp"
#include "ui/common.hpp"
#include "event.hpp"
#include "widget/event.hpp"
#include "app.hpp"


@@ -22,12 +22,12 @@ struct TextField : widget::OpaqueWidget {

TextField();
void draw(const DrawArgs &args) override;
void onButton(const event::Button &e) override;
void onHover(const event::Hover &e) override;
void onEnter(const event::Enter &e) override;
void onSelect(const event::Select &e) override;
void onSelectText(const event::SelectText &e) override;
void onSelectKey(const event::SelectKey &e) override;
void onButton(const widget::ButtonEvent &e) override;
void onHover(const widget::HoverEvent &e) override;
void onEnter(const widget::EnterEvent &e) override;
void onSelect(const widget::SelectEvent &e) override;
void onSelectText(const widget::SelectTextEvent &e) override;
void onSelectKey(const widget::SelectKeyEvent &e) override;

/** Inserts text at the cursor, replacing the selection if necessary */
void insertText(std::string text);


+ 5
- 5
include/widget/ObstructWidget.hpp View File

@@ -9,19 +9,19 @@ namespace widget {
/** A Widget that consumes recursing events without giving a chance for children to consume.
*/
struct ObstructWidget : Widget {
void onHover(const event::Hover &e) override {
void onHover(const HoverEvent &e) override {
e.consume(this);
}
void onButton(const event::Button &e) override {
void onButton(const ButtonEvent &e) override {
e.consume(this);
}
void onHoverKey(const event::HoverKey &e) override {
void onHoverKey(const HoverKeyEvent &e) override {
e.consume(this);
}
void onHoverText(const event::HoverText &e) override {
void onHoverText(const HoverTextEvent &e) override {
e.consume(this);
}
void onDragHover(const event::DragHover &e) override {
void onDragHover(const DragHoverEvent &e) override {
e.consume(this);
}
};


+ 5
- 5
include/widget/OpaqueWidget.hpp View File

@@ -11,27 +11,27 @@ You can of course override the events.
You may also call OpaqueWidget::on*() from the overridden method to continue recursing/consuming the event.
*/
struct OpaqueWidget : Widget {
void onHover(const event::Hover &e) override {
void onHover(const HoverEvent &e) override {
Widget::onHover(e);
if (!e.getConsumed())
e.consume(this);
}
void onButton(const event::Button &e) override {
void onButton(const ButtonEvent &e) override {
Widget::onButton(e);
if (!e.getConsumed())
e.consume(this);
}
void onHoverKey(const event::HoverKey &e) override {
void onHoverKey(const HoverKeyEvent &e) override {
Widget::onHoverKey(e);
if (!e.getConsumed())
e.consume(this);
}
void onHoverText(const event::HoverText &e) override {
void onHoverText(const HoverTextEvent &e) override {
Widget::onHoverText(e);
if (!e.getConsumed())
e.consume(this);
}
void onDragHover(const event::DragHover &e) override {
void onDragHover(const DragHoverEvent &e) override {
Widget::onDragHover(e);
if (!e.getConsumed())
e.consume(this);


+ 7
- 7
include/widget/TransparentWidget.hpp View File

@@ -9,13 +9,13 @@ namespace widget {
/** A Widget that does not respond to events and does not pass events to children */
struct TransparentWidget : Widget {
/** Override behavior to do nothing instead. */
void onHover(const event::Hover &e) override {}
void onButton(const event::Button &e) override {}
void onHoverKey(const event::HoverKey &e) override {}
void onHoverText(const event::HoverText &e) override {}
void onHoverScroll(const event::HoverScroll &e) override {}
void onDragHover(const event::DragHover &e) override {}
void onPathDrop(const event::PathDrop &e) override {}
void onHover(const HoverEvent &e) override {}
void onButton(const ButtonEvent &e) override {}
void onHoverKey(const HoverKeyEvent &e) override {}
void onHoverText(const HoverTextEvent &e) override {}
void onHoverScroll(const HoverScrollEvent &e) override {}
void onDragHover(const DragHoverEvent &e) override {}
void onPathDrop(const PathDropEvent &e) override {}
};




+ 30
- 30
include/widget/Widget.hpp View File

@@ -3,7 +3,7 @@
#include "math.hpp"
#include "window.hpp"
#include "color.hpp"
#include "event.hpp"
#include "widget/event.hpp"
#include <list>


@@ -133,35 +133,35 @@ struct Widget {
/** Override these event callbacks to respond to events.
See events.hpp for a description of each event.
*/
virtual void onHover(const event::Hover &e) {recursePositionEvent(&Widget::onHover, e);}
virtual void onButton(const event::Button &e) {recursePositionEvent(&Widget::onButton, e);}
virtual void onDoubleClick(const event::DoubleClick &e) {}
virtual void onHoverKey(const event::HoverKey &e) {recursePositionEvent(&Widget::onHoverKey, e);}
virtual void onHoverText(const event::HoverText &e) {recursePositionEvent(&Widget::onHoverText, e);}
virtual void onHoverScroll(const event::HoverScroll &e) {recursePositionEvent(&Widget::onHoverScroll, e);}
virtual void onEnter(const event::Enter &e) {}
virtual void onLeave(const event::Leave &e) {}
virtual void onSelect(const event::Select &e) {}
virtual void onDeselect(const event::Deselect &e) {}
virtual void onSelectKey(const event::SelectKey &e) {}
virtual void onSelectText(const event::SelectText &e) {}
virtual void onDragStart(const event::DragStart &e) {}
virtual void onDragEnd(const event::DragEnd &e) {}
virtual void onDragMove(const event::DragMove &e) {}
virtual void onDragHover(const event::DragHover &e) {recursePositionEvent(&Widget::onDragHover, e);}
virtual void onDragEnter(const event::DragEnter &e) {}
virtual void onDragLeave(const event::DragLeave &e) {}
virtual void onDragDrop(const event::DragDrop &e) {}
virtual void onPathDrop(const event::PathDrop &e) {recursePositionEvent(&Widget::onPathDrop, e);}
virtual void onAction(const event::Action &e) {}
virtual void onChange(const event::Change &e) {}
virtual void onZoom(const event::Zoom &e) {recurseEvent(&Widget::onZoom, e);}
virtual void onReposition(const event::Reposition &e) {}
virtual void onResize(const event::Resize &e) {}
virtual void onAdd(const event::Add &e) {}
virtual void onRemove(const event::Remove &e) {}
virtual void onShow(const event::Show &e) {recurseEvent(&Widget::onShow, e);}
virtual void onHide(const event::Hide &e) {recurseEvent(&Widget::onHide, e);}
virtual void onHover(const HoverEvent &e) {recursePositionEvent(&Widget::onHover, e);}
virtual void onButton(const ButtonEvent &e) {recursePositionEvent(&Widget::onButton, e);}
virtual void onDoubleClick(const DoubleClickEvent &e) {}
virtual void onHoverKey(const HoverKeyEvent &e) {recursePositionEvent(&Widget::onHoverKey, e);}
virtual void onHoverText(const HoverTextEvent &e) {recursePositionEvent(&Widget::onHoverText, e);}
virtual void onHoverScroll(const HoverScrollEvent &e) {recursePositionEvent(&Widget::onHoverScroll, e);}
virtual void onEnter(const EnterEvent &e) {}
virtual void onLeave(const LeaveEvent &e) {}
virtual void onSelect(const SelectEvent &e) {}
virtual void onDeselect(const DeselectEvent &e) {}
virtual void onSelectKey(const SelectKeyEvent &e) {}
virtual void onSelectText(const SelectTextEvent &e) {}
virtual void onDragStart(const DragStartEvent &e) {}
virtual void onDragEnd(const DragEndEvent &e) {}
virtual void onDragMove(const DragMoveEvent &e) {}
virtual void onDragHover(const DragHoverEvent &e) {recursePositionEvent(&Widget::onDragHover, e);}
virtual void onDragEnter(const DragEnterEvent &e) {}
virtual void onDragLeave(const DragLeaveEvent &e) {}
virtual void onDragDrop(const DragDropEvent &e) {}
virtual void onPathDrop(const PathDropEvent &e) {recursePositionEvent(&Widget::onPathDrop, e);}
virtual void onAction(const ActionEvent &e) {}
virtual void onChange(const ChangeEvent &e) {}
virtual void onZoom(const ZoomEvent &e) {recurseEvent(&Widget::onZoom, e);}
virtual void onReposition(const RepositionEvent &e) {}
virtual void onResize(const ResizeEvent &e) {}
virtual void onAdd(const AddEvent &e) {}
virtual void onRemove(const RemoveEvent &e) {}
virtual void onShow(const ShowEvent &e) {recurseEvent(&Widget::onShow, e);}
virtual void onHide(const HideEvent &e) {recurseEvent(&Widget::onHide, e);}
};




+ 14
- 14
include/widget/ZoomWidget.hpp View File

@@ -15,38 +15,38 @@ struct ZoomWidget : Widget {
void setZoom(float zoom);
void draw(const DrawArgs &args) override;

void onHover(const event::Hover &e) override {
event::Hover e2 = e;
void onHover(const HoverEvent &e) override {
HoverEvent e2 = e;
e2.pos = e.pos.div(zoom);
Widget::onHover(e2);
}
void onButton(const event::Button &e) override {
event::Button e2 = e;
void onButton(const ButtonEvent &e) override {
ButtonEvent e2 = e;
e2.pos = e.pos.div(zoom);
Widget::onButton(e2);
}
void onHoverKey(const event::HoverKey &e) override {
event::HoverKey e2 = e;
void onHoverKey(const HoverKeyEvent &e) override {
HoverKeyEvent e2 = e;
e2.pos = e.pos.div(zoom);
Widget::onHoverKey(e2);
}
void onHoverText(const event::HoverText &e) override {
event::HoverText e2 = e;
void onHoverText(const HoverTextEvent &e) override {
HoverTextEvent e2 = e;
e2.pos = e.pos.div(zoom);
Widget::onHoverText(e2);
}
void onHoverScroll(const event::HoverScroll &e) override {
event::HoverScroll e2 = e;
void onHoverScroll(const HoverScrollEvent &e) override {
HoverScrollEvent e2 = e;
e2.pos = e.pos.div(zoom);
Widget::onHoverScroll(e2);
}
void onDragHover(const event::DragHover &e) override {
event::DragHover e2 = e;
void onDragHover(const DragHoverEvent &e) override {
DragHoverEvent e2 = e;
e2.pos = e.pos.div(zoom);
Widget::onDragHover(e2);
}
void onPathDrop(const event::PathDrop &e) override {
event::PathDrop e2 = e;
void onPathDrop(const PathDropEvent &e) override {
PathDropEvent e2 = e;
e2.pos = e.pos.div(zoom);
Widget::onPathDrop(e2);
}


include/event.hpp → include/widget/event.hpp View File

@@ -5,47 +5,41 @@


namespace rack {


namespace widget {
struct Widget;
} // namespace widget


/** Event state machine for Widgets
*/
namespace event {
struct Widget;


struct Context {
struct EventContext {
/** The Widget that consumes the event.
This stops propagation of the event if applicable.
*/
widget::Widget *consumed = NULL;
Widget *consumed = NULL;
};


/** Base event class */
struct Event {
Context *context = NULL;
EventContext *context = NULL;

void consume(widget::Widget *w) const {
void consume(Widget *w) const {
if (context)
context->consumed = w;
}
widget::Widget *getConsumed() const {
Widget *getConsumed() const {
return context ? context->consumed : NULL;
}
};


struct Position {
struct PositionEvent {
/** The pixel coordinate where the event occurred, relative to the Widget it is called on. */
math::Vec pos;
};


struct Key {
struct KeyEvent {
/** GLFW_KEY_* */
int key;
/** GLFW_KEY_*. You should usually use `key` instead. */
@@ -58,7 +52,7 @@ struct Key {

// Events

struct Text {
struct TextEvent {
/** Unicode code point of the character */
int codepoint;
};
@@ -68,7 +62,7 @@ struct Text {
Recurses until consumed.
If `target` is set, other events may occur on that Widget.
*/
struct Hover : Event, Position {
struct HoverEvent : Event, PositionEvent {
/** Change in mouse position since the last frame. Can be zero. */
math::Vec mouseDelta;
};
@@ -78,7 +72,7 @@ struct Hover : Event, Position {
Recurses until consumed.
If `target` is set, other events may occur on that Widget.
*/
struct Button : Event, Position {
struct ButtonEvent : Event, PositionEvent {
/** GLFW_MOUSE_BUTTON_LEFT, GLFW_MOUSE_BUTTON_RIGHT, GLFW_MOUSE_BUTTON_MIDDLE, etc. */
int button;
/** GLFW_PRESS or GLFW_RELEASE */
@@ -90,28 +84,28 @@ struct Button : Event, Position {

/** Occurs when the left mouse button is pressed the second time within a time and position window.
*/
struct DoubleClick : Event {
struct DoubleClickEvent : Event {
};


/** Occurs when a key is pressed, released, or repeated while the mouse is hovering a Widget.
Recurses until consumed.
*/
struct HoverKey : Event, Position, Key {
struct HoverKeyEvent : Event, PositionEvent, KeyEvent {
};


/** Occurs when a character is typed while the mouse is hovering a Widget.
Recurses until consumed.
*/
struct HoverText : Event, Position, Text {
struct HoverTextEvent : Event, PositionEvent, TextEvent {
};


/** Occurs when the mouse scroll wheel is moved while the mouse is hovering a Widget.
Recurses until consumed.
*/
struct HoverScroll : Event, Position {
struct HoverScrollEvent : Event, PositionEvent {
/** Change of scroll wheel position. */
math::Vec scrollDelta;
};
@@ -120,59 +114,59 @@ struct HoverScroll : Event, Position {
/** Occurs when a Widget begins consuming the Hover event.
Must consume to set the widget as hovered.
*/
struct Enter : Event {
struct EnterEvent : Event {
};


/** Occurs when a different Widget is entered.
*/
struct Leave : Event {
struct LeaveEvent : Event {
};


/** Occurs when a Widget begins consuming the Button press event.
Must consume to set the widget as selected.
*/
struct Select : Event {
struct SelectEvent : Event {
};


/** Occurs when a different Widget is selected.
*/
struct Deselect : Event {
struct DeselectEvent : Event {
};


/** Occurs when a key is pressed, released, or repeated while a Widget is selected.
If consumed, a HoverKey event will not be triggered.
*/
struct SelectKey : Event, Key {
struct SelectKeyEvent : Event, KeyEvent {
};


/** Occurs when text is typed while a Widget is selected.
If consumed, a HoverText event will not be triggered.
*/
struct SelectText : Event, Text {
struct SelectTextEvent : Event, TextEvent {
};


/** Occurs when a Widget begins being dragged.
Must consume to set the widget as dragged.
*/
struct DragStart : Event {
struct DragStartEvent : Event {
};


/** Occurs when a Widget stops being dragged by releasing the mouse button.
*/
struct DragEnd : Event {
struct DragEndEvent : Event {
};


/** Occurs every frame on the dragged Widget.
*/
struct DragMove : Event {
struct DragMoveEvent : Event {
/** Change in mouse position since the last frame. Can be zero. */
math::Vec mouseDelta;
};
@@ -181,9 +175,9 @@ struct DragMove : Event {
/** Occurs every frame when the mouse is hovering over a Widget while another Widget (possibly the same one) is being dragged.
Recurses until consumed.
*/
struct DragHover : Event, Position {
struct DragHoverEvent : Event, PositionEvent {
/** The dragged widget */
widget::Widget *origin = NULL;
Widget *origin = NULL;
/** Change in mouse position since the last frame. Can be zero. */
math::Vec mouseDelta;
};
@@ -191,33 +185,33 @@ struct DragHover : Event, Position {
/** Occurs when the mouse enters a Widget while dragging.
Must consume to set the widget as drag-hovered.
*/
struct DragEnter : Event {
struct DragEnterEvent : Event {
/** The dragged widget */
widget::Widget *origin = NULL;
Widget *origin = NULL;
};


/** Occurs when the mouse leaves a Widget while dragging.
*/
struct DragLeave : Event {
struct DragLeaveEvent : Event {
/** The dragged widget */
widget::Widget *origin = NULL;
Widget *origin = NULL;
};


/** Occurs when the mouse button is released over a Widget while dragging.
*/
struct DragDrop : Event {
struct DragDropEvent : Event {
/** The dragged widget */
widget::Widget *origin = NULL;
Widget *origin = NULL;
};


/** Occurs when a selection of files from the operating system is dropped onto a Widget.
Recurses until consumed.
*/
struct PathDrop : Event, Position {
PathDrop(const std::vector<std::string> &paths) : paths(paths) {}
struct PathDropEvent : Event, PositionEvent {
PathDropEvent(const std::vector<std::string> &paths) : paths(paths) {}

/** List of file paths in the dropped selection */
const std::vector<std::string> &paths;
@@ -227,79 +221,79 @@ struct PathDrop : Event, Position {
/** Occurs after a certain action is triggered on a Widget.
The concept of an "action" is dependent on the type of Widget.
*/
struct Action : Event {
struct ActionEvent : Event {
};


/** Occurs after the value of a Widget changes.
The concept of a "value" is dependent on the type of Widget.
*/
struct Change : Event {
struct ChangeEvent : Event {
};


/** Occurs after the zoom level of a Widget is changed.
Recurses until consumed.
*/
struct Zoom : Event {
struct ZoomEvent : Event {
};


/** Occurs after a Widget's position is set by Widget::setPos().
*/
struct Reposition : Event {
struct RepositionEvent : Event {
};


/** Occurs after a Widget's size is set by Widget::setSize().
*/
struct Resize : Event {
struct ResizeEvent : Event {
};


/** Occurs after a Widget is added to a parent.
*/
struct Add : Event {
struct AddEvent : Event {
};


/** Occurs before a Widget is removed from its parent.
*/
struct Remove : Event {
struct RemoveEvent : Event {
};


/** Occurs after a Widget is shown with Widget::show().
*/
struct Show : Event {
struct ShowEvent : Event {
};


/** Occurs after a Widget is hidden with Widget::hide().
*/
struct Hide : Event {
struct HideEvent : Event {
};


struct State {
widget::Widget *rootWidget = NULL;
struct EventState {
Widget *rootWidget = NULL;
/** State widgets
Don't set these directly unless you know what you're doing. Use the set*() methods instead.
*/
widget::Widget *hoveredWidget = NULL;
widget::Widget *draggedWidget = NULL;
widget::Widget *dragHoveredWidget = NULL;
widget::Widget *selectedWidget = NULL;
Widget *hoveredWidget = NULL;
Widget *draggedWidget = NULL;
Widget *dragHoveredWidget = NULL;
Widget *selectedWidget = NULL;
/** For double-clicking */
double lastClickTime = -INFINITY;
widget::Widget *lastClickedWidget = NULL;
Widget *lastClickedWidget = NULL;

void setHovered(widget::Widget *w);
void setDragged(widget::Widget *w);
void setDragHovered(widget::Widget *w);
void setSelected(widget::Widget *w);
void setHovered(Widget *w);
void setDragged(Widget *w);
void setDragHovered(Widget *w);
void setSelected(Widget *w);
/** Prepares a widget for deletion */
void finalizeWidget(widget::Widget *w);
void finalizeWidget(Widget *w);

void handleButton(math::Vec pos, int button, int action, int mods);
void handleHover(math::Vec pos, math::Vec mouseDelta);
@@ -312,5 +306,5 @@ struct State {
};


} // namespace event
} // namespace widget
} // namespace rack

+ 3
- 3
src/Core/Blank.cpp View File

@@ -36,20 +36,20 @@ struct ModuleResizeHandle : Widget {
box.size = Vec(RACK_GRID_WIDTH * 1, RACK_GRID_HEIGHT);
}

void onButton(const event::Button &e) override {
void onButton(const widget::ButtonEvent &e) override {
if (e.button == GLFW_MOUSE_BUTTON_LEFT) {
e.consume(this);
}
}

void onDragStart(const event::DragStart &e) override {
void onDragStart(const widget::DragStartEvent &e) override {
dragX = APP->scene->rackWidget->mousePos.x;
ModuleWidget *m = getAncestorOfType<ModuleWidget>();
originalBox = m->box;
e.consume(this);
}

void onDragMove(const event::DragMove &e) override {
void onDragMove(const widget::DragMoveEvent &e) override {
ModuleWidget *m = getAncestorOfType<ModuleWidget>();

float newDragX = APP->scene->rackWidget->mousePos.x;


+ 2
- 2
src/Core/CV_Gate.cpp View File

@@ -145,7 +145,7 @@ struct CV_Gate : Module {

struct CV_GateVelocityItem : MenuItem {
CV_Gate *module;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
module->velocityMode ^= true;
}
};
@@ -153,7 +153,7 @@ struct CV_GateVelocityItem : MenuItem {

struct CV_GatePanicItem : MenuItem {
CV_Gate *module;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
module->midiOutput.panic();
}
};


+ 1
- 1
src/Core/CV_MIDI.cpp View File

@@ -319,7 +319,7 @@ struct CV_MIDI : Module {

struct CV_MIDIPanicItem : MenuItem {
CV_MIDI *module;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
module->midiOutput.panic();
}
};


+ 4
- 4
src/Core/MIDI_CV.cpp View File

@@ -419,7 +419,7 @@ struct MIDI_CV : Module {
struct ClockDivisionValueItem : MenuItem {
MIDI_CV *module;
int clockDivision;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
module->clockDivision = clockDivision;
}
};
@@ -447,7 +447,7 @@ struct ClockDivisionItem : MenuItem {
struct ChannelValueItem : MenuItem {
MIDI_CV *module;
int channels;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
module->setChannels(channels);
}
};
@@ -476,7 +476,7 @@ struct ChannelItem : MenuItem {
struct PolyModeValueItem : MenuItem {
MIDI_CV *module;
MIDI_CV::PolyMode polyMode;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
module->setPolyMode(polyMode);
}
};
@@ -508,7 +508,7 @@ struct PolyModeItem : MenuItem {

struct MIDI_CVPanicItem : MenuItem {
MIDI_CV *module;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
module->panic();
}
};


+ 2
- 2
src/Core/MIDI_Gate.cpp View File

@@ -151,7 +151,7 @@ struct MIDI_Gate : Module {

struct MIDI_GateVelocityItem : MenuItem {
MIDI_Gate *module;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
module->velocityMode ^= true;
}
};
@@ -159,7 +159,7 @@ struct MIDI_GateVelocityItem : MenuItem {

struct MIDI_GatePanicItem : MenuItem {
MIDI_Gate *module;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
module->panic();
}
};


+ 3
- 3
src/Core/MIDI_Map.cpp View File

@@ -245,7 +245,7 @@ struct MIDI_MapChoice : LedDisplayChoice {
this->module = module;
}

void onButton(const event::Button &e) override {
void onButton(const widget::ButtonEvent &e) override {
if (!module)
return;

@@ -259,7 +259,7 @@ struct MIDI_MapChoice : LedDisplayChoice {
}
}

void onSelect(const event::Select &e) override {
void onSelect(const widget::SelectEvent &e) override {
if (!module)
return;

@@ -272,7 +272,7 @@ struct MIDI_MapChoice : LedDisplayChoice {
e.consume(this);
}

void onDeselect(const event::Deselect &e) override {
void onDeselect(const widget::DeselectEvent &e) override {
if (!module)
return;
// Check if a ParamWidget was touched


+ 7
- 7
src/Core/plugin.hpp View File

@@ -93,7 +93,7 @@ struct CcChoice : LedDisplayChoice {
}
}

void onSelect(const event::Select &e) override {
void onSelect(const widget::SelectEvent &e) override {
if (!module)
return;
module->learningId = id;
@@ -101,7 +101,7 @@ struct CcChoice : LedDisplayChoice {
e.consume(this);
}

void onDeselect(const event::Deselect &e) override {
void onDeselect(const widget::DeselectEvent &e) override {
if (!module)
return;
if (module->learningId == id) {
@@ -112,7 +112,7 @@ struct CcChoice : LedDisplayChoice {
}
}

void onSelectText(const event::SelectText &e) override {
void onSelectText(const widget::SelectTextEvent &e) override {
int c = e.codepoint - '0';
if (0 <= c && c <= 9) {
if (focusCc < 0)
@@ -124,9 +124,9 @@ struct CcChoice : LedDisplayChoice {
e.consume(this);
}

void onSelectKey(const event::SelectKey &e) override {
void onSelectKey(const widget::SelectKeyEvent &e) override {
if ((e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER) && e.action == GLFW_PRESS && (e.mods & WINDOW_MOD_MASK) == 0) {
event::Deselect eDeselect;
widget::DeselectEvent eDeselect;
onDeselect(eDeselect);
APP->event->selectedWidget = NULL;
e.consume(this);
@@ -177,14 +177,14 @@ struct NoteChoice : LedDisplayChoice {
}
}

void onSelect(const event::Select &e) override {
void onSelect(const widget::SelectEvent &e) override {
if (!module)
return;
module->learningId = id;
e.consume(this);
}

void onDeselect(const event::Deselect &e) override {
void onDeselect(const widget::DeselectEvent &e) override {
if (!module)
return;
if (module->learningId == id) {


+ 2
- 2
src/app.cpp View File

@@ -1,5 +1,5 @@
#include "app.hpp"
#include "event.hpp"
#include "widget/event.hpp"
#include "window.hpp"
#include "patch.hpp"
#include "engine/Engine.hpp"
@@ -13,7 +13,7 @@ namespace rack {
void App::init(bool headless) {
engine = new engine::Engine;
if (!headless) {
event = new event::State;
event = new widget::EventState;
history = new history::State;
window = new Window;
patch = new PatchManager;


+ 8
- 8
src/app/AudioWidget.cpp View File

@@ -10,14 +10,14 @@ namespace app {
struct AudioDriverItem : ui::MenuItem {
audio::Port *port;
int driver;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
port->setDriver(driver);
}
};

struct AudioDriverChoice : LedDisplayChoice {
audio::Port *port;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
if (!port)
return;

@@ -45,7 +45,7 @@ struct AudioDeviceItem : ui::MenuItem {
audio::Port *port;
int device;
int offset;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
port->setDevice(device, offset);
}
};
@@ -55,7 +55,7 @@ struct AudioDeviceChoice : LedDisplayChoice {
/** Prevents devices with a ridiculous number of channels from being displayed */
int maxTotalChannels = 128;

void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
if (!port)
return;

@@ -103,14 +103,14 @@ struct AudioDeviceChoice : LedDisplayChoice {
struct AudioSampleRateItem : ui::MenuItem {
audio::Port *port;
int sampleRate;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
port->setSampleRate(sampleRate);
}
};

struct AudioSampleRateChoice : LedDisplayChoice {
audio::Port *port;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
if (!port)
return;

@@ -141,14 +141,14 @@ struct AudioSampleRateChoice : LedDisplayChoice {
struct AudioBlockSizeItem : ui::MenuItem {
audio::Port *port;
int blockSize;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
port->setBlockSize(blockSize);
}
};

struct AudioBlockSizeChoice : LedDisplayChoice {
audio::Port *port;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
if (!port)
return;



+ 1
- 1
src/app/CableWidget.cpp View File

@@ -1,7 +1,7 @@
#include "app/CableWidget.hpp"
#include "app/Scene.hpp"
#include "window.hpp"
#include "event.hpp"
#include "widget/event.hpp"
#include "app.hpp"
#include "patch.hpp"
#include "settings.hpp"


+ 5
- 5
src/app/Knob.cpp View File

@@ -11,7 +11,7 @@ namespace app {
static const float KNOB_SENSITIVITY = 0.0015f;


void Knob::onHover(const event::Hover &e) {
void Knob::onHover(const widget::HoverEvent &e) {
math::Vec c = box.size.div(2);
float dist = e.pos.minus(c).norm();
if (dist <= c.x) {
@@ -19,7 +19,7 @@ void Knob::onHover(const event::Hover &e) {
}
}

void Knob::onButton(const event::Button &e) {
void Knob::onButton(const widget::ButtonEvent &e) {
math::Vec c = box.size.div(2);
float dist = e.pos.minus(c).norm();
if (dist <= c.x) {
@@ -27,7 +27,7 @@ void Knob::onButton(const event::Button &e) {
}
}

void Knob::onDragStart(const event::DragStart &e) {
void Knob::onDragStart(const widget::DragStartEvent &e) {
if (paramQuantity) {
oldValue = paramQuantity->getSmoothValue();
if (snap) {
@@ -39,7 +39,7 @@ void Knob::onDragStart(const event::DragStart &e) {
e.consume(this);
}

void Knob::onDragEnd(const event::DragEnd &e) {
void Knob::onDragEnd(const widget::DragEndEvent &e) {
APP->window->cursorUnlock();

if (paramQuantity) {
@@ -57,7 +57,7 @@ void Knob::onDragEnd(const event::DragEnd &e) {
}
}

void Knob::onDragMove(const event::DragMove &e) {
void Knob::onDragMove(const widget::DragMoveEvent &e) {
if (paramQuantity) {
float range;
if (paramQuantity->isBounded()) {


+ 3
- 3
src/app/LedDisplay.cpp View File

@@ -1,7 +1,7 @@
#include "app/LedDisplay.hpp"
#include "asset.hpp"
#include "window.hpp"
#include "event.hpp"
#include "widget/event.hpp"
#include "app.hpp"


@@ -62,9 +62,9 @@ void LedDisplayChoice::draw(const DrawArgs &args) {
}
}

void LedDisplayChoice::onButton(const event::Button &e) {
void LedDisplayChoice::onButton(const widget::ButtonEvent &e) {
if (e.action == GLFW_PRESS && (e.button == GLFW_MOUSE_BUTTON_LEFT || e.button == GLFW_MOUSE_BUTTON_RIGHT)) {
event::Action eAction;
widget::ActionEvent eAction;
onAction(eAction);
e.consume(this);
}


+ 6
- 6
src/app/MidiWidget.cpp View File

@@ -10,14 +10,14 @@ namespace app {
struct MidiDriverItem : ui::MenuItem {
midi::Port *port;
int driverId;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
port->setDriverId(driverId);
}
};

struct MidiDriverChoice : LedDisplayChoice {
midi::Port *port;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
if (!port)
return;

@@ -51,14 +51,14 @@ struct MidiDriverChoice : LedDisplayChoice {
struct MidiDeviceItem : ui::MenuItem {
midi::Port *port;
int deviceId;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
port->setDeviceId(deviceId);
}
};

struct MidiDeviceChoice : LedDisplayChoice {
midi::Port *port;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
if (!port)
return;

@@ -100,14 +100,14 @@ struct MidiDeviceChoice : LedDisplayChoice {
struct MidiChannelItem : ui::MenuItem {
midi::Port *port;
int channel;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
port->channel = channel;
}
};

struct MidiChannelChoice : LedDisplayChoice {
midi::Port *port;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
if (!port)
return;



+ 10
- 10
src/app/ModuleBrowser.cpp View File

@@ -61,7 +61,7 @@ struct BrowserOverlay : widget::OpaqueWidget {
OpaqueWidget::step();
}

void onButton(const event::Button &e) override {
void onButton(const widget::ButtonEvent &e) override {
OpaqueWidget::onButton(e);
if (e.getConsumed() != this)
return;
@@ -218,14 +218,14 @@ struct ModelBox : widget::OpaqueWidget {
nvgResetScissor(args.vg);
}

void onButton(const event::Button &e) override;
void onButton(const widget::ButtonEvent &e) override;

void onEnter(const event::Enter &e) override {
void onEnter(const widget::EnterEvent &e) override {
e.consume(this);
selected = true;
}

void onLeave(const event::Leave &e) override {
void onLeave(const widget::LeaveEvent &e) override {
selected = false;
}
};
@@ -238,7 +238,7 @@ struct BrowserSearchField : ui::TextField {
TextField::step();
}

void onSelectKey(const event::SelectKey &e) override {
void onSelectKey(const widget::SelectKeyEvent &e) override {
if (e.action == GLFW_PRESS) {
if (e.key == GLFW_KEY_ESCAPE) {
BrowserOverlay *overlay = getAncestorOfType<BrowserOverlay>();
@@ -251,14 +251,14 @@ struct BrowserSearchField : ui::TextField {
ui::TextField::onSelectKey(e);
}

void onChange(const event::Change &e) override;
void onChange(const widget::ChangeEvent &e) override;

void onHide(const event::Hide &e) override {
void onHide(const widget::HideEvent &e) override {
APP->event->setSelected(NULL);
ui::TextField::onHide(e);
}

void onShow(const event::Show &e) override {
void onShow(const widget::ShowEvent &e) override {
selectAll();
TextField::onShow(e);
}
@@ -415,7 +415,7 @@ struct ModuleBrowser : widget::OpaqueWidget {
// Implementations to resolve dependencies


inline void ModelBox::onButton(const event::Button &e) {
inline void ModelBox::onButton(const widget::ButtonEvent &e) {
OpaqueWidget::onButton(e);
if (e.getConsumed() != this)
return;
@@ -441,7 +441,7 @@ inline void ModelBox::onButton(const event::Button &e) {
}
}

inline void BrowserSearchField::onChange(const event::Change &e) {
inline void BrowserSearchField::onChange(const widget::ChangeEvent &e) {
ModuleBrowser *browser = getAncestorOfType<ModuleBrowser>();
browser->setSearch(text);
}


+ 19
- 19
src/app/ModuleWidget.cpp View File

@@ -23,7 +23,7 @@ static const char PRESET_FILTERS[] = "VCV Rack module preset (.vcvm):vcvm";

struct ModuleUrlItem : ui::MenuItem {
std::string url;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
std::thread t(system::openBrowser, url);
t.detach();
}
@@ -32,7 +32,7 @@ struct ModuleUrlItem : ui::MenuItem {

struct ModuleFolderItem : ui::MenuItem {
std::string path;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
std::thread t(system::openFolder, path);
t.detach();
}
@@ -104,7 +104,7 @@ struct ModulePluginItem : ui::MenuItem {

struct ModuleDisconnectItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
moduleWidget->disconnectAction();
}
};
@@ -112,7 +112,7 @@ struct ModuleDisconnectItem : ui::MenuItem {

struct ModuleResetItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
moduleWidget->resetAction();
}
};
@@ -120,7 +120,7 @@ struct ModuleResetItem : ui::MenuItem {

struct ModuleRandomizeItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
moduleWidget->randomizeAction();
}
};
@@ -128,7 +128,7 @@ struct ModuleRandomizeItem : ui::MenuItem {

struct ModuleCopyItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
moduleWidget->copyClipboard();
}
};
@@ -136,7 +136,7 @@ struct ModuleCopyItem : ui::MenuItem {

struct ModulePasteItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
moduleWidget->pasteClipboardAction();
}
};
@@ -144,7 +144,7 @@ struct ModulePasteItem : ui::MenuItem {

struct ModuleSaveItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
moduleWidget->saveDialog();
}
};
@@ -152,7 +152,7 @@ struct ModuleSaveItem : ui::MenuItem {

struct ModuleLoadItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
moduleWidget->loadDialog();
}
};
@@ -161,7 +161,7 @@ struct ModuleLoadItem : ui::MenuItem {
struct ModulePresetItem : ui::MenuItem {
ModuleWidget *moduleWidget;
std::string presetPath;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
moduleWidget->loadAction(presetPath);
}
};
@@ -188,7 +188,7 @@ struct ModuleListPresetsItem : ui::MenuItem {

struct ModuleCloneItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
moduleWidget->cloneAction();
}
};
@@ -196,7 +196,7 @@ struct ModuleCloneItem : ui::MenuItem {

struct ModuleBypassItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
moduleWidget->bypassAction();
}
};
@@ -204,7 +204,7 @@ struct ModuleBypassItem : ui::MenuItem {

struct ModuleDeleteItem : ui::MenuItem {
ModuleWidget *moduleWidget;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
moduleWidget->removeAction();
}
};
@@ -273,7 +273,7 @@ void ModuleWidget::drawShadow(const DrawArgs &args) {
nvgFill(args.vg);
}

void ModuleWidget::onHover(const event::Hover &e) {
void ModuleWidget::onHover(const widget::HoverEvent &e) {
widget::OpaqueWidget::onHover(e);

if (!APP->event->selectedWidget) {
@@ -288,7 +288,7 @@ void ModuleWidget::onHover(const event::Hover &e) {
}
}

void ModuleWidget::onButton(const event::Button &e) {
void ModuleWidget::onButton(const widget::ButtonEvent &e) {
widget::OpaqueWidget::onButton(e);

if (e.getConsumed() == this) {
@@ -298,7 +298,7 @@ void ModuleWidget::onButton(const event::Button &e) {
}
}

void ModuleWidget::onHoverKey(const event::HoverKey &e) {
void ModuleWidget::onHoverKey(const widget::HoverKeyEvent &e) {
if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) {
switch (e.key) {
case GLFW_KEY_I: {
@@ -350,13 +350,13 @@ void ModuleWidget::onHoverKey(const event::HoverKey &e) {
widget::OpaqueWidget::onHoverKey(e);
}

void ModuleWidget::onDragStart(const event::DragStart &e) {
void ModuleWidget::onDragStart(const widget::DragStartEvent &e) {
oldPos = box.pos;
dragPos = APP->scene->rackWidget->mousePos.minus(box.pos);
e.consume(this);
}

void ModuleWidget::onDragEnd(const event::DragEnd &e) {
void ModuleWidget::onDragEnd(const widget::DragEndEvent &e) {
if (!box.pos.isEqual(oldPos)) {
// history::ModuleMove
history::ModuleMove *h = new history::ModuleMove;
@@ -367,7 +367,7 @@ void ModuleWidget::onDragEnd(const event::DragEnd &e) {
}
}

void ModuleWidget::onDragMove(const event::DragMove &e) {
void ModuleWidget::onDragMove(const widget::DragMoveEvent &e) {
if (!settings.lockModules) {
math::Rect newBox = box;
newBox.pos = APP->scene->rackWidget->mousePos.minus(dragPos);


+ 8
- 8
src/app/ParamWidget.cpp View File

@@ -31,7 +31,7 @@ struct ParamField : ui::TextField {
selectAll();
}

void onSelectKey(const event::SelectKey &e) override {
void onSelectKey(const widget::SelectKeyEvent &e) override {
if (e.action == GLFW_PRESS && (e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER)) {
float oldValue = paramWidget->paramQuantity->getValue();
if (paramWidget->paramQuantity)
@@ -89,7 +89,7 @@ struct ParamLabel : ui::MenuLabel {

struct ParamResetItem : ui::MenuItem {
ParamWidget *paramWidget;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
paramWidget->resetAction();
}
};
@@ -101,7 +101,7 @@ struct ParamFineItem : ui::MenuItem {

struct ParamUnmapItem : ui::MenuItem {
ParamWidget *paramWidget;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
engine::ParamHandle *paramHandle = APP->engine->getParamHandle(paramWidget->paramQuantity->module, paramWidget->paramQuantity->paramId);
if (paramHandle) {
APP->engine->updateParamHandle(paramHandle, -1, 0);
@@ -121,7 +121,7 @@ void ParamWidget::step() {
// Trigger change event when paramQuantity value changes
if (value != dirtyValue) {
dirtyValue = value;
event::Change eChange;
widget::ChangeEvent eChange;
onChange(eChange);
}
}
@@ -146,7 +146,7 @@ void ParamWidget::draw(const DrawArgs &args) {
}
}

void ParamWidget::onButton(const event::Button &e) {
void ParamWidget::onButton(const widget::ButtonEvent &e) {
// Touch parameter
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT && (e.mods & WINDOW_MOD_MASK) == 0) {
if (paramQuantity) {
@@ -164,11 +164,11 @@ void ParamWidget::onButton(const event::Button &e) {
OpaqueWidget::onButton(e);
}

void ParamWidget::onDoubleClick(const event::DoubleClick &e) {
void ParamWidget::onDoubleClick(const widget::DoubleClickEvent &e) {
resetAction();
}

void ParamWidget::onEnter(const event::Enter &e) {
void ParamWidget::onEnter(const widget::EnterEvent &e) {
if (settings.paramTooltip && !tooltip && paramQuantity) {
ParamTooltip *paramTooltip = new ParamTooltip;
paramTooltip->paramWidget = this;
@@ -178,7 +178,7 @@ void ParamWidget::onEnter(const event::Enter &e) {
}
}

void ParamWidget::onLeave(const event::Leave &e) {
void ParamWidget::onLeave(const widget::LeaveEvent &e) {
if (tooltip) {
APP->scene->removeChild(tooltip);
delete tooltip;


+ 8
- 8
src/app/PortWidget.cpp View File

@@ -59,7 +59,7 @@ void PortWidget::draw(const DrawArgs &args) {
Widget::draw(args);
}

void PortWidget::onButton(const event::Button &e) {
void PortWidget::onButton(const widget::ButtonEvent &e) {
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) {
CableWidget *cw = APP->scene->rackWidget->getTopCable(this);
if (cw) {
@@ -75,16 +75,16 @@ void PortWidget::onButton(const event::Button &e) {
e.consume(this);
}

void PortWidget::onEnter(const event::Enter &e) {
void PortWidget::onEnter(const widget::EnterEvent &e) {
hovered = true;
e.consume(this);
}

void PortWidget::onLeave(const event::Leave &e) {
void PortWidget::onLeave(const widget::LeaveEvent &e) {
hovered = false;
}

void PortWidget::onDragStart(const event::DragStart &e) {
void PortWidget::onDragStart(const widget::DragStartEvent &e) {
CableWidget *cw = NULL;
if ((APP->window->getMods() & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) {
if (type == OUTPUT) {
@@ -130,7 +130,7 @@ void PortWidget::onDragStart(const event::DragStart &e) {
e.consume(this);
}

void PortWidget::onDragEnd(const event::DragEnd &e) {
void PortWidget::onDragEnd(const widget::DragEndEvent &e) {
CableWidget *cw = APP->scene->rackWidget->releaseIncompleteCable();
if (cw->isComplete()) {
APP->scene->rackWidget->addCable(cw);
@@ -145,7 +145,7 @@ void PortWidget::onDragEnd(const event::DragEnd &e) {
}
}

void PortWidget::onDragDrop(const event::DragDrop &e) {
void PortWidget::onDragDrop(const widget::DragDropEvent &e) {
// Reject ports if this is an input port and something is already plugged into it
if (type == INPUT) {
if (APP->scene->rackWidget->getTopCable(this))
@@ -162,7 +162,7 @@ void PortWidget::onDragDrop(const event::DragDrop &e) {
}
}

void PortWidget::onDragEnter(const event::DragEnter &e) {
void PortWidget::onDragEnter(const widget::DragEnterEvent &e) {
// Reject ports if this is an input port and something is already plugged into it
if (type == INPUT) {
if (APP->scene->rackWidget->getTopCable(this))
@@ -179,7 +179,7 @@ void PortWidget::onDragEnter(const event::DragEnter &e) {
e.consume(this);
}

void PortWidget::onDragLeave(const event::DragLeave &e) {
void PortWidget::onDragLeave(const widget::DragLeaveEvent &e) {
PortWidget *originPort = dynamic_cast<PortWidget*>(e.origin);
if (!originPort)
return;


+ 5
- 5
src/app/RackWidget.cpp View File

@@ -121,7 +121,7 @@ void RackWidget::draw(const DrawArgs &args) {
Widget::draw(args);
}

void RackWidget::onHover(const event::Hover &e) {
void RackWidget::onHover(const widget::HoverEvent &e) {
if (!APP->event->selectedWidget) {
// Scroll with arrow keys
float arrowSpeed = 30.0;
@@ -151,7 +151,7 @@ void RackWidget::onHover(const event::Hover &e) {
mousePos = e.pos;
}

void RackWidget::onHoverKey(const event::HoverKey &e) {
void RackWidget::onHoverKey(const widget::HoverKeyEvent &e) {
widget::OpaqueWidget::onHoverKey(e);
if (e.getConsumed() != this)
return;
@@ -167,12 +167,12 @@ void RackWidget::onHoverKey(const event::HoverKey &e) {
}
}

void RackWidget::onDragHover(const event::DragHover &e) {
void RackWidget::onDragHover(const widget::DragHoverEvent &e) {
widget::OpaqueWidget::onDragHover(e);
mousePos = e.pos;
}

void RackWidget::onButton(const event::Button &e) {
void RackWidget::onButton(const widget::ButtonEvent &e) {
widget::OpaqueWidget::onButton(e);
if (e.getConsumed() == this) {
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) {
@@ -181,7 +181,7 @@ void RackWidget::onButton(const event::Button &e) {
}
}

void RackWidget::onZoom(const event::Zoom &e) {
void RackWidget::onZoom(const widget::ZoomEvent &e) {
rails->box.size = math::Vec();
widget::OpaqueWidget::onZoom(e);
}


+ 2
- 2
src/app/Scene.cpp View File

@@ -91,7 +91,7 @@ void Scene::draw(const DrawArgs &args) {
OpaqueWidget::draw(args);
}

void Scene::onHoverKey(const event::HoverKey &e) {
void Scene::onHoverKey(const widget::HoverKeyEvent &e) {
if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) {
switch (e.key) {
case GLFW_KEY_N: {
@@ -152,7 +152,7 @@ void Scene::onHoverKey(const event::HoverKey &e) {
OpaqueWidget::onHoverKey(e);
}

void Scene::onPathDrop(const event::PathDrop &e) {
void Scene::onPathDrop(const widget::PathDropEvent &e) {
if (e.paths.size() >= 1) {
const std::string &path = e.paths[0];
if (string::extension(path) == "vcv") {


+ 4
- 4
src/app/SvgButton.cpp View File

@@ -23,7 +23,7 @@ void SvgButton::addFrame(std::shared_ptr<Svg> svg) {
}
}

void SvgButton::onDragStart(const event::DragStart &e) {
void SvgButton::onDragStart(const widget::DragStartEvent &e) {
if (frames.size() >= 2) {
sw->setSvg(frames[1]);
fb->dirty = true;
@@ -31,16 +31,16 @@ void SvgButton::onDragStart(const event::DragStart &e) {
e.consume(this);
}

void SvgButton::onDragEnd(const event::DragEnd &e) {
void SvgButton::onDragEnd(const widget::DragEndEvent &e) {
if (frames.size() >= 1) {
sw->setSvg(frames[0]);
fb->dirty = true;
}
}

void SvgButton::onDragDrop(const event::DragDrop &e) {
void SvgButton::onDragDrop(const widget::DragDropEvent &e) {
if (e.origin == this) {
event::Action eAction;
widget::ActionEvent eAction;
onAction(eAction);
}
}


+ 1
- 1
src/app/SvgKnob.cpp View File

@@ -31,7 +31,7 @@ void SvgKnob::setSvg(std::shared_ptr<Svg> svg) {
// shadow->box = shadow->box.grow(math::Vec(2, 2));
}

void SvgKnob::onChange(const event::Change &e) {
void SvgKnob::onChange(const widget::ChangeEvent &e) {
// Re-transform the widget::TransformWidget
if (paramQuantity) {
float angle;


+ 1
- 1
src/app/SvgSlider.cpp View File

@@ -30,7 +30,7 @@ void SvgSlider::setHandleSvg(std::shared_ptr<Svg> svg) {
fb->dirty = true;
}

void SvgSlider::onChange(const event::Change &e) {
void SvgSlider::onChange(const widget::ChangeEvent &e) {
if (paramQuantity) {
// Interpolate handle position
float v = paramQuantity->getScaledValue();


+ 1
- 1
src/app/SvgSwitch.cpp View File

@@ -23,7 +23,7 @@ void SvgSwitch::addFrame(std::shared_ptr<Svg> svg) {
}
}

void SvgSwitch::onChange(const event::Change &e) {
void SvgSwitch::onChange(const widget::ChangeEvent &e) {
if (!frames.empty() && paramQuantity) {
int index = (int) std::round(paramQuantity->getValue());
index = math::clamp(index, 0, (int) frames.size() - 1);


+ 3
- 3
src/app/Switch.cpp View File

@@ -23,11 +23,11 @@ void Switch::step() {
ParamWidget::step();
}

void Switch::onDoubleClick(const event::DoubleClick &e) {
void Switch::onDoubleClick(const widget::DoubleClickEvent &e) {
// Don't reset parameter on double-click
}

void Switch::onDragStart(const event::DragStart &e) {
void Switch::onDragStart(const widget::DragStartEvent &e) {
if (momentary) {
if (paramQuantity) {
// Set to maximum value
@@ -63,7 +63,7 @@ void Switch::onDragStart(const event::DragStart &e) {
e.consume(this);
}

void Switch::onDragEnd(const event::DragEnd &e) {
void Switch::onDragEnd(const widget::DragEndEvent &e) {
if (momentary) {
momentaryReleased = true;
}


+ 34
- 34
src/app/Toolbar.cpp View File

@@ -34,63 +34,63 @@ struct MenuButton : ui::Button {


struct NewItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
APP->patch->resetDialog();
}
};


struct OpenItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
APP->patch->loadDialog();
}
};


struct SaveItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
APP->patch->saveDialog();
}
};


struct SaveAsItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
APP->patch->saveAsDialog();
}
};


struct SaveTemplateItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
APP->patch->saveTemplateDialog();
}
};


struct RevertItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
APP->patch->revertDialog();
}
};


struct DisconnectCablesItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
APP->patch->disconnectDialog();
}
};


struct QuitItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
APP->window->close();
}
};


struct FileButton : MenuButton {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
ui::Menu *menu = createMenu();
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
menu->box.size.x = box.size.x;
@@ -136,21 +136,21 @@ struct FileButton : MenuButton {


struct UndoItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
APP->history->undo();
}
};


struct RedoItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
APP->history->redo();
}
};


struct EditButton : MenuButton {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
ui::Menu *menu = createMenu();
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
menu->box.size.x = box.size.x;
@@ -217,28 +217,28 @@ struct CableTensionQuantity : ui::Quantity {


struct CpuMeterItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
settings.cpuMeter ^= true;
}
};


struct ParamTooltipItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
settings.paramTooltip ^= true;
}
};


struct LockModulesItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
settings.lockModules ^= true;
}
};


struct EnginePauseItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
APP->engine->setPaused(!APP->engine->isPaused());
}
};
@@ -246,7 +246,7 @@ struct EnginePauseItem : ui::MenuItem {

struct SampleRateValueItem : ui::MenuItem {
float sampleRate;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
APP->engine->setSampleRate(sampleRate);
APP->engine->setPaused(false);
}
@@ -293,7 +293,7 @@ struct ThreadCountValueItem : ui::MenuItem {
text += " (lowest CPU usage)";
rightText = CHECKMARK(APP->engine->getThreadCount() == threadCount);
}
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
APP->engine->setThreadCount(threadCount);
}
};
@@ -315,14 +315,14 @@ struct ThreadCount : ui::MenuItem {


struct FullscreenItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
APP->window->setFullScreen(!APP->window->isFullScreen());
}
};


struct SettingsButton : MenuButton {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
ui::Menu *menu = createMenu();
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
menu->box.size.x = box.size.x;
@@ -378,7 +378,7 @@ struct SettingsButton : MenuButton {


struct RegisterItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
std::thread t([&]() {
system::openBrowser("https://vcvrack.com/");
});
@@ -389,7 +389,7 @@ struct RegisterItem : ui::MenuItem {

struct AccountEmailField : ui::TextField {
ui::TextField *passwordField;
void onSelectKey(const event::SelectKey &e) override {
void onSelectKey(const widget::SelectKeyEvent &e) override {
if (e.action == GLFW_PRESS && e.key == GLFW_KEY_TAB) {
APP->event->selectedWidget = passwordField;
e.consume(this);
@@ -403,7 +403,7 @@ struct AccountEmailField : ui::TextField {

struct AccountPasswordField : ui::PasswordField {
ui::MenuItem *logInItem;
void onSelectKey(const event::SelectKey &e) override {
void onSelectKey(const widget::SelectKeyEvent &e) override {
if (e.action == GLFW_PRESS && (e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER)) {
logInItem->doAction();
e.consume(this);
@@ -418,7 +418,7 @@ struct AccountPasswordField : ui::PasswordField {
struct LogInItem : ui::MenuItem {
ui::TextField *emailField;
ui::TextField *passwordField;
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
std::string email = emailField->text;
std::string password = passwordField->text;
std::thread t([&, email, password]() {
@@ -432,7 +432,7 @@ struct LogInItem : ui::MenuItem {
struct ManageItem : ui::MenuItem {
ManageItem() {
}
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
std::thread t([&]() {
system::openBrowser("https://vcvrack.com/plugins.html");
});
@@ -442,7 +442,7 @@ struct ManageItem : ui::MenuItem {


struct SyncItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
}
};

@@ -472,7 +472,7 @@ struct SyncItem : ui::MenuItem {
// completed = false;
// }
// }
// void onAction(const event::Action &e) override {
// void onAction(const widget::ActionEvent &e) override {
// available = false;
// std::thread t([this]() {
// if (plugin::sync(false))
@@ -484,7 +484,7 @@ struct SyncItem : ui::MenuItem {


struct LogOutItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
plugin::logOut();
}
};
@@ -510,7 +510,7 @@ struct DownloadQuantity : ui::Quantity {


struct PluginsButton : MenuButton {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
ui::Menu *menu = createMenu();
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
menu->box.size.x = box.size.x;
@@ -576,7 +576,7 @@ struct PluginsButton : MenuButton {


struct ManualItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
std::thread t(system::openBrowser, "https://vcvrack.com/manual/");
t.detach();
}
@@ -584,7 +584,7 @@ struct ManualItem : ui::MenuItem {


struct WebsiteItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
std::thread t(system::openBrowser, "https://vcvrack.com/");
t.detach();
}
@@ -592,14 +592,14 @@ struct WebsiteItem : ui::MenuItem {


struct CheckVersionItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
settings.checkVersion ^= true;
}
};


struct UserFolderItem : ui::MenuItem {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
std::thread t(system::openFolder, asset::user(""));
t.detach();
}
@@ -607,7 +607,7 @@ struct UserFolderItem : ui::MenuItem {


struct HelpButton : MenuButton {
void onAction(const event::Action &e) override {
void onAction(const widget::ActionEvent &e) override {
ui::Menu *menu = createMenu();
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
menu->box.size.x = box.size.x;


+ 0
- 267
src/event.cpp View File

@@ -1,267 +0,0 @@
#include "event.hpp"
#include "widget/Widget.hpp"


namespace rack {
namespace event {


void State::setHovered(widget::Widget *w) {
if (w == hoveredWidget)
return;

if (hoveredWidget) {
// event::Leave
event::Leave eLeave;
hoveredWidget->onLeave(eLeave);
hoveredWidget = NULL;
}

if (w) {
// event::Enter
event::Context eEnterContext;
event::Enter eEnter;
eEnter.context = &eEnterContext;
w->onEnter(eEnter);
hoveredWidget = eEnterContext.consumed;
}
}

void State::setDragged(widget::Widget *w) {
if (w == draggedWidget)
return;

if (draggedWidget) {
// event::DragEnd
event::DragEnd eDragEnd;
draggedWidget->onDragEnd(eDragEnd);
draggedWidget = NULL;
}

if (w) {
// event::DragStart
event::Context eDragStartContext;
event::DragStart eDragStart;
eDragStart.context = &eDragStartContext;
w->onDragStart(eDragStart);
draggedWidget = eDragStartContext.consumed;
}
}

void State::setDragHovered(widget::Widget *w) {
if (w == dragHoveredWidget)
return;

if (dragHoveredWidget) {
// event::DragLeave
event::DragLeave eDragLeave;
eDragLeave.origin = draggedWidget;
dragHoveredWidget->onDragLeave(eDragLeave);
dragHoveredWidget = NULL;
}

if (w) {
// event::DragEnter
event::Context eDragEnterContext;
event::DragEnter eDragEnter;
eDragEnter.context = &eDragEnterContext;
eDragEnter.origin = draggedWidget;
w->onDragEnter(eDragEnter);
dragHoveredWidget = eDragEnterContext.consumed;
}
}

void State::setSelected(widget::Widget *w) {
if (w == selectedWidget)
return;

if (selectedWidget) {
// event::Deselect
event::Deselect eDeselect;
selectedWidget->onDeselect(eDeselect);
selectedWidget = NULL;
}

if (w) {
// event::Select
event::Context eSelectContext;
event::Select eSelect;
eSelect.context = &eSelectContext;
w->onSelect(eSelect);
selectedWidget = eSelectContext.consumed;
}
}

void State::finalizeWidget(widget::Widget *w) {
if (hoveredWidget == w) setHovered(NULL);
if (draggedWidget == w) setDragged(NULL);
if (dragHoveredWidget == w) setDragHovered(NULL);
if (selectedWidget == w) setSelected(NULL);
if (lastClickedWidget == w) lastClickedWidget = NULL;
}

void State::handleButton(math::Vec pos, int button, int action, int mods) {
// event::Button
event::Context eButtonContext;
event::Button eButton;
eButton.context = &eButtonContext;
eButton.pos = pos;
eButton.button = button;
eButton.action = action;
eButton.mods = mods;
rootWidget->onButton(eButton);
widget::Widget *clickedWidget = eButtonContext.consumed;

if (button == GLFW_MOUSE_BUTTON_LEFT) {
if (action == GLFW_PRESS) {
setDragged(clickedWidget);
}

if (action == GLFW_RELEASE) {
setDragHovered(NULL);

if (clickedWidget && draggedWidget) {
// event::DragDrop
event::DragDrop eDragDrop;
eDragDrop.origin = draggedWidget;
clickedWidget->onDragDrop(eDragDrop);
}

setDragged(NULL);
}

if (action == GLFW_PRESS) {
setSelected(clickedWidget);
}

if (action == GLFW_PRESS) {
const double doubleClickDuration = 0.5;
double clickTime = glfwGetTime();
if (clickedWidget
&& clickTime - lastClickTime <= doubleClickDuration
&& lastClickedWidget == clickedWidget) {
// event::DoubleClick
event::DoubleClick eDoubleClick;
clickedWidget->onDoubleClick(eDoubleClick);
}
lastClickTime = clickTime;
lastClickedWidget = clickedWidget;
}
}
}

void State::handleHover(math::Vec pos, math::Vec mouseDelta) {
if (draggedWidget) {
// event::DragMove
event::DragMove eDragMove;
eDragMove.mouseDelta = mouseDelta;
draggedWidget->onDragMove(eDragMove);

// event::DragHover
event::Context eDragHoverContext;
event::DragHover eDragHover;
eDragHover.context = &eDragHoverContext;
eDragHover.pos = pos;
eDragHover.mouseDelta = mouseDelta;
eDragHover.origin = draggedWidget;
rootWidget->onDragHover(eDragHover);

setDragHovered(eDragHoverContext.consumed);

return;
}

// event::Hover
event::Context eHoverContext;
event::Hover eHover;
eHover.context = &eHoverContext;
eHover.pos = pos;
eHover.mouseDelta = mouseDelta;
rootWidget->onHover(eHover);

setHovered(eHoverContext.consumed);
}

void State::handleLeave() {
setDragHovered(NULL);
setHovered(NULL);
}

void State::handleScroll(math::Vec pos, math::Vec scrollDelta) {
// event::HoverScroll
event::Context eHoverScrollContext;
event::HoverScroll eHoverScroll;
eHoverScroll.context = &eHoverScrollContext;
eHoverScroll.pos = pos;
eHoverScroll.scrollDelta = scrollDelta;
rootWidget->onHoverScroll(eHoverScroll);
}

void State::handleDrop(math::Vec pos, const std::vector<std::string> &paths) {
// event::PathDrop
event::Context ePathDropContext;
event::PathDrop ePathDrop(paths);
ePathDrop.context = &ePathDropContext;
ePathDrop.pos = pos;
rootWidget->onPathDrop(ePathDrop);
}

void State::handleText(math::Vec pos, int codepoint) {
if (selectedWidget) {
// event::SelectText
event::Context eSelectTextContext;
event::SelectText eSelectText;
eSelectText.context = &eSelectTextContext;
eSelectText.codepoint = codepoint;
selectedWidget->onSelectText(eSelectText);
if (eSelectTextContext.consumed)
return;
}

// event::HoverText
event::Context eHoverTextContext;
event::HoverText eHoverText;
eHoverText.context = &eHoverTextContext;
eHoverText.pos = pos;
eHoverText.codepoint = codepoint;
rootWidget->onHoverText(eHoverText);
}

void State::handleKey(math::Vec pos, int key, int scancode, int action, int mods) {
if (selectedWidget) {
// event::SelectKey
event::Context eSelectKeyContext;
event::SelectKey eSelectKey;
eSelectKey.context = &eSelectKeyContext;
eSelectKey.key = key;
eSelectKey.scancode = scancode;
eSelectKey.action = action;
eSelectKey.mods = mods;
selectedWidget->onSelectKey(eSelectKey);
if (eSelectKeyContext.consumed)
return;
}

// event::HoverKey
event::Context eHoverKeyContext;
event::HoverKey eHoverKey;
eHoverKey.context = &eHoverKeyContext;
eHoverKey.pos = pos;
eHoverKey.key = key;
eHoverKey.scancode = scancode;
eHoverKey.action = action;
eHoverKey.mods = mods;
rootWidget->onHoverKey(eHoverKey);
}

void State::handleZoom() {
// event::Zoom
event::Context eZoomContext;
event::Zoom eZoom;
eZoom.context = &eZoomContext;
rootWidget->onZoom(eZoom);
}


} // namespace event
} // namespace rack

+ 6
- 6
src/ui/Button.cpp View File

@@ -18,31 +18,31 @@ void Button::draw(const DrawArgs &args) {
bndToolButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str());
}

void Button::onEnter(const event::Enter &e) {
void Button::onEnter(const widget::EnterEvent &e) {
state = BND_HOVER;
e.consume(this);
}

void Button::onLeave(const event::Leave &e) {
void Button::onLeave(const widget::LeaveEvent &e) {
state = BND_DEFAULT;
}

void Button::onDragStart(const event::DragStart &e) {
void Button::onDragStart(const widget::DragStartEvent &e) {
state = BND_ACTIVE;
if (quantity)
quantity->setMax();
e.consume(this);
}

void Button::onDragEnd(const event::DragEnd &e) {
void Button::onDragEnd(const widget::DragEndEvent &e) {
state = BND_HOVER;
if (quantity)
quantity->setMin();
}

void Button::onDragDrop(const event::DragDrop &e) {
void Button::onDragDrop(const widget::DragDropEvent &e) {
if (e.origin == this) {
event::Action eAction;
widget::ActionEvent eAction;
onAction(eAction);
}
}


+ 1
- 1
src/ui/Menu.cpp View File

@@ -54,7 +54,7 @@ void Menu::draw(const DrawArgs &args) {
Widget::draw(args);
}

void Menu::onHoverScroll(const event::HoverScroll &e) {
void Menu::onHoverScroll(const widget::HoverScrollEvent &e) {
if (parent && !parent->box.isContaining(box))
box.pos.y += e.scrollDelta.y;
}


+ 7
- 7
src/ui/MenuItem.cpp View File

@@ -41,7 +41,7 @@ void MenuItem::step() {
Widget::step();
}

void MenuItem::onEnter(const event::Enter &e) {
void MenuItem::onEnter(const widget::EnterEvent &e) {
e.consume(this);
Menu *parentMenu = dynamic_cast<Menu*>(parent);
if (!parentMenu)
@@ -58,11 +58,11 @@ void MenuItem::onEnter(const event::Enter &e) {
parentMenu->setChildMenu(childMenu);
}

void MenuItem::onDragStart(const event::DragStart &e) {
void MenuItem::onDragStart(const widget::DragStartEvent &e) {
e.consume(this);
}

void MenuItem::onDragDrop(const event::DragDrop &e) {
void MenuItem::onDragDrop(const widget::DragDropEvent &e) {
if (e.origin != this)
return;
doAction();
@@ -72,13 +72,13 @@ void MenuItem::doAction() {
if (disabled)
return;

event::Context eActionContext;
event::Action eAction;
eAction.context = &eActionContext;
widget::EventContext cAction;
widget::ActionEvent eAction;
eAction.context = &cAction;
// Consume event by default, but allow action to un-consume it to prevent the menu from being removed.
eAction.consume(this);
onAction(eAction);
if (!eActionContext.consumed)
if (!cAction.consumed)
return;

MenuOverlay *overlay = getAncestorOfType<MenuOverlay>();


+ 2
- 2
src/ui/MenuOverlay.cpp View File

@@ -17,7 +17,7 @@ void MenuOverlay::step() {
Widget::step();
}

void MenuOverlay::onButton(const event::Button &e) {
void MenuOverlay::onButton(const widget::ButtonEvent &e) {
widget::OpaqueWidget::onButton(e);

if (e.getConsumed() == this && e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) {
@@ -25,7 +25,7 @@ void MenuOverlay::onButton(const event::Button &e) {
}
}

void MenuOverlay::onHoverKey(const event::HoverKey &e) {
void MenuOverlay::onHoverKey(const widget::HoverKeyEvent &e) {
widget::OpaqueWidget::onHoverKey(e);

if (e.getConsumed() == this && e.action == GLFW_PRESS && e.key == GLFW_KEY_ESCAPE) {


+ 4
- 4
src/ui/RadioButton.cpp View File

@@ -21,18 +21,18 @@ void RadioButton::draw(const DrawArgs &args) {
bndRadioButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, label.c_str());
}

void RadioButton::onEnter(const event::Enter &e) {
void RadioButton::onEnter(const widget::EnterEvent &e) {
if (state != BND_ACTIVE)
state = BND_HOVER;
e.consume(this);
}

void RadioButton::onLeave(const event::Leave &e) {
void RadioButton::onLeave(const widget::LeaveEvent &e) {
if (state != BND_ACTIVE)
state = BND_DEFAULT;
}

void RadioButton::onDragDrop(const event::DragDrop &e) {
void RadioButton::onDragDrop(const widget::DragDropEvent &e) {
if (e.origin == this) {
if (state == BND_ACTIVE) {
state = BND_HOVER;
@@ -45,7 +45,7 @@ void RadioButton::onDragDrop(const event::DragDrop &e) {
quantity->setMax();
}

event::Action eAction;
widget::ActionEvent eAction;
onAction(eAction);
}
}


+ 3
- 3
src/ui/ScrollBar.cpp View File

@@ -16,13 +16,13 @@ void ScrollBar::draw(const DrawArgs &args) {
bndScrollBar(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, offset, size);
}

void ScrollBar::onDragStart(const event::DragStart &e) {
void ScrollBar::onDragStart(const widget::DragStartEvent &e) {
state = BND_ACTIVE;
APP->window->cursorLock();
e.consume(this);
}

void ScrollBar::onDragMove(const event::DragMove &e) {
void ScrollBar::onDragMove(const widget::DragMoveEvent &e) {
const float sensitivity = 1.f;

ScrollWidget *scrollWidget = dynamic_cast<ScrollWidget*>(parent);
@@ -33,7 +33,7 @@ void ScrollBar::onDragMove(const event::DragMove &e) {
scrollWidget->offset.y += sensitivity * e.mouseDelta.y;
}

void ScrollBar::onDragEnd(const event::DragEnd &e) {
void ScrollBar::onDragEnd(const widget::DragEndEvent &e) {
state = BND_DEFAULT;
APP->window->cursorUnlock();
}


+ 3
- 3
src/ui/ScrollWidget.cpp View File

@@ -1,6 +1,6 @@
#include "ui/ScrollWidget.hpp"
#include "app.hpp"
#include "event.hpp"
#include "widget/event.hpp"


namespace rack {
@@ -69,11 +69,11 @@ void ScrollWidget::step() {
verticalScrollBar->box.size.y = horizontalScrollBar->visible ? inner.y : box.size.y;
}

void ScrollWidget::onHover(const event::Hover &e) {
void ScrollWidget::onHover(const widget::HoverEvent &e) {
widget::Widget::onHover(e);
}

void ScrollWidget::onHoverScroll(const event::HoverScroll &e) {
void ScrollWidget::onHoverScroll(const widget::HoverScrollEvent &e) {
widget::Widget::onHoverScroll(e);
if (e.getConsumed())
return;


+ 4
- 4
src/ui/Slider.cpp View File

@@ -23,24 +23,24 @@ void Slider::draw(const DrawArgs &args) {
bndSlider(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, text.c_str(), NULL);
}

void Slider::onDragStart(const event::DragStart &e) {
void Slider::onDragStart(const widget::DragStartEvent &e) {
state = BND_ACTIVE;
APP->window->cursorLock();
e.consume(this);
}

void Slider::onDragMove(const event::DragMove &e) {
void Slider::onDragMove(const widget::DragMoveEvent &e) {
if (quantity) {
quantity->moveScaledValue(SENSITIVITY * e.mouseDelta.x);
}
}

void Slider::onDragEnd(const event::DragEnd &e) {
void Slider::onDragEnd(const widget::DragEndEvent &e) {
state = BND_DEFAULT;
APP->window->cursorUnlock();
}

void Slider::onDoubleClick(const event::DoubleClick &e) {
void Slider::onDoubleClick(const widget::DoubleClickEvent &e) {
if (quantity)
quantity->reset();
}


+ 14
- 14
src/ui/TextField.cpp View File

@@ -30,14 +30,14 @@ void TextField::draw(const DrawArgs &args) {
nvgResetScissor(args.vg);
}

void TextField::onButton(const event::Button &e) {
void TextField::onButton(const widget::ButtonEvent &e) {
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) {
cursor = selection = getTextPosition(e.pos);
}
widget::OpaqueWidget::onButton(e);
}

void TextField::onHover(const event::Hover &e) {
void TextField::onHover(const widget::HoverEvent &e) {
if (this == APP->event->draggedWidget) {
int pos = getTextPosition(e.pos);
if (pos != selection) {
@@ -47,15 +47,15 @@ void TextField::onHover(const event::Hover &e) {
widget::OpaqueWidget::onHover(e);
}

void TextField::onEnter(const event::Enter &e) {
void TextField::onEnter(const widget::EnterEvent &e) {
e.consume(this);
}

void TextField::onSelect(const event::Select &e) {
void TextField::onSelect(const widget::SelectEvent &e) {
e.consume(this);
}

void TextField::onSelectText(const event::SelectText &e) {
void TextField::onSelectText(const widget::SelectTextEvent &e) {
if (e.codepoint < 128) {
std::string newText(1, (char) e.codepoint);
insertText(newText);
@@ -63,7 +63,7 @@ void TextField::onSelectText(const event::SelectText &e) {
e.consume(this);
}

void TextField::onSelectKey(const event::SelectKey &e) {
void TextField::onSelectKey(const widget::SelectKeyEvent &e) {
if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) {
switch (e.key) {
case GLFW_KEY_BACKSPACE: {
@@ -71,7 +71,7 @@ void TextField::onSelectKey(const event::SelectKey &e) {
cursor--;
if (cursor >= 0) {
text.erase(cursor, 1);
event::Change eChange;
widget::ChangeEvent eChange;
onChange(eChange);
}
selection = cursor;
@@ -79,7 +79,7 @@ void TextField::onSelectKey(const event::SelectKey &e) {
else {
int begin = std::min(cursor, selection);
text.erase(begin, std::abs(selection - cursor));
event::Change eChange;
widget::ChangeEvent eChange;
onChange(eChange);
cursor = selection = begin;
}
@@ -87,13 +87,13 @@ void TextField::onSelectKey(const event::SelectKey &e) {
case GLFW_KEY_DELETE: {
if (cursor == selection) {
text.erase(cursor, 1);
event::Change eChange;
widget::ChangeEvent eChange;
onChange(eChange);
}
else {
int begin = std::min(cursor, selection);
text.erase(begin, std::abs(selection - cursor));
event::Change eChange;
widget::ChangeEvent eChange;
onChange(eChange);
cursor = selection = begin;
}
@@ -168,7 +168,7 @@ void TextField::onSelectKey(const event::SelectKey &e) {
insertText("\n");
}
else {
event::Action eAction;
widget::ActionEvent eAction;
onAction(eAction);
}
} break;
@@ -189,7 +189,7 @@ void TextField::insertText(std::string text) {
this->text.insert(cursor, text);
cursor += text.size();
selection = cursor;
event::Change eChange;
widget::ChangeEvent eChange;
onChange(eChange);
}

@@ -198,8 +198,8 @@ void TextField::setText(std::string text) {
this->text = text;
selection = cursor = text.size();
if (changed) {
// event::Change
event::Change eChange;
// widget::ChangeEvent
widget::ChangeEvent eChange;
onChange(eChange);
}
}


+ 17
- 17
src/widget/Widget.cpp View File

@@ -1,5 +1,5 @@
#include "widget/Widget.hpp"
#include "event.hpp"
#include "widget/event.hpp"
#include "app.hpp"
#include <algorithm>

@@ -16,15 +16,15 @@ Widget::~Widget() {

void Widget::setPos(math::Vec pos) {
box.pos = pos;
// event::Reposition
event::Reposition eReposition;
// RepositionEvent
RepositionEvent eReposition;
onReposition(eReposition);
}

void Widget::setSize(math::Vec size) {
box.size = size;
// event::Resize
event::Resize eResize;
// ResizeEvent
ResizeEvent eResize;
onResize(eResize);
}

@@ -32,8 +32,8 @@ void Widget::show() {
if (visible)
return;
visible = true;
// event::Show
event::Show eShow;
// ShowEvent
ShowEvent eShow;
onShow(eShow);
}

@@ -41,8 +41,8 @@ void Widget::hide() {
if (!visible)
return;
visible = false;
// event::Hide
event::Hide eHide;
// HideEvent
HideEvent eHide;
onHide(eHide);
}

@@ -90,8 +90,8 @@ void Widget::addChild(Widget *child) {
assert(!child->parent);
child->parent = this;
children.push_back(child);
// event::Add
event::Add eAdd;
// AddEvent
AddEvent eAdd;
child->onAdd(eAdd);
}

@@ -99,8 +99,8 @@ void Widget::removeChild(Widget *child) {
assert(child);
// Make sure `this` is the child's parent
assert(child->parent == this);
// event::Remove
event::Remove eRemove;
// RemoveEvent
RemoveEvent eRemove;
child->onRemove(eRemove);
// Prepare to remove widget from the event state
APP->event->finalizeWidget(child);
@@ -114,8 +114,8 @@ void Widget::removeChild(Widget *child) {

void Widget::clearChildren() {
for (Widget *child : children) {
// event::Remove
event::Remove eRemove;
// RemoveEvent
RemoveEvent eRemove;
child->onRemove(eRemove);
APP->event->finalizeWidget(child);
child->parent = NULL;
@@ -129,8 +129,8 @@ void Widget::step() {
Widget *child = *it;
// Delete children if a delete is requested
if (child->requestedDelete) {
// event::Remove
event::Remove eRemove;
// RemoveEvent
RemoveEvent eRemove;
child->onRemove(eRemove);
APP->event->finalizeWidget(child);
it = children.erase(it);


+ 3
- 3
src/widget/ZoomWidget.cpp View File

@@ -23,9 +23,9 @@ void ZoomWidget::setZoom(float zoom) {
return;
this->zoom = zoom;

event::Context eZoomContext;
event::Zoom eZoom;
eZoom.context = &eZoomContext;
EventContext cZoom;
ZoomEvent eZoom;
eZoom.context = &cZoom;
Widget::onZoom(eZoom);
}



+ 267
- 0
src/widget/event.cpp View File

@@ -0,0 +1,267 @@
#include "widget/event.hpp"
#include "widget/Widget.hpp"


namespace rack {
namespace widget {


void EventState::setHovered(Widget *w) {
if (w == hoveredWidget)
return;

if (hoveredWidget) {
// LeaveEvent
LeaveEvent eLeave;
hoveredWidget->onLeave(eLeave);
hoveredWidget = NULL;
}

if (w) {
// EnterEvent
EventContext cEnter;
EnterEvent eEnter;
eEnter.context = &cEnter;
w->onEnter(eEnter);
hoveredWidget = cEnter.consumed;
}
}

void EventState::setDragged(Widget *w) {
if (w == draggedWidget)
return;

if (draggedWidget) {
// DragEndEvent
DragEndEvent eDragEnd;
draggedWidget->onDragEnd(eDragEnd);
draggedWidget = NULL;
}

if (w) {
// DragStartEvent
EventContext cDragStart;
DragStartEvent eDragStart;
eDragStart.context = &cDragStart;
w->onDragStart(eDragStart);
draggedWidget = cDragStart.consumed;
}
}

void EventState::setDragHovered(Widget *w) {
if (w == dragHoveredWidget)
return;

if (dragHoveredWidget) {
// DragLeaveEvent
DragLeaveEvent eDragLeave;
eDragLeave.origin = draggedWidget;
dragHoveredWidget->onDragLeave(eDragLeave);
dragHoveredWidget = NULL;
}

if (w) {
// DragEnterEvent
EventContext cDragEnter;
DragEnterEvent eDragEnter;
eDragEnter.context = &cDragEnter;
eDragEnter.origin = draggedWidget;
w->onDragEnter(eDragEnter);
dragHoveredWidget = cDragEnter.consumed;
}
}

void EventState::setSelected(Widget *w) {
if (w == selectedWidget)
return;

if (selectedWidget) {
// DeselectEvent
DeselectEvent eDeselect;
selectedWidget->onDeselect(eDeselect);
selectedWidget = NULL;
}

if (w) {
// SelectEvent
EventContext cSelect;
SelectEvent eSelect;
eSelect.context = &cSelect;
w->onSelect(eSelect);
selectedWidget = cSelect.consumed;
}
}

void EventState::finalizeWidget(Widget *w) {
if (hoveredWidget == w) setHovered(NULL);
if (draggedWidget == w) setDragged(NULL);
if (dragHoveredWidget == w) setDragHovered(NULL);
if (selectedWidget == w) setSelected(NULL);
if (lastClickedWidget == w) lastClickedWidget = NULL;
}

void EventState::handleButton(math::Vec pos, int button, int action, int mods) {
// ButtonEvent
EventContext cButton;
ButtonEvent eButton;
eButton.context = &cButton;
eButton.pos = pos;
eButton.button = button;
eButton.action = action;
eButton.mods = mods;
rootWidget->onButton(eButton);
Widget *clickedWidget = cButton.consumed;

if (button == GLFW_MOUSE_BUTTON_LEFT) {
if (action == GLFW_PRESS) {
setDragged(clickedWidget);
}

if (action == GLFW_RELEASE) {
setDragHovered(NULL);

if (clickedWidget && draggedWidget) {
// DragDropEvent
DragDropEvent eDragDrop;
eDragDrop.origin = draggedWidget;
clickedWidget->onDragDrop(eDragDrop);
}

setDragged(NULL);
}

if (action == GLFW_PRESS) {
setSelected(clickedWidget);
}

if (action == GLFW_PRESS) {
const double doubleClickDuration = 0.5;
double clickTime = glfwGetTime();
if (clickedWidget
&& clickTime - lastClickTime <= doubleClickDuration
&& lastClickedWidget == clickedWidget) {
// DoubleClickEvent
DoubleClickEvent eDoubleClick;
clickedWidget->onDoubleClick(eDoubleClick);
}
lastClickTime = clickTime;
lastClickedWidget = clickedWidget;
}
}
}

void EventState::handleHover(math::Vec pos, math::Vec mouseDelta) {
if (draggedWidget) {
// DragMoveEvent
DragMoveEvent eDragMove;
eDragMove.mouseDelta = mouseDelta;
draggedWidget->onDragMove(eDragMove);

// DragHoverEvent
EventContext cDragHover;
DragHoverEvent eDragHover;
eDragHover.context = &cDragHover;
eDragHover.pos = pos;
eDragHover.mouseDelta = mouseDelta;
eDragHover.origin = draggedWidget;
rootWidget->onDragHover(eDragHover);

setDragHovered(cDragHover.consumed);

return;
}

// HoverEvent
EventContext cHover;
HoverEvent eHover;
eHover.context = &cHover;
eHover.pos = pos;
eHover.mouseDelta = mouseDelta;
rootWidget->onHover(eHover);

setHovered(cHover.consumed);
}

void EventState::handleLeave() {
setDragHovered(NULL);
setHovered(NULL);
}

void EventState::handleScroll(math::Vec pos, math::Vec scrollDelta) {
// HoverScrollEvent
EventContext cHoverScroll;
HoverScrollEvent eHoverScroll;
eHoverScroll.context = &cHoverScroll;
eHoverScroll.pos = pos;
eHoverScroll.scrollDelta = scrollDelta;
rootWidget->onHoverScroll(eHoverScroll);
}

void EventState::handleDrop(math::Vec pos, const std::vector<std::string> &paths) {
// PathDropEvent
EventContext cPathDrop;
PathDropEvent ePathDrop(paths);
ePathDrop.context = &cPathDrop;
ePathDrop.pos = pos;
rootWidget->onPathDrop(ePathDrop);
}

void EventState::handleText(math::Vec pos, int codepoint) {
if (selectedWidget) {
// SelectTextEvent
EventContext cSelectText;
SelectTextEvent eSelectText;
eSelectText.context = &cSelectText;
eSelectText.codepoint = codepoint;
selectedWidget->onSelectText(eSelectText);
if (cSelectText.consumed)
return;
}

// HoverTextEvent
EventContext cHoverText;
HoverTextEvent eHoverText;
eHoverText.context = &cHoverText;
eHoverText.pos = pos;
eHoverText.codepoint = codepoint;
rootWidget->onHoverText(eHoverText);
}

void EventState::handleKey(math::Vec pos, int key, int scancode, int action, int mods) {
if (selectedWidget) {
// SelectKeyEvent
EventContext cSelectKey;
SelectKeyEvent eSelectKey;
eSelectKey.context = &cSelectKey;
eSelectKey.key = key;
eSelectKey.scancode = scancode;
eSelectKey.action = action;
eSelectKey.mods = mods;
selectedWidget->onSelectKey(eSelectKey);
if (cSelectKey.consumed)
return;
}

// HoverKeyEvent
EventContext cHoverKey;
HoverKeyEvent eHoverKey;
eHoverKey.context = &cHoverKey;
eHoverKey.pos = pos;
eHoverKey.key = key;
eHoverKey.scancode = scancode;
eHoverKey.action = action;
eHoverKey.mods = mods;
rootWidget->onHoverKey(eHoverKey);
}

void EventState::handleZoom() {
// ZoomEvent
EventContext cZoom;
ZoomEvent eZoom;
eZoom.context = &cZoom;
rootWidget->onZoom(eZoom);
}


} // namespace widget
} // namespace rack

+ 1
- 1
src/window.cpp View File

@@ -3,7 +3,7 @@
#include "app/Scene.hpp"
#include "keyboard.hpp"
#include "gamepad.hpp"
#include "event.hpp"
#include "widget/event.hpp"
#include "app.hpp"
#include "patch.hpp"
#include "settings.hpp"


Loading…
Cancel
Save