|
|
@@ -5,6 +5,7 @@ |
|
|
|
#include <history.hpp> |
|
|
|
#include <engine/Engine.hpp> |
|
|
|
#include <settings.hpp> |
|
|
|
#include <helpers.hpp> |
|
|
|
|
|
|
|
|
|
|
|
namespace rack { |
|
|
@@ -71,6 +72,7 @@ PortWidget::PortWidget() { |
|
|
|
internal = new Internal; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PortWidget::~PortWidget() { |
|
|
|
// The port shouldn't have any cables when destroyed, but just to make sure. |
|
|
|
if (module) |
|
|
@@ -80,6 +82,7 @@ PortWidget::~PortWidget() { |
|
|
|
delete internal; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
engine::Port* PortWidget::getPort() { |
|
|
|
if (!module) |
|
|
|
return NULL; |
|
|
@@ -89,6 +92,7 @@ engine::Port* PortWidget::getPort() { |
|
|
|
return &module->outputs[portId]; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
engine::PortInfo* PortWidget::getPortInfo() { |
|
|
|
if (!module) |
|
|
|
return NULL; |
|
|
@@ -98,6 +102,7 @@ engine::PortInfo* PortWidget::getPortInfo() { |
|
|
|
return module->outputInfos[portId]; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PortWidget::createTooltip() { |
|
|
|
if (!settings::tooltips) |
|
|
|
return; |
|
|
@@ -111,6 +116,7 @@ void PortWidget::createTooltip() { |
|
|
|
internal->tooltip = tooltip; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PortWidget::destroyTooltip() { |
|
|
|
if (!internal->tooltip) |
|
|
|
return; |
|
|
@@ -119,10 +125,43 @@ void PortWidget::destroyTooltip() { |
|
|
|
internal->tooltip = NULL; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PortWidget::createContextMenu() { |
|
|
|
ui::Menu* menu = createMenu(); |
|
|
|
WeakPtr<PortWidget> weakThis = this; |
|
|
|
|
|
|
|
menu->addChild(createMenuItem("Delete top cable", "", |
|
|
|
[=]() { |
|
|
|
if (!weakThis) |
|
|
|
return; |
|
|
|
weakThis->deleteTopCableAction(); |
|
|
|
} |
|
|
|
)); |
|
|
|
|
|
|
|
// TODO |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PortWidget::deleteTopCableAction() { |
|
|
|
CableWidget* cw = APP->scene->rack->getTopCable(this); |
|
|
|
if (!cw) |
|
|
|
return; |
|
|
|
|
|
|
|
// history::CableRemove |
|
|
|
history::CableRemove* h = new history::CableRemove; |
|
|
|
h->setCable(cw); |
|
|
|
APP->history->push(h); |
|
|
|
|
|
|
|
APP->scene->rack->removeCable(cw); |
|
|
|
delete cw; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PortWidget::step() { |
|
|
|
Widget::step(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PortWidget::draw(const DrawArgs& args) { |
|
|
|
CableWidget* cw = APP->scene->rack->incompleteCable; |
|
|
|
if (cw) { |
|
|
@@ -134,33 +173,27 @@ void PortWidget::draw(const DrawArgs& args) { |
|
|
|
Widget::draw(args); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PortWidget::onButton(const ButtonEvent& e) { |
|
|
|
OpaqueWidget::onButton(e); |
|
|
|
|
|
|
|
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) { |
|
|
|
CableWidget* cw = APP->scene->rack->getTopCable(this); |
|
|
|
if (cw) { |
|
|
|
// history::CableRemove |
|
|
|
history::CableRemove* h = new history::CableRemove; |
|
|
|
h->setCable(cw); |
|
|
|
APP->history->push(h); |
|
|
|
|
|
|
|
APP->scene->rack->removeCable(cw); |
|
|
|
delete cw; |
|
|
|
} |
|
|
|
|
|
|
|
createContextMenu(); |
|
|
|
e.consume(this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PortWidget::onEnter(const EnterEvent& e) { |
|
|
|
createTooltip(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PortWidget::onLeave(const LeaveEvent& e) { |
|
|
|
destroyTooltip(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PortWidget::onDragStart(const DragStartEvent& e) { |
|
|
|
if (e.button != GLFW_MOUSE_BUTTON_LEFT) |
|
|
|
return; |
|
|
@@ -216,6 +249,7 @@ void PortWidget::onDragStart(const DragStartEvent& e) { |
|
|
|
APP->scene->rack->setIncompleteCable(cw); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PortWidget::onDragEnd(const DragEndEvent& e) { |
|
|
|
if (e.button != GLFW_MOUSE_BUTTON_LEFT) |
|
|
|
return; |
|
|
@@ -237,6 +271,7 @@ void PortWidget::onDragEnd(const DragEndEvent& e) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PortWidget::onDragDrop(const DragDropEvent& e) { |
|
|
|
// HACK: Only delete tooltip if we're not (normal) dragging it. |
|
|
|
if (e.origin == this) |
|
|
@@ -262,6 +297,7 @@ void PortWidget::onDragDrop(const DragDropEvent& e) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PortWidget::onDragEnter(const DragEnterEvent& e) { |
|
|
|
PortWidget* pw = dynamic_cast<PortWidget*>(e.origin); |
|
|
|
if (pw) { |
|
|
@@ -286,6 +322,7 @@ void PortWidget::onDragEnter(const DragEnterEvent& e) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PortWidget::onDragLeave(const DragLeaveEvent& e) { |
|
|
|
destroyTooltip(); |
|
|
|
|
|
|
|