Browse Source

Improve appearance of translucent or transparent cable colors.

tags/v2.3.0
Andrew Belt 1 year ago
parent
commit
1dba28cadd
3 changed files with 12 additions and 10 deletions
  1. +11
    -5
      src/app/CableWidget.cpp
  2. +1
    -1
      src/app/PortWidget.cpp
  3. +0
    -4
      src/app/RackWidget.cpp

+ 11
- 5
src/app/CableWidget.cpp View File

@@ -229,10 +229,13 @@ void CableWidget::mergeJson(json_t* rootJ) {


void CableWidget::fromJson(json_t* rootJ) { void CableWidget::fromJson(json_t* rootJ) {
json_t* colorJ = json_object_get(rootJ, "color"); 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 <v0.6.0, cables used JSON objects instead of hex strings. Just ignore them if so and use the existing cable color. // In <v0.6.0, cables used JSON objects instead of hex strings. Just ignore them if so and use the existing cable color.
if (json_is_string(colorJ))
color = color::fromHexString(json_string_value(colorJ));
// In <=v1, cable colors were not serialized.
color = APP->scene->rack->getNextCableColor();
} }
} }


@@ -251,12 +254,15 @@ void CableWidget::step() {
math::Vec inputPos = getInputPos(); math::Vec inputPos = getInputPos();
math::Vec slump = getSlumpPos(outputPos, inputPos); math::Vec slump = getSlumpPos(outputPos, inputPos);


NVGcolor colorOpaque = color;
colorOpaque.a = 1.f;

// Draw output plug // Draw output plug
bool outputTop = !isComplete() || APP->scene->rack->getTopCable(outputPort) == this; bool outputTop = !isComplete() || APP->scene->rack->getTopCable(outputPort) == this;
outputPlug->setPosition(outputPos); outputPlug->setPosition(outputPos);
outputPlug->setTop(outputTop); outputPlug->setTop(outputTop);
outputPlug->setAngle(slump.minus(outputPos).arg()); outputPlug->setAngle(slump.minus(outputPos).arg());
outputPlug->setColor(color);
outputPlug->setColor(colorOpaque);
outputPlug->setPortWidget(outputPort); outputPlug->setPortWidget(outputPort);


// Draw input plug // Draw input plug
@@ -264,7 +270,7 @@ void CableWidget::step() {
inputPlug->setPosition(inputPos); inputPlug->setPosition(inputPos);
inputPlug->setTop(inputTop); inputPlug->setTop(inputTop);
inputPlug->setAngle(slump.minus(inputPos).arg()); inputPlug->setAngle(slump.minus(inputPos).arg());
inputPlug->setColor(color);
inputPlug->setColor(colorOpaque);
inputPlug->setPortWidget(inputPort); inputPlug->setPortWidget(inputPort);


Widget::step(); Widget::step();


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

@@ -444,7 +444,7 @@ void PortWidget::onDragStart(const DragStartEvent& e) {
cw = new CableWidget; cw = new CableWidget;


// Set color // Set color
if (internal->overrideColor.a > 0.f)
if (internal->overrideCreateCable)
cw->color = internal->overrideColor; cw->color = internal->overrideColor;
else else
cw->color = APP->scene->rack->getNextCableColor(); cw->color = APP->scene->rack->getNextCableColor();


+ 0
- 4
src/app/RackWidget.cpp View File

@@ -377,10 +377,6 @@ void RackWidget::fromJson(json_t* rootJ) {
try { try {
cw->setCable(cable); cw->setCable(cable);
cw->fromJson(cableJ); 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) { catch (Exception& e) {
delete cw; delete cw;


Loading…
Cancel
Save