Browse Source

Clean up event documentation, change event::PathDrop::path type to const reference, make event::Zoom recurse regardless of being consumed

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
de2b5a92af
5 changed files with 23 additions and 17 deletions
  1. +2
    -1
      include/app/ModuleWidget.hpp
  2. +16
    -9
      include/event.hpp
  3. +2
    -3
      include/widgets/Widget.hpp
  4. +1
    -1
      src/app/ModuleBrowser.cpp
  5. +2
    -3
      src/event.cpp

+ 2
- 1
include/app/ModuleWidget.hpp View File

@@ -20,6 +20,8 @@ struct ModuleWidget : OpaqueWidget {
std::vector<ParamWidget*> params;
std::vector<PortWidget*> inputs;
std::vector<PortWidget*> outputs;
/** For RackWidget dragging */
math::Vec dragPos;

ModuleWidget(Module *module);
~ModuleWidget();
@@ -64,7 +66,6 @@ struct ModuleWidget : OpaqueWidget {
void draw(NVGcontext *vg) override;
void drawShadow(NVGcontext *vg);

math::Vec dragPos;
void onHover(const event::Hover &e) override;
void onButton(const event::Button &e) override;
void onHoverKey(const event::HoverKey &e) override;


+ 16
- 9
include/event.hpp View File

@@ -83,7 +83,7 @@ struct Button : Event, Position {
};


/** Occurs when a key is pressed while the mouse is hovering a Widget.
/** Occurs when a key is pressed, released, or repeated while the mouse is hovering a Widget.
Recurses until consumed.
*/
struct HoverKey : Event, Position, Key {
@@ -130,7 +130,7 @@ struct Deselect : Event {
};


/** Occurs when a key is pressed while a Widget is selected.
/** 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 {
@@ -144,7 +144,6 @@ struct SelectText : Event, Text {


/** Occurs when a Widget begins being dragged.
Must consume to allow the drag to occur.
*/
struct DragStart : Event {
};
@@ -157,16 +156,18 @@ struct DragEnd : Event {


/** Occurs every frame on the dragged Widget.
`mouseDelta` may be zero.
*/
struct DragMove : Event {
/** Change in mouse position since the last frame. Can be zero. */
math::Vec mouseDelta;
};


/** Occurs every frame when the mouse is hovering over a Widget while dragging.
/** 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 {
/** The dragged widget */
Widget *origin = NULL;
/** Change in mouse position since the last frame. Can be zero. */
math::Vec mouseDelta;
@@ -175,6 +176,7 @@ struct DragHover : Event, Position {
/** Occurs when the mouse enters a Widget while dragging.
*/
struct DragEnter : Event {
/** The dragged widget */
Widget *origin = NULL;
};

@@ -182,6 +184,7 @@ struct DragEnter : Event {
/** Occurs when the mouse leaves a Widget while dragging.
*/
struct DragLeave : Event {
/** The dragged widget */
Widget *origin = NULL;
};

@@ -189,15 +192,19 @@ struct DragLeave : Event {
/** Occurs when the mouse button is released over a Widget while dragging.
*/
struct DragDrop : Event {
/** The dragged widget */
Widget *origin = NULL;
};


/** Occurs when a selection of files from the operating system are dropped onto a Widget.
/** 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) {}

/** List of file paths in the dropped selection */
std::vector<std::string> paths;
const std::vector<std::string> &paths;
};


@@ -214,7 +221,7 @@ struct Change : Event {


/** Occurs when the zoom level of a Widget is changed.
Recurses.
Recurses until consumed.
*/
struct Zoom : Event {
};
@@ -245,7 +252,7 @@ struct State {
void handleScroll(math::Vec pos, math::Vec scrollDelta);
void handleText(math::Vec pos, int codepoint);
void handleKey(math::Vec pos, int key, int scancode, int action, int mods);
void handleDrop(math::Vec pos, std::vector<std::string> paths);
void handleDrop(math::Vec pos, const std::vector<std::string> &paths);
void handleZoom();
};



+ 2
- 3
include/widgets/Widget.hpp View File

@@ -74,6 +74,7 @@ struct Widget {

// Events

/** Recurses an event to all visible Widgets */
template <typename TMethod, class TEvent>
void recurseEvent(TMethod f, const TEvent &e) {
for (auto it = children.rbegin(); it != children.rend(); it++) {
@@ -84,12 +85,10 @@ struct Widget {

// Call child event handler
(child->*f)(e);
// Stop iterating if consumed
if (e.getConsumed())
break;
}
}

/** Recurses an event to all visible Widgets until it is consumed. */
template <typename TMethod, class TEvent>
void recursePositionEvent(TMethod f, const TEvent &e) {
for (auto it = children.rbegin(); it != children.rend(); it++) {


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

@@ -72,7 +72,7 @@ struct ModuleBox : OpaqueWidget {
// Create module
ModuleWidget *moduleWidget = model->createModuleWidget();
assert(moduleWidget);
context()->scene->rackWidget->addModuleAtMouse(moduleWidget);
context()->scene->rackWidget->addModule(moduleWidget);
// This is a bit nonstandard/unsupported usage, but pretend the moduleWidget was clicked so it can be dragged in the RackWidget
e.consume(moduleWidget);
// Close Module Browser


+ 2
- 3
src/event.cpp View File

@@ -192,13 +192,12 @@ void State::handleScroll(math::Vec pos, math::Vec scrollDelta) {
rootWidget->onHoverScroll(eHoverScroll);
}

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



Loading…
Cancel
Save