diff --git a/include/app/PortWidget.hpp b/include/app/PortWidget.hpp index 685f2ba0..e05a5014 100644 --- a/include/app/PortWidget.hpp +++ b/include/app/PortWidget.hpp @@ -20,12 +20,11 @@ struct PortWidget : widget::OpaqueWidget { engine::Port::Type type = engine::Port::INPUT; int portId = -1; - MultiLightWidget* plugLight; - PortWidget(); ~PortWidget(); engine::Port* getPort(); engine::PortInfo* getPortInfo(); + LightWidget* getPlugLight(); void createTooltip(); void destroyTooltip(); diff --git a/src/app/CableWidget.cpp b/src/app/CableWidget.cpp index af6ba3f4..da18986d 100644 --- a/src/app/CableWidget.cpp +++ b/src/app/CableWidget.cpp @@ -226,7 +226,7 @@ void CableWidget::drawPlugs(const DrawArgs& args) { // Draw plug light nvgSave(args.vg); nvgTranslate(args.vg, outputPos.x - 4, outputPos.y - 4); - outputPort->plugLight->draw(args); + outputPort->getPlugLight()->draw(args); nvgRestore(args.vg); } } @@ -236,7 +236,7 @@ void CableWidget::drawPlugs(const DrawArgs& args) { if (isComplete()) { nvgSave(args.vg); nvgTranslate(args.vg, inputPos.x - 4, inputPos.y - 4); - inputPort->plugLight->draw(args); + inputPort->getPlugLight()->draw(args); nvgRestore(args.vg); } } diff --git a/src/app/PortWidget.cpp b/src/app/PortWidget.cpp index edc3bbbe..b86e8dd9 100644 --- a/src/app/PortWidget.cpp +++ b/src/app/PortWidget.cpp @@ -76,20 +76,21 @@ struct PlugLight : MultiLightWidget { struct PortWidget::Internal { ui::Tooltip* tooltip = NULL; + PlugLight* plugLight; }; PortWidget::PortWidget() { internal = new Internal; - plugLight = new PlugLight; + internal->plugLight = new PlugLight; } PortWidget::~PortWidget() { // HACK: In case onDragDrop() is called but not onLeave() afterwards... destroyTooltip(); - // plugLight is not a child and is thus owned by the PortWidget, so we need to delete it here - delete plugLight; - // HACK + // plugLight is not a child but owned by the PortWidget, so we need to delete it here + delete internal->plugLight; + // The port shouldn't have any cables when destroyed, but just to make sure. if (module) APP->scene->rack->clearCablesOnPort(this); delete internal; @@ -113,6 +114,10 @@ engine::PortInfo* PortWidget::getPortInfo() { return module->outputInfos[portId]; } +LightWidget* PortWidget::getPlugLight() { + return internal->plugLight; +} + void PortWidget::createTooltip() { if (!settings::tooltips) return; @@ -145,7 +150,7 @@ void PortWidget::step() { else values[i] = module->inputs[portId].plugLights[i].getBrightness(); } - plugLight->setBrightnesses(values); + internal->plugLight->setBrightnesses(values); Widget::step(); }