From 1dba28cadda7918d69eb30089e93523b6ea67668 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Thu, 2 Mar 2023 01:57:19 -0500 Subject: [PATCH] Improve appearance of translucent or transparent cable colors. --- src/app/CableWidget.cpp | 16 +++++++++++----- src/app/PortWidget.cpp | 2 +- src/app/RackWidget.cpp | 4 ---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/app/CableWidget.cpp b/src/app/CableWidget.cpp index ce6e5227..62a2ebd2 100644 --- a/src/app/CableWidget.cpp +++ b/src/app/CableWidget.cpp @@ -229,10 +229,13 @@ void CableWidget::mergeJson(json_t* rootJ) { void CableWidget::fromJson(json_t* rootJ) { json_t* colorJ = json_object_get(rootJ, "color"); - if (colorJ) { + if (colorJ && json_is_string(colorJ)) { + color = color::fromHexString(json_string_value(colorJ)); + } + else { // In scene->rack->getNextCableColor(); } } @@ -251,12 +254,15 @@ void CableWidget::step() { math::Vec inputPos = getInputPos(); math::Vec slump = getSlumpPos(outputPos, inputPos); + NVGcolor colorOpaque = color; + colorOpaque.a = 1.f; + // Draw output plug bool outputTop = !isComplete() || APP->scene->rack->getTopCable(outputPort) == this; outputPlug->setPosition(outputPos); outputPlug->setTop(outputTop); outputPlug->setAngle(slump.minus(outputPos).arg()); - outputPlug->setColor(color); + outputPlug->setColor(colorOpaque); outputPlug->setPortWidget(outputPort); // Draw input plug @@ -264,7 +270,7 @@ void CableWidget::step() { inputPlug->setPosition(inputPos); inputPlug->setTop(inputTop); inputPlug->setAngle(slump.minus(inputPos).arg()); - inputPlug->setColor(color); + inputPlug->setColor(colorOpaque); inputPlug->setPortWidget(inputPort); Widget::step(); diff --git a/src/app/PortWidget.cpp b/src/app/PortWidget.cpp index e7d613b6..9bd9802a 100644 --- a/src/app/PortWidget.cpp +++ b/src/app/PortWidget.cpp @@ -444,7 +444,7 @@ void PortWidget::onDragStart(const DragStartEvent& e) { cw = new CableWidget; // Set color - if (internal->overrideColor.a > 0.f) + if (internal->overrideCreateCable) cw->color = internal->overrideColor; else cw->color = APP->scene->rack->getNextCableColor(); diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index fc933318..d5dae358 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -377,10 +377,6 @@ void RackWidget::fromJson(json_t* rootJ) { try { cw->setCable(cable); cw->fromJson(cableJ); - // In <=v1, cable colors were not serialized, so choose one from the available colors. - if (cw->color.a == 0.f) { - cw->color = getNextCableColor(); - } } catch (Exception& e) { delete cw;