From e6f5c6296832b1dd8bf6bc13f255b692f84c10ed Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 16 Nov 2021 21:42:51 -0500 Subject: [PATCH] Add RackWidget::get/setNextCableColorId(). --- include/app/RackWidget.hpp | 4 ++++ src/app/RackWidget.cpp | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/app/RackWidget.hpp b/include/app/RackWidget.hpp index ce1567de..d1404646 100644 --- a/include/app/RackWidget.hpp +++ b/include/app/RackWidget.hpp @@ -119,6 +119,10 @@ struct RackWidget : widget::OpaqueWidget { std::vector getCompleteCables(); /** Returns all cables attached to port, complete or not. */ std::vector getCablesOnPort(PortWidget* port); + /** Returns but does not advance the next cable color. */ + int getNextCableColorId(); + void setNextCableColorId(int id); + /** Returns and advances the next cable color. */ NVGcolor getNextCableColor(); }; diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 571d5483..e5c91ef7 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -1399,12 +1399,25 @@ std::vector RackWidget::getCablesOnPort(PortWidget* port) { } +int RackWidget::getNextCableColorId() { + return internal->nextCableColorId; +} + + +void RackWidget::setNextCableColorId(int id) { + internal->nextCableColorId = id; +} + + NVGcolor RackWidget::getNextCableColor() { if (settings::cableColors.empty()) return color::WHITE; int id = internal->nextCableColorId++; - internal->nextCableColorId %= settings::cableColors.size(); + if (id >= settings::cableColors.size()) + id = 0; + if (internal->nextCableColorId >= settings::cableColors.size()) + internal->nextCableColorId = 0; return settings::cableColors[id]; }