and knobstags/v0.3.2
| @@ -76,6 +76,8 @@ struct Widget { | |||||
| */ | */ | ||||
| void removeChild(Widget *widget); | void removeChild(Widget *widget); | ||||
| void clearChildren(); | void clearChildren(); | ||||
| /** Recursively finalizes event start/end pairs as needed */ | |||||
| void finalizeEvents(); | |||||
| /** Advances the module by one frame */ | /** Advances the module by one frame */ | ||||
| virtual void step(); | virtual void step(); | ||||
| @@ -155,6 +155,7 @@ Widget *ModuleWidget::onHoverKey(Vec pos, int key) { | |||||
| case GLFW_KEY_DELETE: | case GLFW_KEY_DELETE: | ||||
| case GLFW_KEY_BACKSPACE: | case GLFW_KEY_BACKSPACE: | ||||
| gRackWidget->deleteModule(this); | gRackWidget->deleteModule(this); | ||||
| this->finalizeEvents(); | |||||
| delete this; | delete this; | ||||
| break; | break; | ||||
| case GLFW_KEY_I: | case GLFW_KEY_I: | ||||
| @@ -217,6 +218,7 @@ struct DeleteMenuItem : MenuItem { | |||||
| ModuleWidget *moduleWidget; | ModuleWidget *moduleWidget; | ||||
| void onAction() { | void onAction() { | ||||
| gRackWidget->deleteModule(moduleWidget); | gRackWidget->deleteModule(moduleWidget); | ||||
| moduleWidget->finalizeEvents(); | |||||
| delete moduleWidget; | delete moduleWidget; | ||||
| } | } | ||||
| }; | }; | ||||
| @@ -9,6 +9,13 @@ Port::Port() { | |||||
| Port::~Port() { | Port::~Port() { | ||||
| disconnect(); | disconnect(); | ||||
| if (gRackWidget->activeWire) { | |||||
| if (gRackWidget->activeWire->hoveredInputPort == this) | |||||
| gRackWidget->activeWire->hoveredInputPort = NULL; | |||||
| if (gRackWidget->activeWire->hoveredOutputPort == this) | |||||
| gRackWidget->activeWire->hoveredOutputPort = NULL; | |||||
| } | |||||
| } | } | ||||
| void Port::disconnect() { | void Port::disconnect() { | ||||
| @@ -1,4 +1,5 @@ | |||||
| #include "widgets.hpp" | #include "widgets.hpp" | ||||
| #include "app.hpp" | |||||
| #include <algorithm> | #include <algorithm> | ||||
| @@ -62,6 +63,28 @@ void Widget::clearChildren() { | |||||
| children.clear(); | children.clear(); | ||||
| } | } | ||||
| void Widget::finalizeEvents() { | |||||
| // Stop dragging and hovering this widget | |||||
| if (gHoveredWidget == this) { | |||||
| gHoveredWidget->onMouseLeave(); | |||||
| gHoveredWidget = NULL; | |||||
| } | |||||
| if (gDraggedWidget == this) { | |||||
| gDraggedWidget->onDragEnd(); | |||||
| gDraggedWidget = NULL; | |||||
| } | |||||
| if (gDragHoveredWidget == this) { | |||||
| gDragHoveredWidget = NULL; | |||||
| } | |||||
| if (gSelectedWidget == this) { | |||||
| gSelectedWidget->onDeselect(); | |||||
| gSelectedWidget = NULL; | |||||
| } | |||||
| for (Widget *child : children) { | |||||
| child->finalizeEvents(); | |||||
| } | |||||
| } | |||||
| void Widget::step() { | void Widget::step() { | ||||
| for (Widget *child : children) { | for (Widget *child : children) { | ||||
| child->step(); | child->step(); | ||||