Browse Source

Make RackWidget::incompleteCable internal with getter.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
3ec47bf575
3 changed files with 37 additions and 33 deletions
  1. +1
    -1
      include/app/RackWidget.hpp
  2. +4
    -4
      src/app/PortWidget.cpp
  3. +32
    -28
      src/app/RackWidget.cpp

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

@@ -22,7 +22,6 @@ struct RackWidget : widget::OpaqueWidget {
struct Internal;
Internal* internal;

CableWidget* incompleteCable = NULL;
ParamWidget* touchedParam = NULL;

PRIVATE RackWidget();
@@ -110,6 +109,7 @@ struct RackWidget : widget::OpaqueWidget {
/** Removes cable and releases ownership to caller.
*/
void removeCable(CableWidget* cw);
CableWidget* getIncompleteCable();
/** Takes ownership of `cw` and adds it as a child if it isn't already. */
void setIncompleteCable(CableWidget* cw);
CableWidget* releaseIncompleteCable();


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

@@ -297,7 +297,7 @@ void PortWidget::step() {


void PortWidget::draw(const DrawArgs& args) {
CableWidget* cw = APP->scene->rack->incompleteCable;
CableWidget* cw = APP->scene->rack->getIncompleteCable();
if (cw) {
// Dim the PortWidget if the active cable cannot plug into this PortWidget
if (type == engine::Port::OUTPUT ? cw->outputPort : cw->inputPort) {
@@ -461,7 +461,7 @@ void PortWidget::onDragDrop(const DragDropEvent& e) {
return;
}

CableWidget* cw = APP->scene->rack->incompleteCable;
CableWidget* cw = APP->scene->rack->getIncompleteCable();
if (cw) {
cw->hoveredOutputPort = cw->hoveredInputPort = NULL;
if (type == engine::Port::OUTPUT)
@@ -488,7 +488,7 @@ void PortWidget::onDragEnter(const DragEnterEvent& e) {
return;
}

CableWidget* cw = APP->scene->rack->incompleteCable;
CableWidget* cw = APP->scene->rack->getIncompleteCable();
if (cw) {
if (type == engine::Port::OUTPUT)
cw->hoveredOutputPort = this;
@@ -508,7 +508,7 @@ void PortWidget::onDragLeave(const DragLeaveEvent& e) {
if (!originPort)
return;

CableWidget* cw = APP->scene->rack->incompleteCable;
CableWidget* cw = APP->scene->rack->getIncompleteCable();
if (cw) {
if (type == engine::Port::OUTPUT)
cw->hoveredOutputPort = NULL;


+ 32
- 28
src/app/RackWidget.cpp View File

@@ -23,6 +23,22 @@ namespace rack {
namespace app {


struct RackWidget::Internal {
RailWidget* rail = NULL;
widget::Widget* moduleContainer = NULL;
widget::Widget* cableContainer = NULL;
CableWidget* incompleteCable = NULL;
int nextCableColorId = 0;
/** The last mouse position in the RackWidget */
math::Vec mousePos;

bool selecting = false;
math::Vec selectionStart;
math::Vec selectionEnd;
std::set<ModuleWidget*> selectedModules;
};


/** Creates a new Module and ModuleWidget */
static ModuleWidget* moduleWidgetFromJson(json_t* moduleJ) {
plugin::Model* model = plugin::modelFromJson(moduleJ);
@@ -81,21 +97,6 @@ struct CableContainer : widget::TransparentWidget {
};


struct RackWidget::Internal {
RailWidget* rail = NULL;
widget::Widget* moduleContainer = NULL;
widget::Widget* cableContainer = NULL;
int nextCableColorId = 0;
/** The last mouse position in the RackWidget */
math::Vec mousePos;

bool selecting = false;
math::Vec selectionStart;
math::Vec selectionEnd;
std::set<ModuleWidget*> selectedModules;
};


RackWidget::RackWidget() {
internal = new Internal;

@@ -1275,7 +1276,7 @@ void RackWidget::appendSelectionContextMenu(ui::Menu* menu) {
}

void RackWidget::clearCables() {
incompleteCable = NULL;
internal->incompleteCable = NULL;
internal->cableContainer->clearChildren();
}

@@ -1302,8 +1303,8 @@ void RackWidget::clearCablesAction() {
void RackWidget::clearCablesOnPort(PortWidget* port) {
for (CableWidget* cw : getCablesOnPort(port)) {
// Check if cable is connected to port
if (cw == incompleteCable) {
incompleteCable = NULL;
if (cw == internal->incompleteCable) {
internal->incompleteCable = NULL;
internal->cableContainer->removeChild(cw);
}
else {
@@ -1323,25 +1324,29 @@ void RackWidget::removeCable(CableWidget* cw) {
internal->cableContainer->removeChild(cw);
}

CableWidget* RackWidget::getIncompleteCable() {
return internal->incompleteCable;
}

void RackWidget::setIncompleteCable(CableWidget* cw) {
if (incompleteCable) {
internal->cableContainer->removeChild(incompleteCable);
delete incompleteCable;
incompleteCable = NULL;
if (internal->incompleteCable) {
internal->cableContainer->removeChild(internal->incompleteCable);
delete internal->incompleteCable;
internal->incompleteCable = NULL;
}
if (cw) {
internal->cableContainer->addChild(cw);
incompleteCable = cw;
internal->incompleteCable = cw;
}
}

CableWidget* RackWidget::releaseIncompleteCable() {
if (!incompleteCable)
if (!internal->incompleteCable)
return NULL;

CableWidget* cw = incompleteCable;
internal->cableContainer->removeChild(incompleteCable);
incompleteCable = NULL;
CableWidget* cw = internal->incompleteCable;
internal->cableContainer->removeChild(internal->incompleteCable);
internal->incompleteCable = NULL;
return cw;
}

@@ -1404,6 +1409,5 @@ NVGcolor RackWidget::getNextCableColor() {
}



} // namespace app
} // namespace rack

Loading…
Cancel
Save