From 941baf2d7ed0c2acd491462df35f15f0c401f252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Sun, 2 Apr 2023 21:44:45 +0200 Subject: [PATCH 01/63] Add a new script version which digests the raw selected colors. --- engine/src/rgbalgorithm.h | 4 ++- engine/src/rgbaudio.cpp | 3 +- engine/src/rgbaudio.h | 2 +- engine/src/rgbimage.cpp | 3 +- engine/src/rgbimage.h | 2 +- engine/src/rgbmatrix.cpp | 14 +++++++-- engine/src/rgbplain.cpp | 5 +-- engine/src/rgbplain.h | 2 +- engine/src/rgbscript.cpp | 13 ++++++-- engine/src/rgbscript.h | 2 +- engine/src/rgbscriptv4.cpp | 13 ++++++-- engine/src/rgbscriptv4.h | 2 +- engine/src/rgbtext.cpp | 3 +- engine/src/rgbtext.h | 2 +- engine/test/rgbscript/rgbscript_test.cpp | 40 +++++++++++++++--------- engine/test/rgbtext/rgbtext_test.cpp | 30 ++++++++++++------ 16 files changed, 98 insertions(+), 42 deletions(-) diff --git a/engine/src/rgbalgorithm.h b/engine/src/rgbalgorithm.h index 69ce660e05..92fe3cfcd8 100644 --- a/engine/src/rgbalgorithm.h +++ b/engine/src/rgbalgorithm.h @@ -40,6 +40,8 @@ typedef QVector > RGBMap; #define KXMLQLCRGBAlgorithm QString("Algorithm") #define KXMLQLCRGBAlgorithmType QString("Type") +#define RGBAlgorithmRawColorCount 2 + class RGBAlgorithm { public: @@ -73,7 +75,7 @@ class RGBAlgorithm virtual int rgbMapStepCount(const QSize& size) = 0; /** Load a RGBMap for the given step. */ - virtual void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) = 0; + virtual void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors) = 0; /** Release resources that may have been acquired in rgbMap() */ virtual void postRun() {} diff --git a/engine/src/rgbaudio.cpp b/engine/src/rgbaudio.cpp index d41769938d..8f9c5f9a18 100644 --- a/engine/src/rgbaudio.cpp +++ b/engine/src/rgbaudio.cpp @@ -121,9 +121,10 @@ int RGBAudio::rgbMapStepCount(const QSize& size) return 1; } -void RGBAudio::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) +void RGBAudio::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors) { Q_UNUSED(step); + Q_UNUSED(rawColors); QMutexLocker locker(&m_mutex); diff --git a/engine/src/rgbaudio.h b/engine/src/rgbaudio.h index 42718389d3..5f8e73c3fe 100644 --- a/engine/src/rgbaudio.h +++ b/engine/src/rgbaudio.h @@ -71,7 +71,7 @@ protected slots: int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors); /** @reimp */ virtual void postRun(); diff --git a/engine/src/rgbimage.cpp b/engine/src/rgbimage.cpp index 259f0e70cd..f26565eefb 100644 --- a/engine/src/rgbimage.cpp +++ b/engine/src/rgbimage.cpp @@ -235,9 +235,10 @@ int RGBImage::rgbMapStepCount(const QSize& size) } } -void RGBImage::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) +void RGBImage::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors) { Q_UNUSED(rgb); + Q_UNUSED(rawColors); QMutexLocker locker(&m_mutex); diff --git a/engine/src/rgbimage.h b/engine/src/rgbimage.h index 6ed672bfe4..6f65bfc609 100644 --- a/engine/src/rgbimage.h +++ b/engine/src/rgbimage.h @@ -103,7 +103,7 @@ class RGBImage : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors); /** @reimp */ QString name() const; diff --git a/engine/src/rgbmatrix.cpp b/engine/src/rgbmatrix.cpp index 7af1c822c9..afc19ec277 100644 --- a/engine/src/rgbmatrix.cpp +++ b/engine/src/rgbmatrix.cpp @@ -277,8 +277,12 @@ void RGBMatrix::previewMap(int step, RGBMatrixStep *handler) if (m_group == NULL) m_group = doc()->fixtureGroup(fixtureGroup()); - if (m_group != NULL) - m_algorithm->rgbMap(m_group->size(), handler->stepColor().rgb(), step, handler->m_map); + if (m_group != NULL) { + unsigned int rawColors[] = { + m_startColor.rgb(), + m_endColor.isValid() ? m_endColor.rgb() : 0}; + m_algorithm->rgbMap(m_group->size(), handler->stepColor().rgb(), step, handler->m_map, rawColors); + } } /**************************************************************************** @@ -576,9 +580,13 @@ void RGBMatrix::write(MasterTimer *timer, QList universes) if (tempoType() == Beats) m_stepBeatDuration = beatsToTime(duration(), timer->beatTimeDuration()); + unsigned int rawColors[] = { + m_startColor.rgb(), + m_endColor.isValid() ? m_endColor.rgb() : 0}; //qDebug() << "RGBMatrix step" << m_stepHandler->currentStepIndex() << ", color:" << QString::number(m_stepHandler->stepColor().rgb(), 16); m_algorithm->rgbMap(m_group->size(), m_stepHandler->stepColor().rgb(), - m_stepHandler->currentStepIndex(), m_stepHandler->m_map); + m_stepHandler->currentStepIndex(), m_stepHandler->m_map, + rawColors); updateMapChannels(m_stepHandler->m_map, m_group, universes); } } diff --git a/engine/src/rgbplain.cpp b/engine/src/rgbplain.cpp index a9b972009f..fea9758461 100644 --- a/engine/src/rgbplain.cpp +++ b/engine/src/rgbplain.cpp @@ -56,9 +56,10 @@ int RGBPlain::rgbMapStepCount(const QSize& size) return 1; } -void RGBPlain::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) +void RGBPlain::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors) { - Q_UNUSED(step) + Q_UNUSED(step); + Q_UNUSED(rawColors); map.resize(size.height()); for (int y = 0; y < size.height(); y++) { diff --git a/engine/src/rgbplain.h b/engine/src/rgbplain.h index 83691b70ae..cfbd842881 100644 --- a/engine/src/rgbplain.h +++ b/engine/src/rgbplain.h @@ -50,7 +50,7 @@ class RGBPlain : public QObject, public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors); /** @reimp */ QString name() const; diff --git a/engine/src/rgbscript.cpp b/engine/src/rgbscript.cpp index 0a23270bba..d312ba338f 100644 --- a/engine/src/rgbscript.cpp +++ b/engine/src/rgbscript.cpp @@ -231,7 +231,7 @@ int RGBScript::rgbMapStepCount(const QSize& size) return ret; } -void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) +void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors) { QMutexLocker engineLocker(s_engineMutex); @@ -239,7 +239,16 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) return; QScriptValueList args; - args << size.width() << size.height() << rgb << step; + if (m_apiVersion <= 2) { + args << size.width() << size.height() << rgb << step; + } else { + QScriptValue jsRawColors = s_engine->newArray(RGBAlgorithmRawColorCount); + Q_ASSERT(2 == RGBAlgorithmRawColorCount); + jsRawColors.setProperty(0, QScriptValue(s_engine, rawColors[0])); + jsRawColors.setProperty(1, QScriptValue(s_engine, rawColors[1])); + + args << size.width() << size.height() << rgb << step << jsRawColors; + } QScriptValue yarray = m_rgbMap.call(QScriptValue(), args); if (yarray.isArray() == true) { diff --git a/engine/src/rgbscript.h b/engine/src/rgbscript.h index 2d2bcdebbb..69bfa5adec 100644 --- a/engine/src/rgbscript.h +++ b/engine/src/rgbscript.h @@ -88,7 +88,7 @@ class RGBScript : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors); /** @reimp */ QString name() const; diff --git a/engine/src/rgbscriptv4.cpp b/engine/src/rgbscriptv4.cpp index 7b9908b9de..398dd18df4 100644 --- a/engine/src/rgbscriptv4.cpp +++ b/engine/src/rgbscriptv4.cpp @@ -217,7 +217,7 @@ int RGBScript::rgbMapStepCount(const QSize& size) return ret; } -void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) +void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors) { QMutexLocker engineLocker(s_engineMutex); @@ -225,7 +225,16 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) return; QJSValueList args; - args << size.width() << size.height() << rgb << step; + if (m_apiVersion <= 2) { + args << size.width() << size.height() << rgb << step; + } else { + QJSValue jsRawColors = s_engine->newArray(RGBAlgorithmRawColorCount); + Q_ASSERT(2 == RGBAlgorithmRawColorCount); + jsRawColors.setProperty(0, QJSValue(rawColors[0])); + jsRawColors.setProperty(1, QJSValue(rawColors[1])); + + args << size.width() << size.height() << rgb << step << jsRawColors; + } QJSValue yarray(m_rgbMap.call(args)); if (yarray.isArray() == true) diff --git a/engine/src/rgbscriptv4.h b/engine/src/rgbscriptv4.h index 6f00f71473..ec7e8d68dc 100644 --- a/engine/src/rgbscriptv4.h +++ b/engine/src/rgbscriptv4.h @@ -89,7 +89,7 @@ class RGBScript : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors); /** @reimp */ QString name() const; diff --git a/engine/src/rgbtext.cpp b/engine/src/rgbtext.cpp index 10b2af6d79..19c85e72ab 100644 --- a/engine/src/rgbtext.cpp +++ b/engine/src/rgbtext.cpp @@ -266,8 +266,9 @@ int RGBText::rgbMapStepCount(const QSize& size) return scrollingTextStepCount(); } -void RGBText::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) +void RGBText::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors) { + Q_UNUSED(rawColors); if (animationStyle() == StaticLetters) renderStaticLetters(size, rgb, step, map); else diff --git a/engine/src/rgbtext.h b/engine/src/rgbtext.h index 1f1879c27a..3ea71d24ad 100644 --- a/engine/src/rgbtext.h +++ b/engine/src/rgbtext.h @@ -99,7 +99,7 @@ class RGBText : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors); /** @reimp */ QString name() const; diff --git a/engine/test/rgbscript/rgbscript_test.cpp b/engine/test/rgbscript/rgbscript_test.cpp index 888bc5e935..17d4bbf145 100644 --- a/engine/test/rgbscript/rgbscript_test.cpp +++ b/engine/test/rgbscript/rgbscript_test.cpp @@ -175,7 +175,11 @@ void RGBScript_Test::evaluateNoRgbMapFunction() RGBMap map; s.m_contents = code; QCOMPARE(s.evaluate(), false); - s.rgbMap(QSize(5, 5), 1, 0, map); + uint rawRgbColors[RGBAlgorithmRawColorCount] = { + QColor(Qt::red).rgb(), + QColor(Qt::green).rgb() + }; + s.rgbMap(QSize(5, 5), 1, 0, map, rawRgbColors); QCOMPARE(map, RGBMap()); } @@ -208,7 +212,11 @@ void RGBScript_Test::rgbMap() { RGBMap map; RGBScript s = m_doc->rgbScriptsCache()->script("Stripes"); - s.rgbMap(QSize(3, 4), 0, 0, map); + uint rawRgbColors[RGBAlgorithmRawColorCount] = { + QColor(Qt::red).rgb(), + uint(0) + }; + s.rgbMap(QSize(3, 4), 0, 0, map, rawRgbColors); QVERIFY(map.isEmpty() == false); s.setProperty("orientation", "Vertical"); @@ -217,16 +225,16 @@ void RGBScript_Test::rgbMap() for (int step = 0; step < 5; step++) { RGBMap map; - s.rgbMap(QSize(5, 5), QColor(Qt::red).rgb(), step, map); + s.rgbMap(QSize(5, 5), rawRgbColors[0], step, map, rawRgbColors); for (int y = 0; y < 5; y++) { for (int x = 0; x < 5; x++) { if (y == step) - QCOMPARE(map[y][x], QColor(Qt::red).rgb()); + QCOMPARE(map[y][x], rawRgbColors[0]); else - QCOMPARE(map[y][x], uint(0)); + QCOMPARE(map[y][x], rawRgbColors[1]); } } } @@ -239,6 +247,10 @@ void RGBScript_Test::runScripts() // QColor(Qt::red).rgb() is 0xffff0000 due to the alpha channel // This test also wants to test that there is no color space overrun. int red = 0xff0000; + uint rawRgbColors[RGBAlgorithmRawColorCount] = { + QColor(Qt::red).rgb(), + 0 + }; // Iterate the list of scripts QStringList names = m_doc->rgbScriptsCache()->names(); @@ -273,7 +285,7 @@ void RGBScript_Test::runScripts() { // limit the scope of this map to keep it clean for future executions RGBMap map; - s.rgbMap(mapSize, 0, 0, map); + s.rgbMap(mapSize, 0, 0, map, rawRgbColors); QVERIFY(map.isEmpty() == false); } @@ -292,7 +304,7 @@ void RGBScript_Test::runScripts() RGBMap rgbMap; for (int step = 0; step < realsteps; step++) { - s.rgbMap(mapSize, red, step, rgbMap); + s.rgbMap(mapSize, red, step, rgbMap, rawRgbColors); QVERIFY(rgbMap.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) @@ -314,12 +326,12 @@ void RGBScript_Test::runScripts() RGBMap rgbRefMap; if (1 < s.acceptColors() && 2 < steps && ! randomScript) { // When more than 2 colors are accepted, the steps shall be reproducible to allow back and forth color fade. - s.rgbMap(mapSizePlus, red, 0, rgbRefMap); + s.rgbMap(mapSizePlus, red, 0, rgbRefMap, rawRgbColors); } // Switch to the larger map and step a few times. for (int step = 0; step < realsteps; step++) { - s.rgbMap(mapSizePlus, red, step, rgbMap); + s.rgbMap(mapSizePlus, red, step, rgbMap, rawRgbColors); // Check that the color values are limited to a valid range for (int y = 0; y < mapSizePlus.height(); y++) { @@ -386,7 +398,7 @@ void RGBScript_Test::runScripts() for (int step = 0; step < realsteps; step++) { RGBMap map; - s.rgbMap(mapSize, red, step, map); + s.rgbMap(mapSize, red, step, map, rawRgbColors); QVERIFY(map.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) @@ -415,7 +427,7 @@ void RGBScript_Test::runScripts() for (int step = 0; step < realsteps; step++) { RGBMap map; - s.rgbMap(mapSize, red, step, map); + s.rgbMap(mapSize, red, step, map, rawRgbColors); QVERIFY(map.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) @@ -433,7 +445,7 @@ void RGBScript_Test::runScripts() for (int step = 0; step < realsteps; step++) { RGBMap map; - s.rgbMap(mapSize, red, step, map); + s.rgbMap(mapSize, red, step, map, rawRgbColors); QVERIFY(map.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) @@ -453,7 +465,7 @@ void RGBScript_Test::runScripts() for (int step = 0; step < realsteps; step++) { RGBMap map; - s.rgbMap(mapSize, red, step, map); + s.rgbMap(mapSize, red, step, map, rawRgbColors); QVERIFY(map.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) @@ -473,7 +485,7 @@ void RGBScript_Test::runScripts() for (int step = 0; step < realsteps; step++) { RGBMap map; - s.rgbMap(mapSize, red, step, map); + s.rgbMap(mapSize, red, step, map, rawRgbColors); QVERIFY(map.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) diff --git a/engine/test/rgbtext/rgbtext_test.cpp b/engine/test/rgbtext/rgbtext_test.cpp index 1c2a4cad90..0fa478ef0e 100644 --- a/engine/test/rgbtext/rgbtext_test.cpp +++ b/engine/test/rgbtext/rgbtext_test.cpp @@ -324,28 +324,32 @@ void RGBText_Test::staticLetters() QRgb color(0xFFFFFFFF); RGBMap map; + uint rawRgbColors[RGBAlgorithmRawColorCount] = { + QColor(Qt::red).rgb(), + QColor(Qt::green).rgb() + }; // Since fonts and their rendering differs from installation to installation, // these tests are here only to check that nothing crashes. The end result is // more or less OS, platform, HW and SW dependent and testing individual pixels // would thus be rather pointless. - text.rgbMap(QSize(10, 10), color, 0, map); + text.rgbMap(QSize(10, 10), color, 0, map, rawRgbColors); QCOMPARE(map.size(), 10); for (int i = 0; i < 10; i++) QCOMPARE(map[i].size(), 10); - text.rgbMap(QSize(10, 10), color, 1, map); + text.rgbMap(QSize(10, 10), color, 1, map, rawRgbColors); QCOMPARE(map.size(), 10); for (int i = 0; i < 10; i++) QCOMPARE(map[i].size(), 10); - text.rgbMap(QSize(10, 10), color, 2, map); + text.rgbMap(QSize(10, 10), color, 2, map, rawRgbColors); QCOMPARE(map.size(), 10); for (int i = 0; i < 10; i++) QCOMPARE(map[i].size(), 10); // Invalid step - text.rgbMap(QSize(10, 10), color, 3, map); + text.rgbMap(QSize(10, 10), color, 3, map, rawRgbColors); QCOMPARE(map.size(), 10); for (int i = 0; i < 10; i++) { @@ -362,6 +366,10 @@ void RGBText_Test::horizontalScroll() RGBText text(m_doc); text.setText("QLC"); text.setAnimationStyle(RGBText::Horizontal); + uint rawRgbColors[RGBAlgorithmRawColorCount] = { + QColor(Qt::red).rgb(), + QColor(Qt::green).rgb() + }; QFontMetrics fm(text.font()); #if (QT_VERSION < QT_VERSION_CHECK(5, 11, 0)) @@ -381,7 +389,7 @@ void RGBText_Test::horizontalScroll() #endif { RGBMap map; - text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), i, map); + text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), i, map, rawRgbColors); QCOMPARE(map.size(), 10); for (int y = 0; y < 10; y++) QCOMPARE(map[y].size(), 10); @@ -390,9 +398,9 @@ void RGBText_Test::horizontalScroll() RGBMap map; // Invalid step #if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0)) - text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), fm.width("QLC"), map); + text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), fm.width("QLC"), map, rawRgbColors); #else - text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), fm.horizontalAdvance("QLC"), map); + text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), fm.horizontalAdvance("QLC"), map, rawRgbColors); #endif QCOMPARE(map.size(), 10); for (int i = 0; i < 10; i++) @@ -410,6 +418,10 @@ void RGBText_Test::verticalScroll() RGBText text(m_doc); text.setText("QLC"); text.setAnimationStyle(RGBText::Vertical); + uint rawRgbColors[RGBAlgorithmRawColorCount] = { + QColor(Qt::red).rgb(), + QColor(Qt::green).rgb() + }; QFontMetrics fm(text.font()); QCOMPARE(text.rgbMapStepCount(QSize()), fm.ascent() * 3); // Q, L, C @@ -421,7 +433,7 @@ void RGBText_Test::verticalScroll() for (int i = 0; i < fm.ascent() * 3; i++) { RGBMap map; - text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), i, map); + text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), i, map, rawRgbColors); QCOMPARE(map.size(), 10); for (int y = 0; y < 10; y++) QCOMPARE(map[y].size(), 10); @@ -429,7 +441,7 @@ void RGBText_Test::verticalScroll() // Invalid step RGBMap map; - text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), fm.ascent() * 4, map); + text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), fm.ascent() * 4, map, rawRgbColors); QCOMPARE(map.size(), 10); for (int i = 0; i < 10; i++) { From 41ca80a5ac478651d38adf31a946e3236e96269e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Tue, 4 Apr 2023 22:05:31 +0200 Subject: [PATCH 02/63] Implement an additional rawColors array function argument --- engine/src/rgbalgorithm.h | 3 ++- engine/src/rgbaudio.cpp | 2 +- engine/src/rgbaudio.h | 2 +- engine/src/rgbimage.cpp | 2 +- engine/src/rgbimage.h | 2 +- engine/src/rgbmatrix.cpp | 7 +++---- engine/src/rgbplain.cpp | 2 +- engine/src/rgbplain.h | 2 +- engine/src/rgbscript.cpp | 2 +- engine/src/rgbscript.h | 2 +- engine/src/rgbscriptv4.cpp | 4 ++-- engine/src/rgbscriptv4.h | 2 +- engine/src/rgbtext.cpp | 2 +- engine/src/rgbtext.h | 2 +- 14 files changed, 18 insertions(+), 18 deletions(-) diff --git a/engine/src/rgbalgorithm.h b/engine/src/rgbalgorithm.h index 92fe3cfcd8..8679c7af14 100644 --- a/engine/src/rgbalgorithm.h +++ b/engine/src/rgbalgorithm.h @@ -75,7 +75,8 @@ class RGBAlgorithm virtual int rgbMapStepCount(const QSize& size) = 0; /** Load a RGBMap for the given step. */ - virtual void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors) = 0; + virtual void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, + uint (&rawColors)[RGBAlgorithmRawColorCount]) = 0; /** Release resources that may have been acquired in rgbMap() */ virtual void postRun() {} diff --git a/engine/src/rgbaudio.cpp b/engine/src/rgbaudio.cpp index 8f9c5f9a18..f38b18016d 100644 --- a/engine/src/rgbaudio.cpp +++ b/engine/src/rgbaudio.cpp @@ -121,7 +121,7 @@ int RGBAudio::rgbMapStepCount(const QSize& size) return 1; } -void RGBAudio::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors) +void RGBAudio::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]) { Q_UNUSED(step); Q_UNUSED(rawColors); diff --git a/engine/src/rgbaudio.h b/engine/src/rgbaudio.h index 5f8e73c3fe..8fee1c5046 100644 --- a/engine/src/rgbaudio.h +++ b/engine/src/rgbaudio.h @@ -71,7 +71,7 @@ protected slots: int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]); /** @reimp */ virtual void postRun(); diff --git a/engine/src/rgbimage.cpp b/engine/src/rgbimage.cpp index f26565eefb..12fc5da60e 100644 --- a/engine/src/rgbimage.cpp +++ b/engine/src/rgbimage.cpp @@ -235,7 +235,7 @@ int RGBImage::rgbMapStepCount(const QSize& size) } } -void RGBImage::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors) +void RGBImage::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]) { Q_UNUSED(rgb); Q_UNUSED(rawColors); diff --git a/engine/src/rgbimage.h b/engine/src/rgbimage.h index 6f65bfc609..226967a61a 100644 --- a/engine/src/rgbimage.h +++ b/engine/src/rgbimage.h @@ -103,7 +103,7 @@ class RGBImage : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]); /** @reimp */ QString name() const; diff --git a/engine/src/rgbmatrix.cpp b/engine/src/rgbmatrix.cpp index afc19ec277..1fc52bd852 100644 --- a/engine/src/rgbmatrix.cpp +++ b/engine/src/rgbmatrix.cpp @@ -278,7 +278,7 @@ void RGBMatrix::previewMap(int step, RGBMatrixStep *handler) m_group = doc()->fixtureGroup(fixtureGroup()); if (m_group != NULL) { - unsigned int rawColors[] = { + uint rawColors[] = { m_startColor.rgb(), m_endColor.isValid() ? m_endColor.rgb() : 0}; m_algorithm->rgbMap(m_group->size(), handler->stepColor().rgb(), step, handler->m_map, rawColors); @@ -580,13 +580,12 @@ void RGBMatrix::write(MasterTimer *timer, QList universes) if (tempoType() == Beats) m_stepBeatDuration = beatsToTime(duration(), timer->beatTimeDuration()); - unsigned int rawColors[] = { + uint rawColors[] = { m_startColor.rgb(), m_endColor.isValid() ? m_endColor.rgb() : 0}; //qDebug() << "RGBMatrix step" << m_stepHandler->currentStepIndex() << ", color:" << QString::number(m_stepHandler->stepColor().rgb(), 16); m_algorithm->rgbMap(m_group->size(), m_stepHandler->stepColor().rgb(), - m_stepHandler->currentStepIndex(), m_stepHandler->m_map, - rawColors); + m_stepHandler->currentStepIndex(), m_stepHandler->m_map, rawColors); updateMapChannels(m_stepHandler->m_map, m_group, universes); } } diff --git a/engine/src/rgbplain.cpp b/engine/src/rgbplain.cpp index fea9758461..00404f6a0e 100644 --- a/engine/src/rgbplain.cpp +++ b/engine/src/rgbplain.cpp @@ -56,7 +56,7 @@ int RGBPlain::rgbMapStepCount(const QSize& size) return 1; } -void RGBPlain::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors) +void RGBPlain::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]) { Q_UNUSED(step); Q_UNUSED(rawColors); diff --git a/engine/src/rgbplain.h b/engine/src/rgbplain.h index cfbd842881..5748741235 100644 --- a/engine/src/rgbplain.h +++ b/engine/src/rgbplain.h @@ -50,7 +50,7 @@ class RGBPlain : public QObject, public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]); /** @reimp */ QString name() const; diff --git a/engine/src/rgbscript.cpp b/engine/src/rgbscript.cpp index d312ba338f..bb611aebc8 100644 --- a/engine/src/rgbscript.cpp +++ b/engine/src/rgbscript.cpp @@ -231,7 +231,7 @@ int RGBScript::rgbMapStepCount(const QSize& size) return ret; } -void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors) +void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]) { QMutexLocker engineLocker(s_engineMutex); diff --git a/engine/src/rgbscript.h b/engine/src/rgbscript.h index 69bfa5adec..3aa2f2a1d4 100644 --- a/engine/src/rgbscript.h +++ b/engine/src/rgbscript.h @@ -88,7 +88,7 @@ class RGBScript : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]); /** @reimp */ QString name() const; diff --git a/engine/src/rgbscriptv4.cpp b/engine/src/rgbscriptv4.cpp index 398dd18df4..e5253596cd 100644 --- a/engine/src/rgbscriptv4.cpp +++ b/engine/src/rgbscriptv4.cpp @@ -217,7 +217,7 @@ int RGBScript::rgbMapStepCount(const QSize& size) return ret; } -void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors) +void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]) { QMutexLocker engineLocker(s_engineMutex); @@ -228,7 +228,7 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint if (m_apiVersion <= 2) { args << size.width() << size.height() << rgb << step; } else { - QJSValue jsRawColors = s_engine->newArray(RGBAlgorithmRawColorCount); + QVariantList jsRawColors = s_engine->newArray(RGBAlgorithmRawColorCount); Q_ASSERT(2 == RGBAlgorithmRawColorCount); jsRawColors.setProperty(0, QJSValue(rawColors[0])); jsRawColors.setProperty(1, QJSValue(rawColors[1])); diff --git a/engine/src/rgbscriptv4.h b/engine/src/rgbscriptv4.h index ec7e8d68dc..fdb4cdc302 100644 --- a/engine/src/rgbscriptv4.h +++ b/engine/src/rgbscriptv4.h @@ -89,7 +89,7 @@ class RGBScript : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]); /** @reimp */ QString name() const; diff --git a/engine/src/rgbtext.cpp b/engine/src/rgbtext.cpp index 19c85e72ab..542a9dec20 100644 --- a/engine/src/rgbtext.cpp +++ b/engine/src/rgbtext.cpp @@ -266,7 +266,7 @@ int RGBText::rgbMapStepCount(const QSize& size) return scrollingTextStepCount(); } -void RGBText::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors) +void RGBText::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]) { Q_UNUSED(rawColors); if (animationStyle() == StaticLetters) diff --git a/engine/src/rgbtext.h b/engine/src/rgbtext.h index 3ea71d24ad..d5a1ad7561 100644 --- a/engine/src/rgbtext.h +++ b/engine/src/rgbtext.h @@ -99,7 +99,7 @@ class RGBText : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint *rawColors); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]); /** @reimp */ QString name() const; From fbfe04a9ade23b5b4bf7ee17a00d66c76bf00f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Thu, 6 Apr 2023 11:09:34 +0200 Subject: [PATCH 03/63] Integrate JS rgbScript updates. --- engine/test/rgbscript/rgbscript_test.cpp | 2 +- resources/rgbscripts/alternate.js | 118 +++-------------------- resources/rgbscripts/ballscolors.js | 4 +- resources/rgbscripts/devtool/devtool.js | 28 +++++- resources/rgbscripts/empty.js | 4 +- resources/rgbscripts/plasmacolors.js | 4 +- 6 files changed, 44 insertions(+), 116 deletions(-) diff --git a/engine/test/rgbscript/rgbscript_test.cpp b/engine/test/rgbscript/rgbscript_test.cpp index 17d4bbf145..19805acca0 100644 --- a/engine/test/rgbscript/rgbscript_test.cpp +++ b/engine/test/rgbscript/rgbscript_test.cpp @@ -289,7 +289,7 @@ void RGBScript_Test::runScripts() QVERIFY(map.isEmpty() == false); } - QVERIFY(s.apiVersion() >= 1 && s.apiVersion() <= 2); + QVERIFY(s.apiVersion() >= 1 && s.apiVersion() <= 3); QVERIFY(!s.author().isEmpty()); QVERIFY(!s.name().isEmpty()); QVERIFY(s.type() == RGBAlgorithm::Script); diff --git a/resources/rgbscripts/alternate.js b/resources/rgbscripts/alternate.js index a1f612445f..2214afd6f1 100644 --- a/resources/rgbscripts/alternate.js +++ b/resources/rgbscripts/alternate.js @@ -21,117 +21,17 @@ var testAlgo; (function() { - var colorPalette = new Object; - colorPalette.collection = new Array( - ["White", 0xFFFFFF], // 0 - ["Cream", 0xFFFF7F], // 1 - ["Pink", 0xFF7F7F], // 2 - ["Rose", 0x7F3F3F], // 3 - ["Coral", 0x7F3F1F], // 4 - ["Dim Red", 0x7F0000], // 5 - ["Red", 0xFF0000], // 6 - ["Orange", 0xFF3F00], // 7 - ["Dim Orange", 0x7F1F00], // 8 - ["Goldenrod", 0x7F3F00], // 9 - ["Gold", 0xFF7F00], // 10 - ["Yellow", 0xFFFF00], // 11 - ["Dim Yellow", 0x7F7F00], // 12 - ["Lime", 0x7FFF00], // 13 - ["Pale Green", 0x3F7F00], // 14 - ["Dim Green", 0x007F00], // 15 - ["Green", 0x00FF00], // 16 - ["Seafoam", 0x00FF3F], // 17 - ["Turquoise", 0x007F3F], // 18 - ["Teal", 0x007F7F], // 19 - ["Cyan", 0x00FFFF], // 20 - ["Electric Blue", 0x007FFF], // 21 - ["Blue", 0x0000FF], // 22 - ["Dim Blue", 0x00007F], // 23 - ["Pale Blue", 0x1F1F7F], // 24 - ["Indigo", 0x1F00BF], // 25 - ["Purple", 0x3F00BF], // 26 - ["Violet", 0x7F007F], // 27 - ["Magenta", 0xFF00FF], // 28 - ["Hot Pink", 0xFF003F], // 29 - ["Deep Pink", 0x7F001F], // 30 - ["OFF", 0x000000]); // 31 - - colorPalette.makeSubArray = function(_index) { - var _array = new Array(); - for (var i = 0; i < colorPalette.collection.length; i++) { - _array.push(colorPalette.collection[parseInt(i)][parseInt(_index)]); - } - return _array; - }; - colorPalette.names = colorPalette.makeSubArray(0); - var algo = new Object; - algo.apiVersion = 2; + algo.apiVersion = 3; algo.name = "Alternate"; algo.author = "Hans-Jürgen Tappe"; var x = 0; var y = 0; - algo.acceptColors = 0; + algo.acceptColors = 2; algo.properties = new Array(); - algo.getColorIndex = function(_name) { - var idx = colorPalette.names.indexOf(_name); - if (idx === -1) { - idx = (colorPalette.collection.length - 1); - } - return idx; - }; - - algo.color1Index = algo.getColorIndex("Red"); - algo.properties.push("name:color1Index|type:list|display:Color 1|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor1Index|read:getColor1Name"); - algo.color2Index = algo.getColorIndex("Green"); - algo.properties.push("name:color2Index|type:list|display:Color 2|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor2Index|read:getColor2Name"); - - algo.getColorName = function(_index) { - if (_index < 0) { - _index = 0; - } - if (_index >= colorPalette.collection.length) { - _index = (colorPalette.collection.length - 1); - } - return colorPalette.collection[parseInt(_index)][0]; - }; - algo.getColorValue = function(_index) { - if (_index < 0) { - _index = 0; - } - if (_index >= colorPalette.collection.length) { - _index = (colorPalette.collection.length - 1); - } - return colorPalette.collection[parseInt(_index)][1]; - }; - - algo.setColor1Index = function(_name) { - algo.color1Index = algo.getColorIndex(_name); - }; - algo.getColor1Name = function() { - return algo.getColorName(algo.color1Index); - }; - algo.getColor1Value = function() { - return algo.getColorValue(algo.color1Index); - }; - - algo.setColor2Index = function(_name) { - algo.color2Index = algo.getColorIndex(_name); - }; - algo.getColor2Name = function() { - return algo.getColorName(algo.color2Index); - }; - algo.getColor2Value = function() { - return algo.getColorValue(algo.color2Index); - }; - algo.align = 0; algo.properties.push("name:align|type:list|" + "display:Align (for even width)|values:Left,Centered|" + @@ -199,7 +99,15 @@ var testAlgo; return algo.offset; }; - algo.rgbMap = function(width, height, rgb, step) { + algo.getRawColor = function (rawColors, idx) { + if (Array.isArray(rawColors) && ! Number.isNaN(rawColors[idx])) { + return rawColors[idx]; + } else { + return 0; + } + } + + algo.rgbMap = function(width, height, rgb, step, rawColors) { var map = new Array(height); var effectiveStep = step; var colorSelectOne = (step === 1) ? false : true; @@ -244,9 +152,9 @@ var testAlgo; } } if (colorSelectOne) { - map[parseInt(y)][parseInt(x)] = algo.getColor1Value(); + map[parseInt(y)][parseInt(x)] = algo.getRawColor(rawColors, 0); } else { - map[parseInt(y)][parseInt(x)] = algo.getColor2Value(); + map[parseInt(y)][parseInt(x)] = algo.getRawColor(rawColors, 1); } } } diff --git a/resources/rgbscripts/ballscolors.js b/resources/rgbscripts/ballscolors.js index 994cacfde4..b75d446b89 100644 --- a/resources/rgbscripts/ballscolors.js +++ b/resources/rgbscripts/ballscolors.js @@ -67,7 +67,7 @@ var testAlgo; colorPalette.names = colorPalette.makeSubArray(0); var algo = new Object; - algo.apiVersion = 2; + algo.apiVersion = 3; algo.name = "Balls (Colors)"; algo.author = "Rob Nieuwenhuizen"; algo.acceptColors = 0; @@ -213,7 +213,7 @@ var testAlgo; return; }; - algo.rgbMap = function (width, height, rgb, progstep) { + algo.rgbMap = function (width, height, rgb, progstep, rawColors) { if (algo.initialized === false) { util.initialize(width, height); } diff --git a/resources/rgbscripts/devtool/devtool.js b/resources/rgbscripts/devtool/devtool.js index 06409afa32..47e5c1f390 100644 --- a/resources/rgbscripts/devtool/devtool.js +++ b/resources/rgbscripts/devtool/devtool.js @@ -247,12 +247,22 @@ devtool.getRgbFromColorInt = function(color) return [red, green, blue]; } -devtool.getCurrentColorInt = function() +devtool.getPrimaryColorInt = function() { var primaryColorInput = document.getElementById("primaryColor"); - var primaryColor = parseInt(primaryColorInput.value, 16); + return parseInt(primaryColorInput.value, 16); +} + +devtool.getSecondaryColorInt = function() +{ var secondaryColorInput = document.getElementById("secondaryColor"); - var secondaryColor = parseInt(secondaryColorInput.value, 16); + return parseInt(secondaryColorInput.value, 16); +} + +devtool.getCurrentColorInt = function() +{ + var primaryColor = devtool.getPrimaryColorInt(); + var secondaryColor = devtool.getSecondaryColorInt(); if (testAlgo.acceptColors === 0 || Number.isNaN(primaryColor)) { return null; @@ -283,7 +293,17 @@ devtool.writeCurrentStep = function() for (var i = map.rows.length - 1; i >= 0; i--) { map.deleteRow(i); } - var rgb = testAlgo.rgbMap(devtool.gridwidth, devtool.gridheight, devtool.getCurrentColorInt(), devtool.currentStep); + + var primaryColorRgb = devtool.getPrimaryColorInt(); + var secondaryColorRgb = devtool.getSecondaryColorInt(); + var rawColors = [primaryColorRgb, secondaryColorRgb]; + + var rgb; + if (testAlgo.apiVersion > 2) { + rgb = testAlgo.rgbMap(devtool.gridwidth, devtool.gridheight, devtool.getCurrentColorInt(), devtool.currentStep, rawColors); + } else { + rgb = testAlgo.rgbMap(devtool.gridwidth, devtool.gridheight, devtool.getCurrentColorInt(), devtool.currentStep); + } for (var y = 0; y < devtool.gridheight; y++) { diff --git a/resources/rgbscripts/empty.js b/resources/rgbscripts/empty.js index 25589b639e..7aa49628f1 100644 --- a/resources/rgbscripts/empty.js +++ b/resources/rgbscripts/empty.js @@ -24,7 +24,7 @@ var testAlgo; function() { var algo = new Object; - algo.apiVersion = 2; + algo.apiVersion = 3; algo.name = "Script name"; algo.author = "Your Name"; algo.properties = new Array(); @@ -37,7 +37,7 @@ var testAlgo; * @param rgb Tells the color requested by user in the UI. * @return A two-dimensional array[height][width]. */ - algo.rgbMap = function(width, height, rgb, step) + algo.rgbMap = function(width, height, rgb, step, rawColors) { var map = new Array(height); for (var y = 0; y < height; y++) diff --git a/resources/rgbscripts/plasmacolors.js b/resources/rgbscripts/plasmacolors.js index 168d7d4c5e..f9ac8e14d8 100644 --- a/resources/rgbscripts/plasmacolors.js +++ b/resources/rgbscripts/plasmacolors.js @@ -70,7 +70,7 @@ function() colorPalette.names = colorPalette.makeSubArray(0); var algo = new Object; - algo.apiVersion = 2; + algo.apiVersion = 3; algo.name = "Plasma (Colors)"; algo.author = "Nathan Durnan"; algo.acceptColors = 0; @@ -312,7 +312,7 @@ function() grad(p[BB+1], x-1, y-1, z-1 ))))); }; - algo.rgbMap = function(width, height, rgb, step) + algo.rgbMap = function(width, height, rgb, step, rawColors) { if (util.initialized === false) { util.initialize(); From a360e260739281d3eb16b5dab4413e56ceb1df22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Thu, 6 Apr 2023 21:15:57 +0200 Subject: [PATCH 04/63] Update the scripts to follow the stage colors. --- engine/src/rgbscript.cpp | 9 ++- engine/src/rgbscriptv4.cpp | 7 +- engine/test/rgbscript/rgbscript_test.cpp | 4 +- resources/rgbscripts/ballscolors.js | 53 ++++++--------- resources/rgbscripts/plasmacolors.js | 87 ++++++++++-------------- 5 files changed, 65 insertions(+), 95 deletions(-) diff --git a/engine/src/rgbscript.cpp b/engine/src/rgbscript.cpp index bb611aebc8..f9ce9ef16a 100644 --- a/engine/src/rgbscript.cpp +++ b/engine/src/rgbscript.cpp @@ -240,12 +240,11 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint QScriptValueList args; if (m_apiVersion <= 2) { - args << size.width() << size.height() << rgb << step; + args << size.width() << size.height() << rgb << step; } else { - QScriptValue jsRawColors = s_engine->newArray(RGBAlgorithmRawColorCount); - Q_ASSERT(2 == RGBAlgorithmRawColorCount); - jsRawColors.setProperty(0, QScriptValue(s_engine, rawColors[0])); - jsRawColors.setProperty(1, QScriptValue(s_engine, rawColors[1])); + Q_ASSERT(2 == RGBAlgorithmRawColorCount); + QScriptValueList jsRawColors; + jsRawColors << rawColors[0] << rawColors[1]; args << size.width() << size.height() << rgb << step << jsRawColors; } diff --git a/engine/src/rgbscriptv4.cpp b/engine/src/rgbscriptv4.cpp index e5253596cd..7f6008482a 100644 --- a/engine/src/rgbscriptv4.cpp +++ b/engine/src/rgbscriptv4.cpp @@ -228,10 +228,9 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint if (m_apiVersion <= 2) { args << size.width() << size.height() << rgb << step; } else { - QVariantList jsRawColors = s_engine->newArray(RGBAlgorithmRawColorCount); - Q_ASSERT(2 == RGBAlgorithmRawColorCount); - jsRawColors.setProperty(0, QJSValue(rawColors[0])); - jsRawColors.setProperty(1, QJSValue(rawColors[1])); + Q_ASSERT(2 == RGBAlgorithmRawColorCount); + QJSValueList jsRawColors; + jsRawColors << rawColors[0] << rawColors[1]; args << size.width() << size.height() << rgb << step << jsRawColors; } diff --git a/engine/test/rgbscript/rgbscript_test.cpp b/engine/test/rgbscript/rgbscript_test.cpp index 19805acca0..be1e47e10e 100644 --- a/engine/test/rgbscript/rgbscript_test.cpp +++ b/engine/test/rgbscript/rgbscript_test.cpp @@ -339,8 +339,8 @@ void RGBScript_Test::runScripts() { if (s.acceptColors() > 0) { - // If colors are accepted, verify that the requested color is applied - QVERIFY((rgbMap[y][x] & 0xff00ffff) == 0); + // verify that the alpha channel is zero + QVERIFY((rgbMap[y][x] & 0xff000000) == 0); QVERIFY((rgbMap[y][x] >> 16) <= 0x0000ff); if (!randomScript && 0 == step && 1 < s.acceptColors() && 2 < steps) { diff --git a/resources/rgbscripts/ballscolors.js b/resources/rgbscripts/ballscolors.js index b75d446b89..4f50ead61f 100644 --- a/resources/rgbscripts/ballscolors.js +++ b/resources/rgbscripts/ballscolors.js @@ -70,7 +70,7 @@ var testAlgo; algo.apiVersion = 3; algo.name = "Balls (Colors)"; algo.author = "Rob Nieuwenhuizen"; - algo.acceptColors = 0; + algo.acceptColors = 2; algo.properties = new Array(); algo.presetSize = 1; algo.properties.push("name:presetSize|type:range|display:Size|values:1,20|write:setSize|read:getSize"); @@ -78,16 +78,8 @@ var testAlgo; algo.properties.push("name:presetNumber|type:range|display:Number|values:1,5|write:setNumber|read:getNumber"); algo.presetCollision = 0; algo.properties.push("name:presetCollision|type:list|display:Self Collision|values:No,Yes|write:setCollision|read:getCollision"); - algo.color1Index = 0; - algo.properties.push( - "name:color1Index|type:list|display:Color 1|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor1|read:getColor1"); - algo.color2Index = 6; - algo.properties.push( - "name:color2Index|type:list|display:Color 2|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor2|read:getColor2"); + algo.color1Rgb = 0xff0000; + algo.color2Rgb = 0x00ff00; algo.color3Index = 16; algo.properties.push( "name:color3Index|type:list|display:Color 3|" + @@ -106,8 +98,6 @@ var testAlgo; algo.presetSize = 5; algo.colorIndex = new Array( - algo.color1Index, - algo.color2Index, algo.color3Index, algo.color4Index, algo.color5Index); @@ -143,11 +133,11 @@ var testAlgo; if (i === -1) { i = (colorPalette.collection.length - 1); } - algo.colorIndex[_index] = i; - return algo.colorIndex[_index]; + algo.colorIndex[_index - algo.acceptColors] = i; + return algo.colorIndex[_index - algo.acceptColors]; }; algo.getColor = function (_index) { - var i = algo.colorIndex[_index]; + var i = algo.colorIndex[_index- algo.acceptColors]; if (i < 0) { i = 0; } if (i >= colorPalette.collection.length) { i = (colorPalette.collection.length - 1); @@ -155,21 +145,13 @@ var testAlgo; return colorPalette.collection[i][0]; }; - algo.setColor1 = function (_preset) { - algo.color1Index = algo.setColor(0, _preset); - algo.initialized = false; - }; - algo.getColor1 = function () { - return algo.getColor(0); - }; - - algo.setColor2 = function (_preset) { - algo.color2Index = algo.setColor(1, _preset); - algo.initialized = false; - }; - algo.getColor2 = function () { - return algo.getColor(1); - }; + algo.getRawColor = function (rawColors, idx) { + if (Array.isArray(rawColors) && ! Number.isNaN(rawColors[idx])) { + return rawColors[idx]; + } else { + return 0; + } + } algo.setColor3 = function (_preset) { algo.color3Index = algo.setColor(2, _preset); @@ -207,7 +189,10 @@ var testAlgo; var yDirection = (Math.random() * 2) - 1; // and random directions var xDirection = (Math.random() * 2) - 1; algo.direction[i] = [yDirection, xDirection]; - algo.colour[i] = colorPalette.collection[algo.colorIndex[i]][1]; + } + // Get the colors from the external preset. + for (var i = algo.acceptColors; i < algo.presetNumber; i++) { + algo.colour[i] = colorPalette.collection[algo.colorIndex[i - algo.acceptColors]][1]; } algo.initialized = true; return; @@ -217,6 +202,10 @@ var testAlgo; if (algo.initialized === false) { util.initialize(width, height); } + for (var i = 0; i < algo.acceptColors; i++) { + algo.colour[i] = algo.getRawColor(rawColors, i); + } + var map = new Array(height); // Clear map data for (var y = 0; y < height; y++) { map[y] = new Array(); diff --git a/resources/rgbscripts/plasmacolors.js b/resources/rgbscripts/plasmacolors.js index f9ac8e14d8..04bc39423f 100644 --- a/resources/rgbscripts/plasmacolors.js +++ b/resources/rgbscripts/plasmacolors.js @@ -73,21 +73,11 @@ function() algo.apiVersion = 3; algo.name = "Plasma (Colors)"; algo.author = "Nathan Durnan"; - algo.acceptColors = 0; + algo.acceptColors = 2; algo.properties = new Array(); algo.rstepcount = 0; algo.gstepcount = 50; algo.bstepcount = 100; - algo.color1Index = 0; - algo.properties.push( - "name:color1Index|type:list|display:Color 1|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor1|read:getColor1"); - algo.color2Index = 6; - algo.properties.push( - "name:color2Index|type:list|display:Color 2|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor2|read:getColor2"); algo.color3Index = 16; algo.properties.push( "name:color3Index|type:list|display:Color 3|" + @@ -116,8 +106,6 @@ function() "name:stepsize|type:range|display:Speed|" + "values:1,50|write:setStep|read:getStep"); algo.colorIndex = new Array( - algo.color1Index, - algo.color2Index, algo.color3Index, algo.color4Index, algo.color5Index); @@ -126,6 +114,7 @@ function() util.initialized = false; util.gradientData = new Array(); util.colorArray = new Array(); + util.colorCache = new Array(); algo.setColor = function(_index, _preset) { @@ -133,13 +122,13 @@ function() if (i === -1) { i = (colorPalette.collection.length - 1); } - algo.colorIndex[_index] = i; - return algo.colorIndex[_index]; + algo.colorIndex[_index - algo.acceptColors] = i; + return algo.colorIndex[_index - algo.acceptColors]; }; algo.getColor = function(_index) { - var i = algo.colorIndex[_index]; + var i = algo.colorIndex[_index - algo.acceptColors]; if (i < 0) { i = 0; } if (i >= colorPalette.collection.length) { i = (colorPalette.collection.length - 1); @@ -147,30 +136,18 @@ function() return colorPalette.collection[i][0]; }; - algo.setColor1 = function(_preset) - { - algo.color1Index = algo.setColor(0, _preset); - util.initialize(); - }; - algo.getColor1 = function() - { - return algo.getColor(0); - }; - - algo.setColor2 = function(_preset) - { - algo.color2Index = algo.setColor(1, _preset); - util.initialize(); - }; - algo.getColor2 = function() - { - return algo.getColor(1); - }; + algo.getRawColor = function (rawColors, idx) { + if (Array.isArray(rawColors) && ! Number.isNaN(rawColors[idx])) { + return rawColors[idx]; + } else { + return 0; + } + } algo.setColor3 = function(_preset) { algo.color3Index = algo.setColor(2, _preset); - util.initialize(); + util.initialized = false; }; algo.getColor3 = function() { @@ -180,7 +157,7 @@ function() algo.setColor4 = function(_preset) { algo.color4Index = algo.setColor(3, _preset); - util.initialize(); + util.initialized = false; }; algo.getColor4 = function() { @@ -190,7 +167,7 @@ function() algo.setColor5 = function(_preset) { algo.color5Index = algo.setColor(4, _preset); - util.initialize(); + util.initialized = false; }; algo.getColor5 = function() { @@ -200,7 +177,7 @@ function() algo.setSize = function(_size) { algo.presetSize = _size; - util.initialize(); + util.initialized = false; }; algo.getSize = function() { @@ -210,7 +187,7 @@ function() algo.setRamp = function(_ramp) { algo.ramp = _ramp; - util.initialize(); + util.initialized = false; }; algo.getRamp = function() { @@ -220,24 +197,26 @@ function() algo.setStep = function(_step) { algo.stepsize = _step; - util.initialize(); + util.initialized = false; }; algo.getStep = function() { return algo.stepsize; }; - util.initialize = function() + util.initialize = function(rawColors) { + // Get the colors from the external preset. + for (var i = 0; i < algo.acceptColors; i++) { + util.colorArray[i] = algo.getRawColor(rawColors, i); + } + for (var i = 0; i < algo.colorIndex.length; i++) { + util.colorArray[i + algo.acceptColors] = colorPalette.collection[algo.colorIndex[i]][1]; + } // calculate the gradient for the selected preset // with the given width var gradIdx = 0; util.gradientData = new Array(); - util.colorArray = new Array(); - for (var j = 0; j < algo.colorIndex.length; j++) - { - util.colorArray[j] = colorPalette.collection[algo.colorIndex[j]][1]; - } for (var i = 0; i < util.colorArray.length; i++) { var sColor = util.colorArray[i]; @@ -314,9 +293,16 @@ function() algo.rgbMap = function(width, height, rgb, step, rawColors) { + for (var i = 0; i < algo.acceptColors; i++) { + if (typeof util.colorCache[i] === 'undefined' || util.colorCache[i] !== rawColors[i]) { + util.colorCache[i] = algo.getRawColor(rawColors, i); + util.initialized = false; + } + } if (util.initialized === false) { - util.initialize(); + util.initialize(rawColors); } + var size = algo.presetSize/2; // set a scaling value var speed = Math.pow(100 , (algo.stepsize / 50)); // create a more uniform speed control algo.bstepcount += (speed / 500); @@ -343,10 +329,7 @@ function() algo.rgbMapStepCount = function(width, height) { - if (util.initialized === false) { - util.initialize(); - } - return width * height; // This make no difference to the script ;-) + return 2; // This make no difference to the script ;-) }; // Development tool access From b87b7cbbbd707c810807903f15e4a7b2a32395d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Thu, 6 Apr 2023 21:40:35 +0200 Subject: [PATCH 05/63] Convert startColor and endColor into an array to prepare potential extension for e.g. 5 colors as used in color scripts --- engine/src/rgbalgorithm.cpp | 12 ++-- engine/src/rgbalgorithm.h | 10 +-- engine/src/rgbaudio.cpp | 4 +- engine/src/rgbaudio.h | 2 +- engine/src/rgbmatrix.cpp | 72 +++++++++----------- engine/src/rgbmatrix.h | 11 ++-- engine/src/rgbplain.cpp | 4 +- engine/src/rgbplain.h | 2 +- engine/test/rgbmatrix/rgbmatrix_test.cpp | 36 +++++----- qmlui/rgbmatrixeditor.cpp | 42 ++++++------ qmlui/tardis/tardis.cpp | 8 +-- ui/src/rgbmatrixeditor.cpp | 83 +++++++++++++----------- ui/src/virtualconsole/vcmatrix.cpp | 22 +++---- 13 files changed, 156 insertions(+), 152 deletions(-) diff --git a/engine/src/rgbalgorithm.cpp b/engine/src/rgbalgorithm.cpp index 7daae49dcb..db02828043 100644 --- a/engine/src/rgbalgorithm.cpp +++ b/engine/src/rgbalgorithm.cpp @@ -39,15 +39,17 @@ RGBAlgorithm::RGBAlgorithm(Doc * doc) : m_doc(doc) - , m_startColor(QColor()) - , m_endColor(QColor()) + , m_colors{ + QColor(), // was m_startColor + QColor() // was m_endColor + } { } -void RGBAlgorithm::setColors(QColor start, QColor end) +void RGBAlgorithm::setColors(QColor colors[RGBMATRIX_MAXCOLORS]) { - m_startColor = start; - m_endColor = end; + for (unsigned int i = 0; i < RGBMATRIX_MAXCOLORS; i++) + m_colors[i] = colors[i]; } /**************************************************************************** diff --git a/engine/src/rgbalgorithm.h b/engine/src/rgbalgorithm.h index 8679c7af14..b9efce543a 100644 --- a/engine/src/rgbalgorithm.h +++ b/engine/src/rgbalgorithm.h @@ -26,6 +26,8 @@ #include #include +#define RGBMATRIX_MAXCOLORS 2 + class QXmlStreamReader; class QXmlStreamWriter; @@ -105,14 +107,14 @@ class RGBAlgorithm ************************************************************************/ public: /** Set the start/end color the algorithm can use */ - virtual void setColors(QColor start, QColor end); + virtual void setColors(QColor[RGBMATRIX_MAXCOLORS]); - QColor startColor() { return m_startColor; } + QColor startColor() { return m_colors[0]; } - QColor endColor() { return m_endColor; } + QColor endColor() { return m_colors[1]; } private: - QColor m_startColor, m_endColor; + QColor m_colors[RGBMATRIX_MAXCOLORS]; /************************************************************************ * Available algorithms diff --git a/engine/src/rgbaudio.cpp b/engine/src/rgbaudio.cpp index f38b18016d..494621610e 100644 --- a/engine/src/rgbaudio.cpp +++ b/engine/src/rgbaudio.cpp @@ -204,9 +204,9 @@ int RGBAudio::apiVersion() const return 1; } -void RGBAudio::setColors(QColor start, QColor end) +void RGBAudio::setColors(QColor colors[RGBMATRIX_MAXCOLORS]) { - RGBAlgorithm::setColors(start, end); + RGBAlgorithm::setColors(colors); // invalidate bars colors so the next time a rendering is // required, it will be filled with the right values diff --git a/engine/src/rgbaudio.h b/engine/src/rgbaudio.h index 8fee1c5046..2270d62e12 100644 --- a/engine/src/rgbaudio.h +++ b/engine/src/rgbaudio.h @@ -86,7 +86,7 @@ protected slots: int apiVersion() const; /** @reimp */ - void setColors(QColor start, QColor end); + void setColors(QColor colors[RGBMATRIX_MAXCOLORS]); /** @reimp */ RGBAlgorithm::Type type() const; diff --git a/engine/src/rgbmatrix.cpp b/engine/src/rgbmatrix.cpp index 1fc52bd852..b20779cfe1 100644 --- a/engine/src/rgbmatrix.cpp +++ b/engine/src/rgbmatrix.cpp @@ -66,8 +66,10 @@ RGBMatrix::RGBMatrix(Doc* doc) #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) , m_algorithmMutex(QMutex::Recursive) #endif - , m_startColor(Qt::red) - , m_endColor(QColor()) + , m_rgbColors{ + Qt::red, // was m_startColor + QColor() // was m_endColor + } , m_stepHandler(new RGBMatrixStep()) , m_roundTime(new QElapsedTimer()) , m_stepsCount(0) @@ -168,8 +170,9 @@ bool RGBMatrix::copyFrom(const Function* function) setAlgorithm(mtx->algorithm()->clone()); else setAlgorithm(NULL); - setStartColor(mtx->startColor()); - setEndColor(mtx->endColor()); + + for(unsigned int i = 0; i < RGBMATRIX_MAXCOLORS; i++) + setColor(i, mtx->getColor(i)); return Function::copyFrom(function); } @@ -279,8 +282,8 @@ void RGBMatrix::previewMap(int step, RGBMatrixStep *handler) if (m_group != NULL) { uint rawColors[] = { - m_startColor.rgb(), - m_endColor.isValid() ? m_endColor.rgb() : 0}; + m_rgbColors[0].rgb(), + m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0}; m_algorithm->rgbMap(m_group->size(), handler->stepColor().rgb(), step, handler->m_map, rawColors); } } @@ -289,47 +292,30 @@ void RGBMatrix::previewMap(int step, RGBMatrixStep *handler) * Color ****************************************************************************/ -void RGBMatrix::setStartColor(const QColor& c) +void RGBMatrix::setColor(unsigned int i, QColor c) { - m_startColor = c; + if (i >= RGBMATRIX_MAXCOLORS) + return; + m_rgbColors[i] = c; { QMutexLocker algorithmLocker(&m_algorithmMutex); if (m_algorithm != NULL) { - m_algorithm->setColors(m_startColor, m_endColor); + m_algorithm->setColors(&m_rgbColors[0]); updateColorDelta(); } } emit changed(id()); } -QColor RGBMatrix::startColor() const +QColor RGBMatrix::getColor(unsigned int i) const { - return m_startColor; -} - -void RGBMatrix::setEndColor(const QColor &c) -{ - m_endColor = c; - { - QMutexLocker algorithmLocker(&m_algorithmMutex); - if (m_algorithm != NULL) - { - m_algorithm->setColors(m_startColor, m_endColor); - updateColorDelta(); - } - } - emit changed(id()); -} - -QColor RGBMatrix::endColor() const -{ - return m_endColor; + return m_rgbColors[i]; } void RGBMatrix::updateColorDelta() { - m_stepHandler->calculateColorDelta(m_startColor, m_endColor); + m_stepHandler->calculateColorDelta(m_rgbColors[0], m_rgbColors[1]); } /************************************************************************ @@ -407,13 +393,16 @@ bool RGBMatrix::loadXML(QXmlStreamReader &root) { loadXMLRunOrder(root); } +#if (2 != RGBMATRIX_MAXCOLORS) +#error "Further colors need to be read." +#endif else if (root.name() == KXMLQLCRGBMatrixStartColor) { - setStartColor(QColor::fromRgb(QRgb(root.readElementText().toUInt()))); + setColor(0, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); } else if (root.name() == KXMLQLCRGBMatrixEndColor) { - setEndColor(QColor::fromRgb(QRgb(root.readElementText().toUInt()))); + setColor(1, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); } else if (root.name() == KXMLQLCRGBMatrixControlMode) { @@ -468,11 +457,14 @@ bool RGBMatrix::saveXML(QXmlStreamWriter *doc) doc->writeTextElement(KXMLQLCRGBMatrixDimmerControl, QString::number(dimmerControl())); /* Start Color */ - doc->writeTextElement(KXMLQLCRGBMatrixStartColor, QString::number(startColor().rgb())); + doc->writeTextElement(KXMLQLCRGBMatrixStartColor, QString::number(getColor(0).rgb())); /* End Color */ - if (endColor().isValid()) - doc->writeTextElement(KXMLQLCRGBMatrixEndColor, QString::number(endColor().rgb())); + if (getColor(1).isValid()) + doc->writeTextElement(KXMLQLCRGBMatrixEndColor, QString::number(getColor(1).rgb())); +#if (2 != RGBMATRIX_MAXCOLORS) +#error "Further colors need to be written." +#endif /* Control Mode */ doc->writeTextElement(KXMLQLCRGBMatrixControlMode, RGBMatrix::controlModeToString(m_controlMode)); @@ -531,7 +523,7 @@ void RGBMatrix::preRun(MasterTimer *timer) if (m_algorithm != NULL) { // Copy direction from parent class direction - m_stepHandler->initializeDirection(direction(), m_startColor, m_endColor, m_stepsCount); + m_stepHandler->initializeDirection(direction(), m_rgbColors[0], m_rgbColors[1], m_stepsCount); if (m_algorithm->type() == RGBAlgorithm::Script) { @@ -581,8 +573,8 @@ void RGBMatrix::write(MasterTimer *timer, QList universes) m_stepBeatDuration = beatsToTime(duration(), timer->beatTimeDuration()); uint rawColors[] = { - m_startColor.rgb(), - m_endColor.isValid() ? m_endColor.rgb() : 0}; + m_rgbColors[0].rgb(), + m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0}; //qDebug() << "RGBMatrix step" << m_stepHandler->currentStepIndex() << ", color:" << QString::number(m_stepHandler->stepColor().rgb(), 16); m_algorithm->rgbMap(m_group->size(), m_stepHandler->stepColor().rgb(), m_stepHandler->currentStepIndex(), m_stepHandler->m_map, rawColors); @@ -672,7 +664,7 @@ void RGBMatrix::roundCheck() if (m_algorithm == NULL) return; - if (m_stepHandler->checkNextStep(runOrder(), m_startColor, m_endColor, m_stepsCount) == false) + if (m_stepHandler->checkNextStep(runOrder(), m_rgbColors[0], m_rgbColors[1], m_stepsCount) == false) stop(FunctionParent::master()); m_roundTime->restart(); diff --git a/engine/src/rgbmatrix.h b/engine/src/rgbmatrix.h index 8f607d9ba0..8fda62f838 100644 --- a/engine/src/rgbmatrix.h +++ b/engine/src/rgbmatrix.h @@ -188,17 +188,16 @@ class RGBMatrix : public Function * Color ************************************************************************/ public: - void setStartColor(const QColor& c); - QColor startColor() const; + void setColor(unsigned int i, QColor c); + QColor getColor(unsigned int i) const; - void setEndColor(const QColor& c); - QColor endColor() const; + void setRgbColor(const unsigned int i, const QColor& c); + QColor rgbColor(const unsigned int i) const; void updateColorDelta(); private: - QColor m_startColor; - QColor m_endColor; + QColor m_rgbColors[RGBMATRIX_MAXCOLORS]; RGBMatrixStep *m_stepHandler; /************************************************************************ diff --git a/engine/src/rgbplain.cpp b/engine/src/rgbplain.cpp index 00404f6a0e..a560af29dc 100644 --- a/engine/src/rgbplain.cpp +++ b/engine/src/rgbplain.cpp @@ -83,9 +83,9 @@ int RGBPlain::apiVersion() const return 1; } -void RGBPlain::setColors(QColor start, QColor end) +void RGBPlain::setColors(QColor colors[RGBMATRIX_MAXCOLORS]) { - RGBAlgorithm::setColors(start, end); + RGBAlgorithm::setColors(colors); } RGBAlgorithm::Type RGBPlain::type() const diff --git a/engine/src/rgbplain.h b/engine/src/rgbplain.h index 5748741235..0280d56c94 100644 --- a/engine/src/rgbplain.h +++ b/engine/src/rgbplain.h @@ -62,7 +62,7 @@ class RGBPlain : public QObject, public RGBAlgorithm int apiVersion() const; /** @reimp */ - void setColors(QColor start, QColor end); + void setColors(QColor colors[RGBMATRIX_MAXCOLORS]); /** @reimp */ RGBAlgorithm::Type type() const; diff --git a/engine/test/rgbmatrix/rgbmatrix_test.cpp b/engine/test/rgbmatrix/rgbmatrix_test.cpp index 88b165a78a..ba3a41b8f5 100644 --- a/engine/test/rgbmatrix/rgbmatrix_test.cpp +++ b/engine/test/rgbmatrix/rgbmatrix_test.cpp @@ -82,8 +82,8 @@ void RGBMatrix_Test::initial() RGBMatrix mtx(m_doc); QCOMPARE(mtx.type(), Function::RGBMatrixType); QCOMPARE(mtx.fixtureGroup(), FixtureGroup::invalidId()); - QCOMPARE(mtx.startColor(), QColor(Qt::red)); - QCOMPARE(mtx.endColor(), QColor()); + QCOMPARE(mtx.getColor(0), QColor(Qt::red)); + QCOMPARE(mtx.getColor(1), QColor()); QCOMPARE(mtx.m_fadersMap.count(), 0); QCOMPARE(mtx.m_stepHandler->currentStepIndex(), 0); QCOMPARE(mtx.name(), tr("New RGB Matrix")); @@ -110,32 +110,32 @@ void RGBMatrix_Test::group() void RGBMatrix_Test::color() { RGBMatrix mtx(m_doc); - mtx.setStartColor(Qt::blue); - QCOMPARE(mtx.startColor(), QColor(Qt::blue)); + mtx.setColor(0, Qt::blue); + QCOMPARE(mtx.getColor(0), QColor(Qt::blue)); - mtx.setStartColor(QColor()); - QCOMPARE(mtx.startColor(), QColor()); + mtx.setColor(0, QColor()); + QCOMPARE(mtx.getColor(0), QColor()); - mtx.setEndColor(Qt::green); - QCOMPARE(mtx.endColor(), QColor(Qt::green)); + mtx.setColor(1, Qt::green); + QCOMPARE(mtx.getColor(1), QColor(Qt::green)); - mtx.setEndColor(QColor()); - QCOMPARE(mtx.endColor(), QColor()); + mtx.setColor(1, QColor()); + QCOMPARE(mtx.getColor(1), QColor()); } void RGBMatrix_Test::copy() { RGBMatrix mtx(m_doc); - mtx.setStartColor(Qt::magenta); - mtx.setEndColor(Qt::yellow); + mtx.setColor(0, Qt::magenta); + mtx.setColor(1, Qt::yellow); mtx.setFixtureGroup(0); mtx.setAlgorithm(RGBAlgorithm::algorithm(m_doc, "Stripes")); QVERIFY(mtx.algorithm() != NULL); RGBMatrix* copyMtx = qobject_cast (mtx.createCopy(m_doc)); QVERIFY(copyMtx != NULL); - QCOMPARE(copyMtx->startColor(), QColor(Qt::magenta)); - QCOMPARE(copyMtx->endColor(), QColor(Qt::yellow)); + QCOMPARE(copyMtx->getColor(0), QColor(Qt::magenta)); + QCOMPARE(copyMtx->getColor(1), QColor(Qt::yellow)); QCOMPARE(copyMtx->fixtureGroup(), uint(0)); QVERIFY(copyMtx->algorithm() != NULL); QVERIFY(copyMtx->algorithm() != mtx.algorithm()); // Different object pointer! @@ -203,8 +203,8 @@ void RGBMatrix_Test::property() void RGBMatrix_Test::loadSave() { RGBMatrix* mtx = new RGBMatrix(m_doc); - mtx->setStartColor(Qt::magenta); - mtx->setEndColor(Qt::blue); + mtx->setColor(0, Qt::magenta); + mtx->setColor(1, Qt::blue); mtx->setControlMode(RGBMatrix::ControlModeRgb); mtx->setFixtureGroup(42); mtx->setAlgorithm(RGBAlgorithm::algorithm(m_doc, "Stripes")); @@ -309,8 +309,8 @@ void RGBMatrix_Test::loadSave() QVERIFY(mtx2.loadXML(xmlReader) == true); QCOMPARE(mtx2.direction(), Function::Backward); QCOMPARE(mtx2.runOrder(), Function::PingPong); - QCOMPARE(mtx2.startColor(), QColor(Qt::magenta)); - QCOMPARE(mtx2.endColor(), QColor(Qt::blue)); + QCOMPARE(mtx2.getColor(0), QColor(Qt::magenta)); + QCOMPARE(mtx2.getColor(1), QColor(Qt::blue)); QCOMPARE(mtx2.controlMode(), RGBMatrix::ControlModeRgb); QCOMPARE(mtx2.fixtureGroup(), uint(42)); QVERIFY(mtx2.algorithm() != NULL); diff --git a/qmlui/rgbmatrixeditor.cpp b/qmlui/rgbmatrixeditor.cpp index 6865f19678..fa5f4684af 100644 --- a/qmlui/rgbmatrixeditor.cpp +++ b/qmlui/rgbmatrixeditor.cpp @@ -134,7 +134,11 @@ void RGBMatrixEditor::setAlgorithmIndex(int algoIndex) /** if we're setting the same algorithm, then there's nothing to do */ if (m_matrix->algorithm() != nullptr && m_matrix->algorithm()->name() == algo->name()) return; - algo->setColors(m_matrix->startColor(), m_matrix->endColor()); + QColor colors[RGBMATRIX_MAXCOLORS] = { + m_matrix->getColor(0), + m_matrix->getColor(1) + }; + algo->setColors(colors); } Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetAlgorithmIndex, m_matrix->id(), algorithmIndex(), algoIndex); @@ -159,17 +163,17 @@ QColor RGBMatrixEditor::startColor() const if (m_matrix == nullptr) return Qt::red; - return m_matrix->startColor(); + return m_matrix->getColor(0); } void RGBMatrixEditor::setStartColor(QColor algoStartColor) { - if (m_matrix == nullptr || m_matrix->startColor() == algoStartColor) + if (m_matrix == nullptr || m_matrix->getColor(0) == algoStartColor) return; - Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetStartColor, m_matrix->id(), m_matrix->startColor(), algoStartColor); - m_matrix->setStartColor(algoStartColor); - m_previewStepHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor()); + Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetStartColor, m_matrix->id(), m_matrix->getColor(0), algoStartColor); + m_matrix->setColor(0, algoStartColor); + m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); emit startColorChanged(algoStartColor); } @@ -179,17 +183,17 @@ QColor RGBMatrixEditor::endColor() const if (m_matrix == nullptr) return QColor(); - return m_matrix->endColor(); + return m_matrix->getColor(1); } void RGBMatrixEditor::setEndColor(QColor algoEndColor) { - if (m_matrix == nullptr || m_matrix->endColor() == algoEndColor) + if (m_matrix == nullptr || m_matrix->getColor(1) == algoEndColor) return; - Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetEndColor, m_matrix->id(), m_matrix->endColor(), algoEndColor); - m_matrix->setEndColor(algoEndColor); - m_previewStepHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor()); + Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetEndColor, m_matrix->id(), m_matrix->getColor(1), algoEndColor); + m_matrix->setColor(1, algoEndColor); + m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); emit endColorChanged(algoEndColor); if (algoEndColor.isValid()) @@ -198,7 +202,7 @@ void RGBMatrixEditor::setEndColor(QColor algoEndColor) bool RGBMatrixEditor::hasEndColor() const { - if (m_matrix == nullptr || m_matrix->endColor().isValid() == false) + if (m_matrix == nullptr || m_matrix->getColor(1).isValid() == false) return false; return true; @@ -208,8 +212,8 @@ void RGBMatrixEditor::setHasEndColor(bool hasEndCol) { if (m_matrix && hasEndCol == false) { - m_matrix->setEndColor(QColor()); - m_previewStepHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor()); + m_matrix->setColor(1, QColor()); + m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); } emit hasEndColorChanged(hasEndCol); } @@ -567,8 +571,8 @@ void RGBMatrixEditor::slotPreviewTimeout() { QMutexLocker locker(&m_previewMutex); - m_previewStepHandler->checkNextStep(m_matrix->runOrder(), m_matrix->startColor(), - m_matrix->endColor(), m_matrix->stepsCount()); + m_previewStepHandler->checkNextStep(m_matrix->runOrder(), m_matrix->getColor(0), + m_matrix->getColor(1), m_matrix->stepsCount()); m_matrix->previewMap(m_previewStepHandler->currentStepIndex(), m_previewStepHandler); @@ -632,9 +636,9 @@ void RGBMatrixEditor::initPreviewData() if (m_matrix == nullptr) return; - m_previewStepHandler->initializeDirection(m_matrix->direction(), m_matrix->startColor(), - m_matrix->endColor(), m_matrix->stepsCount()); - m_previewStepHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor()); + m_previewStepHandler->initializeDirection(m_matrix->direction(), m_matrix->getColor(0), + m_matrix->getColor(1), m_matrix->stepsCount()); + m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); m_previewTimer->start(MasterTimer::tick()); } diff --git a/qmlui/tardis/tardis.cpp b/qmlui/tardis/tardis.cpp index 4baa25b732..4ff2212658 100644 --- a/qmlui/tardis/tardis.cpp +++ b/qmlui/tardis/tardis.cpp @@ -835,14 +835,14 @@ int Tardis::processAction(TardisAction &action, bool undo) break; case RGBMatrixSetStartColor: { - auto member = std::mem_fn(&RGBMatrix::setStartColor); - member(qobject_cast(m_doc->function(action.m_objID)), value->value()); + auto member = std::mem_fn(&RGBMatrix::setColor); + member(qobject_cast(m_doc->function(action.m_objID)), 0, value->value()); } break; case RGBMatrixSetEndColor: { - auto member = std::mem_fn(&RGBMatrix::setEndColor); - member(qobject_cast(m_doc->function(action.m_objID)), value->value()); + auto member = std::mem_fn(&RGBMatrix::setColor); + member(qobject_cast(m_doc->function(action.m_objID)), 1, value->value()); } break; case RGBMatrixSetScriptIntValue: diff --git a/ui/src/rgbmatrixeditor.cpp b/ui/src/rgbmatrixeditor.cpp index 09e8401ded..f1517d745d 100644 --- a/ui/src/rgbmatrixeditor.cpp +++ b/ui/src/rgbmatrixeditor.cpp @@ -174,11 +174,11 @@ void RGBMatrixEditor::init() fillImageAnimationCombo(); QPixmap pm(50, 26); - pm.fill(m_matrix->startColor()); + pm.fill(m_matrix->getColor(0)); m_startColorButton->setIcon(QIcon(pm)); - if (m_matrix->endColor().isValid()) - pm.fill(m_matrix->endColor()); + if (m_matrix->getColor(1).isValid()) + pm.fill(m_matrix->getColor(1)); else pm.fill(Qt::transparent); m_endColorButton->setIcon(QIcon(pm)); @@ -405,10 +405,10 @@ void RGBMatrixEditor::updateColors() { if (m_matrix->blendMode() == Universe::MaskBlend) { - m_matrix->setStartColor(Qt::white); - m_matrix->setEndColor(QColor()); + m_matrix->setColor(0, Qt::white); + m_matrix->setColor(1, QColor()); - m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor()); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); QPixmap pm(50, 26); pm.fill(Qt::white); @@ -417,41 +417,41 @@ void RGBMatrixEditor::updateColors() else if (m_controlModeCombo->currentIndex() != RGBMatrix::ControlModeRgb) { // Convert startColor to grayscale for single color modes - uchar gray = qGray(m_matrix->startColor().rgb()); + uchar gray = qGray(m_matrix->getColor(0).rgb()); QPixmap pm(50, 26); pm.fill(QColor(gray, gray, gray)); m_startColorButton->setIcon(QIcon(pm)); - m_matrix->setStartColor(QColor(gray, gray, gray)); + m_matrix->setColor(0, QColor(gray, gray, gray)); if (accColors > 1) { // Convert endColor to grayscale for single color modes - gray = qGray(m_matrix->endColor().rgb()); - m_matrix->setEndColor(QColor(gray, gray, gray)); + gray = qGray(m_matrix->getColor(1).rgb()); + m_matrix->setColor(1, QColor(gray, gray, gray)); - if (m_matrix->endColor() == QColor()) + if (m_matrix->getColor(1) == QColor()) pm.fill(Qt::transparent); else pm.fill(QColor(gray, gray, gray)); m_endColorButton->setIcon(QIcon(pm)); } - m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor()); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); } else { QPixmap pm(50, 26); - pm.fill(m_matrix->startColor()); + pm.fill(m_matrix->getColor(0)); m_startColorButton->setIcon(QIcon(pm)); if (accColors > 1) { - m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor()); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); - if (m_matrix->endColor() == QColor()) + if (m_matrix->getColor(1) == QColor()) pm.fill(Qt::transparent); else - pm.fill(m_matrix->endColor()); + pm.fill(m_matrix->getColor(1)); m_endColorButton->setIcon(QIcon(pm)); } @@ -564,8 +564,8 @@ bool RGBMatrixEditor::createPreviewItems() return false; } - m_previewHandler->initializeDirection(m_matrix->direction(), m_matrix->startColor(), - m_matrix->endColor(), m_matrix->stepsCount()); + m_previewHandler->initializeDirection(m_matrix->direction(), m_matrix->getColor(0), + m_matrix->getColor(1), m_matrix->stepsCount()); m_matrix->previewMap(m_previewHandler->currentStepIndex(), m_previewHandler); @@ -621,8 +621,8 @@ void RGBMatrixEditor::slotPreviewTimeout() uint elapsed = 0; while (m_previewIterator >= MAX(m_matrix->duration(), MasterTimer::tick())) { - m_previewHandler->checkNextStep(m_matrix->runOrder(), m_matrix->startColor(), - m_matrix->endColor(), m_matrix->stepsCount()); + m_previewHandler->checkNextStep(m_matrix->runOrder(), m_matrix->getColor(0), + m_matrix->getColor(1), m_matrix->stepsCount()); m_matrix->previewMap(m_previewHandler->currentStepIndex(), m_previewHandler); @@ -676,10 +676,15 @@ void RGBMatrixEditor::slotDialDestroyed(QObject *) void RGBMatrixEditor::slotPatternActivated(const QString& text) { RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, text); - if (algo != NULL) - algo->setColors(m_matrix->startColor(), m_matrix->endColor()); + if (algo != NULL) { + QColor colors[RGBMATRIX_MAXCOLORS] = { + m_matrix->getColor(0), + m_matrix->getColor(1) + }; + algo->setColors(colors); + } m_matrix->setAlgorithm(algo); - m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor()); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); updateExtraOptions(); slotRestartTest(); @@ -728,10 +733,10 @@ void RGBMatrixEditor::slotControlModeChanged(int index) void RGBMatrixEditor::slotStartColorButtonClicked() { - QColor col = QColorDialog::getColor(m_matrix->startColor()); + QColor col = QColorDialog::getColor(m_matrix->getColor(0)); if (col.isValid() == true) { - m_matrix->setStartColor(col); + m_matrix->setColor(0, col); updateColors(); slotRestartTest(); } @@ -739,10 +744,10 @@ void RGBMatrixEditor::slotStartColorButtonClicked() void RGBMatrixEditor::slotEndColorButtonClicked() { - QColor col = QColorDialog::getColor(m_matrix->endColor()); + QColor col = QColorDialog::getColor(m_matrix->getColor(1)); if (col.isValid() == true) { - m_matrix->setEndColor(col); + m_matrix->setColor(1, col); updateColors(); slotRestartTest(); } @@ -750,8 +755,8 @@ void RGBMatrixEditor::slotEndColorButtonClicked() void RGBMatrixEditor::slotResetEndColorButtonClicked() { - m_matrix->setEndColor(QColor()); - m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor()); + m_matrix->setColor(1, QColor()); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); updateColors(); slotRestartTest(); } @@ -886,35 +891,35 @@ void RGBMatrixEditor::slotOffsetSpinChanged() void RGBMatrixEditor::slotLoopClicked() { m_matrix->setRunOrder(Function::Loop); - m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor()); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); slotRestartTest(); } void RGBMatrixEditor::slotPingPongClicked() { m_matrix->setRunOrder(Function::PingPong); - m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor()); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); slotRestartTest(); } void RGBMatrixEditor::slotSingleShotClicked() { m_matrix->setRunOrder(Function::SingleShot); - m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor()); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); slotRestartTest(); } void RGBMatrixEditor::slotForwardClicked() { m_matrix->setDirection(Function::Forward); - m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor()); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); slotRestartTest(); } void RGBMatrixEditor::slotBackwardClicked() { m_matrix->setDirection(Function::Backward); - m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor()); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); slotRestartTest(); } @@ -1099,16 +1104,16 @@ void RGBMatrixEditor::slotSaveToSequenceClicked() int totalSteps = m_matrix->stepsCount(); int increment = 1; int currentStep = 0; - m_previewHandler->setStepColor(m_matrix->startColor()); + m_previewHandler->setStepColor(m_matrix->getColor(0)); if (m_matrix->direction() == Function::Backward) { currentStep = totalSteps - 1; increment = -1; - if (m_matrix->endColor().isValid()) - m_previewHandler->setStepColor(m_matrix->endColor()); + if (m_matrix->getColor(1).isValid()) + m_previewHandler->setStepColor(m_matrix->getColor(1)); } - m_previewHandler->calculateColorDelta(m_matrix->startColor(), m_matrix->endColor()); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); if (m_matrix->runOrder() == RGBMatrix::PingPong) totalSteps = (totalSteps * 2) - 1; @@ -1215,7 +1220,7 @@ void RGBMatrixEditor::slotSaveToSequenceClicked() currentStep = totalSteps - 2; increment = -1; } - m_previewHandler->updateStepColor(currentStep, m_matrix->startColor(), m_matrix->stepsCount()); + m_previewHandler->updateStepColor(currentStep, m_matrix->getColor(0), m_matrix->stepsCount()); } m_doc->addFunction(sequence); diff --git a/ui/src/virtualconsole/vcmatrix.cpp b/ui/src/virtualconsole/vcmatrix.cpp index 2426464c3b..0ee9849ec7 100644 --- a/ui/src/virtualconsole/vcmatrix.cpp +++ b/ui/src/virtualconsole/vcmatrix.cpp @@ -280,7 +280,7 @@ void VCMatrix::slotStartColorChanged(QRgb color) if (matrix == NULL || mode() == Doc::Design) return; - matrix->setStartColor(col); + matrix->setColor(0, col); if (instantChanges() == true) matrix->updateColorDelta(); } @@ -296,7 +296,7 @@ void VCMatrix::slotEndColorChanged(QRgb color) if (matrix == NULL || mode() == Doc::Design) return; - matrix->setEndColor(col); + matrix->setColor(1, col); if (instantChanges() == true) matrix->updateColorDelta(); } @@ -458,8 +458,8 @@ void VCMatrix::slotUpdate() if (matrix == NULL) return; - QColor startColor = matrix->startColor(); - QColor endColor = matrix->endColor(); + QColor startColor = matrix->getColor(0); + QColor endColor = matrix->getColor(1); QString algorithmName; RGBAlgorithm::Type algorithmType = RGBAlgorithm::Plain; QHash algorithmProperties; @@ -750,21 +750,21 @@ void VCMatrix::slotCustomControlClicked() if (control->m_type == VCMatrixControl::StartColor) { - matrix->setStartColor(control->m_color); + matrix->setColor(0, control->m_color); if (instantChanges() == true) matrix->updateColorDelta(); btn->setDown(true); } else if (control->m_type == VCMatrixControl::EndColor) { - matrix->setEndColor(control->m_color); + matrix->setColor(1, control->m_color); if (instantChanges() == true) matrix->updateColorDelta(); btn->setDown(true); } else if (control->m_type == VCMatrixControl::ResetEndColor) { - matrix->setEndColor(QColor()); + matrix->setColor(1, QColor()); if (instantChanges() == true) matrix->updateColorDelta(); } @@ -812,21 +812,21 @@ void VCMatrix::slotCustomControlValueChanged() if (control->m_type == VCMatrixControl::StartColorKnob) { - QRgb color = matrix->startColor().rgb(); + QRgb color = matrix->getColor(0).rgb(); QRgb knobValueColor = control->valueToRgb(knob->value()); color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb()); - matrix->setStartColor(color); + matrix->setColor(0, color); if (instantChanges() == true) matrix->updateColorDelta(); } else if (control->m_type == VCMatrixControl::EndColorKnob) { - QRgb color = matrix->endColor().rgb(); + QRgb color = matrix->getColor(1).rgb(); QRgb knobValueColor = control->valueToRgb(knob->value()); color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb()); - matrix->setEndColor(color); + matrix->setColor(1, color); if (instantChanges() == true) matrix->updateColorDelta(); } From 1ea868f6984a027f66ed8a967893ef87df5388f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Sun, 19 Mar 2023 21:56:26 +0100 Subject: [PATCH 06/63] Merge duplicate defined values --- engine/src/rgbalgorithm.cpp | 4 ++-- engine/src/rgbalgorithm.h | 6 ++---- engine/src/rgbaudio.cpp | 2 +- engine/src/rgbaudio.h | 2 +- engine/src/rgbmatrix.cpp | 8 ++++---- engine/src/rgbmatrix.h | 2 +- engine/src/rgbplain.cpp | 2 +- engine/src/rgbplain.h | 2 +- qmlui/rgbmatrixeditor.cpp | 2 +- ui/src/rgbmatrixeditor.cpp | 2 +- 10 files changed, 15 insertions(+), 17 deletions(-) diff --git a/engine/src/rgbalgorithm.cpp b/engine/src/rgbalgorithm.cpp index db02828043..174b288ceb 100644 --- a/engine/src/rgbalgorithm.cpp +++ b/engine/src/rgbalgorithm.cpp @@ -46,9 +46,9 @@ RGBAlgorithm::RGBAlgorithm(Doc * doc) { } -void RGBAlgorithm::setColors(QColor colors[RGBMATRIX_MAXCOLORS]) +void RGBAlgorithm::setColors(QColor colors[RGBAlgorithmRawColorCount]) { - for (unsigned int i = 0; i < RGBMATRIX_MAXCOLORS; i++) + for (unsigned int i = 0; i < RGBAlgorithmRawColorCount; i++) m_colors[i] = colors[i]; } diff --git a/engine/src/rgbalgorithm.h b/engine/src/rgbalgorithm.h index b9efce543a..f0b123a0e0 100644 --- a/engine/src/rgbalgorithm.h +++ b/engine/src/rgbalgorithm.h @@ -26,8 +26,6 @@ #include #include -#define RGBMATRIX_MAXCOLORS 2 - class QXmlStreamReader; class QXmlStreamWriter; @@ -107,14 +105,14 @@ class RGBAlgorithm ************************************************************************/ public: /** Set the start/end color the algorithm can use */ - virtual void setColors(QColor[RGBMATRIX_MAXCOLORS]); + virtual void setColors(QColor[RGBAlgorithmRawColorCount]); QColor startColor() { return m_colors[0]; } QColor endColor() { return m_colors[1]; } private: - QColor m_colors[RGBMATRIX_MAXCOLORS]; + QColor m_colors[RGBAlgorithmRawColorCount]; /************************************************************************ * Available algorithms diff --git a/engine/src/rgbaudio.cpp b/engine/src/rgbaudio.cpp index 494621610e..34bf7fcf49 100644 --- a/engine/src/rgbaudio.cpp +++ b/engine/src/rgbaudio.cpp @@ -204,7 +204,7 @@ int RGBAudio::apiVersion() const return 1; } -void RGBAudio::setColors(QColor colors[RGBMATRIX_MAXCOLORS]) +void RGBAudio::setColors(QColor colors[RGBAlgorithmRawColorCount]) { RGBAlgorithm::setColors(colors); diff --git a/engine/src/rgbaudio.h b/engine/src/rgbaudio.h index 2270d62e12..39f0adb1a3 100644 --- a/engine/src/rgbaudio.h +++ b/engine/src/rgbaudio.h @@ -86,7 +86,7 @@ protected slots: int apiVersion() const; /** @reimp */ - void setColors(QColor colors[RGBMATRIX_MAXCOLORS]); + void setColors(QColor colors[RGBAlgorithmRawColorCount]); /** @reimp */ RGBAlgorithm::Type type() const; diff --git a/engine/src/rgbmatrix.cpp b/engine/src/rgbmatrix.cpp index b20779cfe1..5ac1191d07 100644 --- a/engine/src/rgbmatrix.cpp +++ b/engine/src/rgbmatrix.cpp @@ -171,7 +171,7 @@ bool RGBMatrix::copyFrom(const Function* function) else setAlgorithm(NULL); - for(unsigned int i = 0; i < RGBMATRIX_MAXCOLORS; i++) + for(unsigned int i = 0; i < RGBAlgorithmRawColorCount; i++) setColor(i, mtx->getColor(i)); return Function::copyFrom(function); @@ -294,7 +294,7 @@ void RGBMatrix::previewMap(int step, RGBMatrixStep *handler) void RGBMatrix::setColor(unsigned int i, QColor c) { - if (i >= RGBMATRIX_MAXCOLORS) + if (i >= RGBAlgorithmRawColorCount) return; m_rgbColors[i] = c; { @@ -393,7 +393,7 @@ bool RGBMatrix::loadXML(QXmlStreamReader &root) { loadXMLRunOrder(root); } -#if (2 != RGBMATRIX_MAXCOLORS) +#if (2 != RGBAlgorithmRawColorCount) #error "Further colors need to be read." #endif else if (root.name() == KXMLQLCRGBMatrixStartColor) @@ -462,7 +462,7 @@ bool RGBMatrix::saveXML(QXmlStreamWriter *doc) /* End Color */ if (getColor(1).isValid()) doc->writeTextElement(KXMLQLCRGBMatrixEndColor, QString::number(getColor(1).rgb())); -#if (2 != RGBMATRIX_MAXCOLORS) +#if (2 != RGBAlgorithmRawColorCount) #error "Further colors need to be written." #endif diff --git a/engine/src/rgbmatrix.h b/engine/src/rgbmatrix.h index 8fda62f838..f65c1f80b0 100644 --- a/engine/src/rgbmatrix.h +++ b/engine/src/rgbmatrix.h @@ -197,7 +197,7 @@ class RGBMatrix : public Function void updateColorDelta(); private: - QColor m_rgbColors[RGBMATRIX_MAXCOLORS]; + QColor m_rgbColors[RGBAlgorithmRawColorCount]; RGBMatrixStep *m_stepHandler; /************************************************************************ diff --git a/engine/src/rgbplain.cpp b/engine/src/rgbplain.cpp index a560af29dc..5daaedb135 100644 --- a/engine/src/rgbplain.cpp +++ b/engine/src/rgbplain.cpp @@ -83,7 +83,7 @@ int RGBPlain::apiVersion() const return 1; } -void RGBPlain::setColors(QColor colors[RGBMATRIX_MAXCOLORS]) +void RGBPlain::setColors(QColor colors[RGBAlgorithmRawColorCount]) { RGBAlgorithm::setColors(colors); } diff --git a/engine/src/rgbplain.h b/engine/src/rgbplain.h index 0280d56c94..0aea97180d 100644 --- a/engine/src/rgbplain.h +++ b/engine/src/rgbplain.h @@ -62,7 +62,7 @@ class RGBPlain : public QObject, public RGBAlgorithm int apiVersion() const; /** @reimp */ - void setColors(QColor colors[RGBMATRIX_MAXCOLORS]); + void setColors(QColor colors[RGBAlgorithmRawColorCount]); /** @reimp */ RGBAlgorithm::Type type() const; diff --git a/qmlui/rgbmatrixeditor.cpp b/qmlui/rgbmatrixeditor.cpp index fa5f4684af..708a838716 100644 --- a/qmlui/rgbmatrixeditor.cpp +++ b/qmlui/rgbmatrixeditor.cpp @@ -134,7 +134,7 @@ void RGBMatrixEditor::setAlgorithmIndex(int algoIndex) /** if we're setting the same algorithm, then there's nothing to do */ if (m_matrix->algorithm() != nullptr && m_matrix->algorithm()->name() == algo->name()) return; - QColor colors[RGBMATRIX_MAXCOLORS] = { + QColor colors[RGBAlgorithmRawColorCount] = { m_matrix->getColor(0), m_matrix->getColor(1) }; diff --git a/ui/src/rgbmatrixeditor.cpp b/ui/src/rgbmatrixeditor.cpp index f1517d745d..ceaf938c40 100644 --- a/ui/src/rgbmatrixeditor.cpp +++ b/ui/src/rgbmatrixeditor.cpp @@ -677,7 +677,7 @@ void RGBMatrixEditor::slotPatternActivated(const QString& text) { RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, text); if (algo != NULL) { - QColor colors[RGBMATRIX_MAXCOLORS] = { + QColor colors[RGBAlgorithmRawColorCount] = { m_matrix->getColor(0), m_matrix->getColor(1) }; From bc7a4b81f17bcf3b1170a174ec277d00939eb934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Fri, 7 Apr 2023 07:25:46 +0200 Subject: [PATCH 07/63] Fix whitespace tabs to spaces --- engine/src/rgbmatrix.cpp | 16 ++++++++-------- qmlui/rgbmatrixeditor.cpp | 4 ++-- ui/src/rgbmatrixeditor.cpp | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/engine/src/rgbmatrix.cpp b/engine/src/rgbmatrix.cpp index 5ac1191d07..a941efec9f 100644 --- a/engine/src/rgbmatrix.cpp +++ b/engine/src/rgbmatrix.cpp @@ -69,7 +69,7 @@ RGBMatrix::RGBMatrix(Doc* doc) , m_rgbColors{ Qt::red, // was m_startColor QColor() // was m_endColor - } + } , m_stepHandler(new RGBMatrixStep()) , m_roundTime(new QElapsedTimer()) , m_stepsCount(0) @@ -172,7 +172,7 @@ bool RGBMatrix::copyFrom(const Function* function) setAlgorithm(NULL); for(unsigned int i = 0; i < RGBAlgorithmRawColorCount; i++) - setColor(i, mtx->getColor(i)); + setColor(i, mtx->getColor(i)); return Function::copyFrom(function); } @@ -282,8 +282,8 @@ void RGBMatrix::previewMap(int step, RGBMatrixStep *handler) if (m_group != NULL) { uint rawColors[] = { - m_rgbColors[0].rgb(), - m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0}; + m_rgbColors[0].rgb(), + m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0}; m_algorithm->rgbMap(m_group->size(), handler->stepColor().rgb(), step, handler->m_map, rawColors); } } @@ -294,8 +294,8 @@ void RGBMatrix::previewMap(int step, RGBMatrixStep *handler) void RGBMatrix::setColor(unsigned int i, QColor c) { - if (i >= RGBAlgorithmRawColorCount) - return; + if (i >= RGBAlgorithmRawColorCount) + return; m_rgbColors[i] = c; { QMutexLocker algorithmLocker(&m_algorithmMutex); @@ -573,8 +573,8 @@ void RGBMatrix::write(MasterTimer *timer, QList universes) m_stepBeatDuration = beatsToTime(duration(), timer->beatTimeDuration()); uint rawColors[] = { - m_rgbColors[0].rgb(), - m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0}; + m_rgbColors[0].rgb() + ,m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0}; //qDebug() << "RGBMatrix step" << m_stepHandler->currentStepIndex() << ", color:" << QString::number(m_stepHandler->stepColor().rgb(), 16); m_algorithm->rgbMap(m_group->size(), m_stepHandler->stepColor().rgb(), m_stepHandler->currentStepIndex(), m_stepHandler->m_map, rawColors); diff --git a/qmlui/rgbmatrixeditor.cpp b/qmlui/rgbmatrixeditor.cpp index 708a838716..281f1e70ff 100644 --- a/qmlui/rgbmatrixeditor.cpp +++ b/qmlui/rgbmatrixeditor.cpp @@ -135,8 +135,8 @@ void RGBMatrixEditor::setAlgorithmIndex(int algoIndex) if (m_matrix->algorithm() != nullptr && m_matrix->algorithm()->name() == algo->name()) return; QColor colors[RGBAlgorithmRawColorCount] = { - m_matrix->getColor(0), - m_matrix->getColor(1) + m_matrix->getColor(0), + m_matrix->getColor(1) }; algo->setColors(colors); } diff --git a/ui/src/rgbmatrixeditor.cpp b/ui/src/rgbmatrixeditor.cpp index ceaf938c40..ebf8d824ed 100644 --- a/ui/src/rgbmatrixeditor.cpp +++ b/ui/src/rgbmatrixeditor.cpp @@ -678,8 +678,8 @@ void RGBMatrixEditor::slotPatternActivated(const QString& text) RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, text); if (algo != NULL) { QColor colors[RGBAlgorithmRawColorCount] = { - m_matrix->getColor(0), - m_matrix->getColor(1) + m_matrix->getColor(0), + m_matrix->getColor(1) }; algo->setColors(colors); } From a2e9b40703bfa3ac8b4a2ff62f98945705ab28f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Wed, 12 Apr 2023 19:28:16 +0200 Subject: [PATCH 08/63] Evaluate properties on apiVersion 2 and above. --- engine/src/rgbscript.cpp | 2 +- engine/src/rgbscriptv4.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/src/rgbscript.cpp b/engine/src/rgbscript.cpp index f9ce9ef16a..f3b6e46a72 100644 --- a/engine/src/rgbscript.cpp +++ b/engine/src/rgbscript.cpp @@ -186,7 +186,7 @@ bool RGBScript::evaluate() m_apiVersion = m_script.property("apiVersion").toInteger(); if (m_apiVersion > 0) { - if (m_apiVersion == 2) + if (m_apiVersion >= 2) return loadProperties(); return true; } diff --git a/engine/src/rgbscriptv4.cpp b/engine/src/rgbscriptv4.cpp index 7f6008482a..ad83bba6e9 100644 --- a/engine/src/rgbscriptv4.cpp +++ b/engine/src/rgbscriptv4.cpp @@ -173,7 +173,7 @@ bool RGBScript::evaluate() m_apiVersion = m_script.property("apiVersion").toInt(); if (m_apiVersion > 0) { - if (m_apiVersion == 2) + if (m_apiVersion >= 2) return loadProperties(); return true; } From 2ae42866965e96fc70ef58728c48a7e4a8812dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Fri, 14 Apr 2023 21:53:04 +0200 Subject: [PATCH 09/63] Handle script errors and use corrected array handling. - Handle script errors which occur only in .call(), not just parse errors from .evaluate(). - Hand over an array, not just a variable arguments list. --- engine/src/rgbmatrix.cpp | 2 + engine/src/rgbscript.cpp | 58 +++++++++++++++++----- engine/src/rgbscript.h | 3 ++ engine/src/rgbscriptv4.cpp | 62 ++++++++++++++++++------ engine/src/rgbscriptv4.h | 3 ++ engine/test/rgbscript/rgbscript_test.cpp | 45 +++++++++-------- resources/rgbscripts/plasmacolors.js | 14 +++--- 7 files changed, 136 insertions(+), 51 deletions(-) diff --git a/engine/src/rgbmatrix.cpp b/engine/src/rgbmatrix.cpp index a941efec9f..67cc89a913 100644 --- a/engine/src/rgbmatrix.cpp +++ b/engine/src/rgbmatrix.cpp @@ -281,6 +281,7 @@ void RGBMatrix::previewMap(int step, RGBMatrixStep *handler) m_group = doc()->fixtureGroup(fixtureGroup()); if (m_group != NULL) { + Q_ASSERT(2 == RGBAlgorithmRawColorCount); uint rawColors[] = { m_rgbColors[0].rgb(), m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0}; @@ -572,6 +573,7 @@ void RGBMatrix::write(MasterTimer *timer, QList universes) if (tempoType() == Beats) m_stepBeatDuration = beatsToTime(duration(), timer->beatTimeDuration()); + Q_ASSERT(2 == RGBAlgorithmRawColorCount); uint rawColors[] = { m_rgbColors[0].rgb() ,m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0}; diff --git a/engine/src/rgbscript.cpp b/engine/src/rgbscript.cpp index f3b6e46a72..c115ce5040 100644 --- a/engine/src/rgbscript.cpp +++ b/engine/src/rgbscript.cpp @@ -213,6 +213,17 @@ void RGBScript::initEngine() Q_ASSERT(s_engine != NULL); } +void RGBScript::displayError(QScriptValue e, const QString& fileName) +{ + if (e.isError()) { + QString msg("%1: Exception at line %2. Error: %3"); + qWarning() << msg.arg(fileName) + .arg(e.property("lineNumber").toInt32()) + .arg(e.toString()); + qDebug() << "Stack: " << e.property("stack").toString(); + } +} + /**************************************************************************** * Script API ****************************************************************************/ @@ -227,8 +238,14 @@ int RGBScript::rgbMapStepCount(const QSize& size) QScriptValueList args; args << size.width() << size.height(); QScriptValue value = m_rgbMapStepCount.call(QScriptValue(), args); - int ret = value.isNumber() ? value.toInteger() : -1; - return ret; + if (value.isError()) + { + displayError(value, m_fileName); + return -1; + } else { + int ret = value.isNumber() ? value.toInteger() : -1; + return ret; + } } void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]) @@ -242,14 +259,19 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint if (m_apiVersion <= 2) { args << size.width() << size.height() << rgb << step; } else { - Q_ASSERT(2 == RGBAlgorithmRawColorCount); - QScriptValueList jsRawColors; - jsRawColors << rawColors[0] << rawColors[1]; - + QScriptValue jsRawColors; + for (int i = 0; i < RGBAlgorithmRawColorCount; i++) { + jsRawColors.setProperty(i, QScriptValue(rawColors[i])); + } args << size.width() << size.height() << rgb << step << jsRawColors; } QScriptValue yarray = m_rgbMap.call(QScriptValue(), args); - if (yarray.isArray() == true) + if (yarray.isError()) + { + displayError(yarray, m_fileName); + } + + if (yarray.isArray()) { int ylen = yarray.property("length").toInteger(); map.resize(ylen); @@ -357,7 +379,11 @@ QHash RGBScript::propertiesAsStrings() { QScriptValueList args; QScriptValue value = readMethod.call(QScriptValue(), args); - if (value.isValid()) + if (value.isError()) + { + displayError(value, m_fileName); + } + else if (value.isValid()) properties.insert(cap.m_name, value.toString()); } } @@ -380,8 +406,14 @@ bool RGBScript::setProperty(QString propertyName, QString value) } QScriptValueList args; args << value; - writeMethod.call(QScriptValue(), args); - return true; + QScriptValue written = writeMethod.call(QScriptValue(), args); + if (written.isError()) + { + displayError(written, m_fileName); + return false; + } else { + return true; + } } } return false; @@ -403,7 +435,11 @@ QString RGBScript::property(QString propertyName) const } QScriptValueList args; QScriptValue value = readMethod.call(QScriptValue(), args); - if (value.isValid()) + if (value.isError()) + { + displayError(value, m_fileName); + return QString(); + } else if (value.isValid()) return value.toString(); else return QString(); diff --git a/engine/src/rgbscript.h b/engine/src/rgbscript.h index 3aa2f2a1d4..7f30660354 100644 --- a/engine/src/rgbscript.h +++ b/engine/src/rgbscript.h @@ -80,6 +80,9 @@ class RGBScript : public RGBAlgorithm /** Init engine, engine mutex, and scripts map */ static void initEngine(); + /** Handle an error after evaluate() or call() of a script */ + static void displayError(QScriptValue e, const QString& fileName); + /************************************************************************ * RGBAlgorithm API ************************************************************************/ diff --git a/engine/src/rgbscriptv4.cpp b/engine/src/rgbscriptv4.cpp index ad83bba6e9..528708d08b 100644 --- a/engine/src/rgbscriptv4.cpp +++ b/engine/src/rgbscriptv4.cpp @@ -148,11 +148,7 @@ bool RGBScript::evaluate() m_script = s_engine->evaluate(m_contents, m_fileName); if (m_script.isError()) { - QString msg("%1: Uncaught exception at line %2. Error: %3"); - qWarning() << msg.arg(m_fileName) - .arg(m_script.property("lineNumber").toInt()) - .arg(m_script.toString()); - qDebug() << "Stack: " << m_script.property("stack").toString(); + displayError(m_script, m_fileName); return false; } @@ -199,6 +195,17 @@ void RGBScript::initEngine() Q_ASSERT(s_engine != NULL); } +void RGBScript::displayError(QJSValue e, const QString& fileName) +{ + if (e.isError()) { + QString msg("%1: Exception at line %2. Error: %3"); + qWarning() << msg.arg(fileName) + .arg(e.property("lineNumber").toInt()) + .arg(e.toString()); + qDebug() << "Stack: " << e.property("stack").toString(); + } +} + /**************************************************************************** * Script API ****************************************************************************/ @@ -213,8 +220,14 @@ int RGBScript::rgbMapStepCount(const QSize& size) QJSValueList args; args << size.width() << size.height(); QJSValue value = m_rgbMapStepCount.call(args); - int ret = value.isNumber() ? value.toInt() : -1; - return ret; + if (value.isError()) + { + displayError(value, m_fileName); + return -1; + } else { + int ret = value.isNumber() ? value.toInt() : -1; + return ret; + } } void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]) @@ -228,15 +241,20 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint if (m_apiVersion <= 2) { args << size.width() << size.height() << rgb << step; } else { - Q_ASSERT(2 == RGBAlgorithmRawColorCount); - QJSValueList jsRawColors; - jsRawColors << rawColors[0] << rawColors[1]; + QJSValue jsRawColors; + for (int i = 0; i < RGBAlgorithmRawColorCount; i++) { + jsRawColors.setProperty(i, QJSValue(rawColors[i])); + } args << size.width() << size.height() << rgb << step << jsRawColors; } QJSValue yarray(m_rgbMap.call(args)); + if (yarray.isError()) + { + displayError(yarray, m_fileName); + } - if (yarray.isArray() == true) + if (yarray.isArray()) { QVariantList yvArray = yarray.toVariant().toList(); int ylen = yvArray.length(); @@ -344,7 +362,11 @@ QHash RGBScript::propertiesAsStrings() { QJSValueList args; QJSValue value = readMethod.call(args); - if (!value.isUndefined()) + if (value.isError()) + { + displayError(value, m_fileName); + } + else if (!value.isUndefined()) properties.insert(cap.m_name, value.toString()); } } @@ -367,8 +389,14 @@ bool RGBScript::setProperty(QString propertyName, QString value) } QJSValueList args; args << value; - writeMethod.call(args); - return true; + QJSValue written = writeMethod.call(args); + if (written.isError()) + { + displayError(written, m_fileName); + return false; + } else { + return true; + } } } return false; @@ -390,7 +418,11 @@ QString RGBScript::property(QString propertyName) const } QJSValueList args; QJSValue value = readMethod.call(args); - if (!value.isUndefined()) + if (value.isError()) + { + displayError(value, m_fileName); + return QString(); + } else if (!value.isUndefined()) return value.toString(); else return QString(); diff --git a/engine/src/rgbscriptv4.h b/engine/src/rgbscriptv4.h index fdb4cdc302..d9f40ecfe2 100644 --- a/engine/src/rgbscriptv4.h +++ b/engine/src/rgbscriptv4.h @@ -71,6 +71,9 @@ class RGBScript : public RGBAlgorithm /** Init engine, engine mutex, and scripts map */ static void initEngine(); + /** Handle an error after evaluate() or call() of a script */ + static void displayError(QJSValue e, const QString& fileName); + private: static QJSEngine* s_engine; //! The engine that runs all scripts #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) diff --git a/engine/test/rgbscript/rgbscript_test.cpp b/engine/test/rgbscript/rgbscript_test.cpp index be1e47e10e..b6f7deae1e 100644 --- a/engine/test/rgbscript/rgbscript_test.cpp +++ b/engine/test/rgbscript/rgbscript_test.cpp @@ -217,6 +217,7 @@ void RGBScript_Test::rgbMap() uint(0) }; s.rgbMap(QSize(3, 4), 0, 0, map, rawRgbColors); + // verify that an array within an array has been returned QVERIFY(map.isEmpty() == false); s.setProperty("orientation", "Vertical"); @@ -244,12 +245,11 @@ void RGBScript_Test::runScripts() { QSize mapSize = QSize(7, 11); // Use different numbers for x and y for the test QSize mapSizePlus = QSize(12, 22); // Prepare a larger matrix to check behaviour on matrix change - // QColor(Qt::red).rgb() is 0xffff0000 due to the alpha channel - // This test also wants to test that there is no color space overrun. - int red = 0xff0000; uint rawRgbColors[RGBAlgorithmRawColorCount] = { - QColor(Qt::red).rgb(), - 0 + // QColor(Qt::red).rgb() is 0xffff0000 due to the alpha channel + // This test also wants to test that there is no color space overrun. + QColor(Qt::red).rgb() & 0xffffff, + uint(0) }; // Iterate the list of scripts @@ -304,19 +304,19 @@ void RGBScript_Test::runScripts() RGBMap rgbMap; for (int step = 0; step < realsteps; step++) { - s.rgbMap(mapSize, red, step, rgbMap, rawRgbColors); + s.rgbMap(mapSize, rawRgbColors[0], step, rgbMap, rawRgbColors); QVERIFY(rgbMap.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) { for (int x = 0; x < mapSize.width(); x++) { - //if (map[y][x] > 0x00ffffff) { - // uint pxr = (map[y][x] >> 16 & 0x000000ff); - // uint pxg = (map[y][x] >> 8 & 0x000000ff); - // uint pxb = (map[y][x] & 0x000000ff); - // qDebug() << "C:" << Qt::hex << pxr << ":" << Qt::hex << pxg << ":" << Qt::hex << pxb << " (" << Qt::hex << map[y][x]<< ")"; - //} + if (rgbMap[y][x] > 0x00ffffff) { + uint pxr = (rgbMap[y][x] >> 16 & 0x000000ff); + uint pxg = (rgbMap[y][x] >> 8 & 0x000000ff); + uint pxb = (rgbMap[y][x] & 0x000000ff); + qDebug() << "height:" << mapSize.height() << "width:" << mapSize.width() << "step:" << step << "y:" << y << "x:" << x << "C:" << Qt::hex << pxr << ":" << Qt::hex << pxg << ":" << Qt::hex << pxb << " (" << Qt::hex << rgbMap[y][x]<< ")"; + } QVERIFY(rgbMap[y][x] <= 0xffffff); } } @@ -326,12 +326,12 @@ void RGBScript_Test::runScripts() RGBMap rgbRefMap; if (1 < s.acceptColors() && 2 < steps && ! randomScript) { // When more than 2 colors are accepted, the steps shall be reproducible to allow back and forth color fade. - s.rgbMap(mapSizePlus, red, 0, rgbRefMap, rawRgbColors); + s.rgbMap(mapSizePlus, rawRgbColors[0], 0, rgbRefMap, rawRgbColors); } // Switch to the larger map and step a few times. for (int step = 0; step < realsteps; step++) { - s.rgbMap(mapSizePlus, red, step, rgbMap, rawRgbColors); + s.rgbMap(mapSizePlus, rawRgbColors[0], step, rgbMap, rawRgbColors); // Check that the color values are limited to a valid range for (int y = 0; y < mapSizePlus.height(); y++) { @@ -340,6 +340,13 @@ void RGBScript_Test::runScripts() if (s.acceptColors() > 0) { // verify that the alpha channel is zero + if (rgbMap[y][x] > 0x00ffffff) + { + uint pxr = (rgbMap[y][x] >> 16 & 0x000000ff); + uint pxg = (rgbMap[y][x] >> 8 & 0x000000ff); + uint pxb = (rgbMap[y][x] & 0x000000ff); + qDebug() << "step:" << step << "x:" << x << "y:" << y << "C:" << Qt::hex << pxr << ":" << Qt::hex << pxg << ":" << Qt::hex << pxb << " (" << Qt::hex << rgbMap[y][x]<< ")"; + } QVERIFY((rgbMap[y][x] & 0xff000000) == 0); QVERIFY((rgbMap[y][x] >> 16) <= 0x0000ff); if (!randomScript && 0 == step && 1 < s.acceptColors() && 2 < steps) @@ -398,7 +405,7 @@ void RGBScript_Test::runScripts() for (int step = 0; step < realsteps; step++) { RGBMap map; - s.rgbMap(mapSize, red, step, map, rawRgbColors); + s.rgbMap(mapSize, rawRgbColors[0], step, map, rawRgbColors); QVERIFY(map.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) @@ -427,7 +434,7 @@ void RGBScript_Test::runScripts() for (int step = 0; step < realsteps; step++) { RGBMap map; - s.rgbMap(mapSize, red, step, map, rawRgbColors); + s.rgbMap(mapSize, rawRgbColors[0], step, map, rawRgbColors); QVERIFY(map.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) @@ -445,7 +452,7 @@ void RGBScript_Test::runScripts() for (int step = 0; step < realsteps; step++) { RGBMap map; - s.rgbMap(mapSize, red, step, map, rawRgbColors); + s.rgbMap(mapSize, rawRgbColors[0], step, map, rawRgbColors); QVERIFY(map.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) @@ -465,7 +472,7 @@ void RGBScript_Test::runScripts() for (int step = 0; step < realsteps; step++) { RGBMap map; - s.rgbMap(mapSize, red, step, map, rawRgbColors); + s.rgbMap(mapSize, rawRgbColors[0], step, map, rawRgbColors); QVERIFY(map.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) @@ -485,7 +492,7 @@ void RGBScript_Test::runScripts() for (int step = 0; step < realsteps; step++) { RGBMap map; - s.rgbMap(mapSize, red, step, map, rawRgbColors); + s.rgbMap(mapSize, rawRgbColors[0], step, map, rawRgbColors); QVERIFY(map.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) diff --git a/resources/rgbscripts/plasmacolors.js b/resources/rgbscripts/plasmacolors.js index 04bc39423f..f2a6bbb5c2 100644 --- a/resources/rgbscripts/plasmacolors.js +++ b/resources/rgbscripts/plasmacolors.js @@ -114,7 +114,6 @@ function() util.initialized = false; util.gradientData = new Array(); util.colorArray = new Array(); - util.colorCache = new Array(); algo.setColor = function(_index, _preset) { @@ -137,7 +136,7 @@ function() }; algo.getRawColor = function (rawColors, idx) { - if (Array.isArray(rawColors) && ! Number.isNaN(rawColors[idx])) { + if (Array.isArray(rawColors) && rawColors.length > idx && ! Number.isNaN(rawColors[idx])) { return rawColors[idx]; } else { return 0; @@ -293,10 +292,13 @@ function() algo.rgbMap = function(width, height, rgb, step, rawColors) { - for (var i = 0; i < algo.acceptColors; i++) { - if (typeof util.colorCache[i] === 'undefined' || util.colorCache[i] !== rawColors[i]) { - util.colorCache[i] = algo.getRawColor(rawColors, i); - util.initialized = false; + if (util.colorArray.length == 0) { + util.initialized = false; + } else if (util.colorArray.length >= algo.acceptColors - 1 && Array.isArray(rawColors)) { + for (var i = 0; i < Math.min(algo.acceptColors, rawColors.length); i++) { + if (util.colorArray[i] !== rawColors[i]) { + util.initialized = false; + } } } if (util.initialized === false) { From 301c3b7b443d0ecb0c46f984709d53c88e30ee46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Sat, 15 Apr 2023 22:06:20 +0200 Subject: [PATCH 10/63] Rotate color array and format the algorithm. The algorithm prefers the inner colors (1-2-3-4-5) over the outer colors as the noise function output is a Gauss distribution. To make the colors set from thr outside more persent, shift them from 1 and 2 to 2 and 3. Also, format the algorithms. --- resources/rgbscripts/plasmacolors.js | 147 +++++++++++++++++++-------- 1 file changed, 104 insertions(+), 43 deletions(-) diff --git a/resources/rgbscripts/plasmacolors.js b/resources/rgbscripts/plasmacolors.js index f2a6bbb5c2..0bdcc967c8 100644 --- a/resources/rgbscripts/plasmacolors.js +++ b/resources/rgbscripts/plasmacolors.js @@ -168,6 +168,7 @@ function() algo.color5Index = algo.setColor(4, _preset); util.initialized = false; }; + algo.getColor5 = function() { return algo.getColor(4); @@ -178,6 +179,7 @@ function() algo.presetSize = _size; util.initialized = false; }; + algo.getSize = function() { return algo.presetSize; @@ -188,6 +190,7 @@ function() algo.ramp = _ramp; util.initialized = false; }; + algo.getRamp = function() { return algo.ramp; @@ -198,6 +201,7 @@ function() algo.stepsize = _step; util.initialized = false; }; + algo.getStep = function() { return algo.stepsize; @@ -212,6 +216,13 @@ function() for (var i = 0; i < algo.colorIndex.length; i++) { util.colorArray[i + algo.acceptColors] = colorPalette.collection[algo.colorIndex[i]][1]; } + // Shift colors 1 & 2 as the outer colors are selected less in the Gauss-Noise function + var tempColor = util.colorArray[util.colorArray.length - 1]; + for (var i = util.colorArray.length - 1; i > 0; i--) { + util.colorArray[i] = util.colorArray[i - 1]; + } + util.colorArray[0] = tempColor; + // calculate the gradient for the selected preset // with the given width var gradIdx = 0; @@ -219,9 +230,9 @@ function() for (var i = 0; i < util.colorArray.length; i++) { var sColor = util.colorArray[i]; - var eColor = util.colorArray[i + 1]; - if (eColor == undefined) { - eColor = util.colorArray[0]; + var eColor = util.colorArray[0];; + if (i < util.colorArray.length - 1) { + eColor = util.colorArray[i + 1]; } util.gradientData[gradIdx++] = sColor; var sr = (sColor >> 16) & 0x00FF; @@ -247,69 +258,119 @@ function() util.initialized = true; }; - function fade(t) { return t * t * t * (t * (t * 6 - 15) + 10); } - function lerp( t, a, b) { return a + t * (b - a); } - function grad(hash, x, y, z) { - var h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE - var u = h<8 ? x : y, // INTO 12 GRADIENT DIRECTIONS. - v = h<4 ? y : h===12||h===14 ? x : z; - return ((h&1) === 0 ? u : -u) + ((h&2) === 0 ? v : -v); - } - function scale(n) { return (1 + n)/2; } - // This is a port of Ken Perlin's Java code. The // original Java code is at http://cs.nyu.edu/%7Eperlin/noise/. // Note that in this version, a number from 0 to 1 is returned. util.noise = function(x, y, z) { var p = new Array(512); - var permutation = [ 151,160,137,91,90,15,131,13,201,95,96,53,194,233, 7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190, 6,148,247,120,234,75, 0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20, 125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229, 122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54, 65,25,63,161,1, 216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100, 109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212, 207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152, 2,44,154, 163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232, 178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,49,192,214, 31,181,199,106,157,184, 84,204,176,115, 121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180]; - - for (var i=0; i < 256 ; i++) { - p[256+i] = p[i] = permutation[i]; + var permutation = [ // 256 members + 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, + 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, + 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, + 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, + 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, + 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, + 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, + 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, + 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, + 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, + 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, + 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, + 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, + 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, + 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, + 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, + 78, 66, 215, 61, 156, 180 + ]; + + // initialize symmetrical permutation array(512) + for (var i = 0; i < 256; i++) { + p[i] = permutation[i]; + p[256 + i] = permutation[i]; } - var X = Math.floor(x) & 255, // FIND UNIT CUBE THAT - Y = Math.floor(y) & 255, // CONTAINS POINT. - Z = Math.floor(z) & 255; - x -= Math.floor(x); // FIND RELATIVE X,Y,Z - y -= Math.floor(y); // OF POINT IN CUBE. - z -= Math.floor(z); - var u = fade(x), // COMPUTE FADE CURVES - v = fade(y), // FOR EACH OF X,Y,Z. - w = fade(z); - var A = p[X ]+Y, AA = p[A]+Z, AB = p[A+1]+Z, // HASH COORDINATES OF - B = p[X+1]+Y, BA = p[B]+Z, BB = p[B+1]+Z; // THE 8 CUBE CORNERS, - - return scale(lerp(w, lerp(v, lerp(u, grad(p[AA ], x , y , z ), // AND ADD - grad(p[BA ], x-1, y , z )), // BLENDED - lerp(u, grad(p[AB ], x , y-1, z ), // RESULTS - grad(p[BB ], x-1, y-1, z ))), // FROM 8 - lerp(v, lerp(u, grad(p[AA+1], x , y , z-1 ), // CORNERS - grad(p[BA+1], x-1, y , z-1 )), // OF CUBE - lerp(u, grad(p[AB+1], x , y-1, z-1 ), - grad(p[BB+1], x-1, y-1, z-1 ))))); + // Find unit cube that contains point. + var X = Math.floor(x) & 255; + var Y = Math.floor(y) & 255; + var Z = Math.floor(z) & 255; + // Find relative x,y,z of point in cube. + x -= Math.floor(x); + y -= Math.floor(y); + z -= Math.floor(z); + // Compute fade curves for each of y, y, z + var u = fade(x); + var v = fade(y); + var w = fade(z); + // Hash coordinates of the 8 cube corners, + var A = p[X] + Y; + var AA = p[A] + Z; + var AB = p[A + 1] + Z; + var B = p[X + 1] + Y; + var BA = p[B] + Z; + var BB = p[B + 1] + Z; + + // And add blended results from8 corners of cube + var rawNoise = lerp(w, + lerp(v, lerp(u, grad(p[AA ], x , y , z ), + grad(p[BA ], x-1, y , z )), + lerp(u, grad(p[AB ], x , y - 1, z ), + grad(p[BB ], x-1, y - 1, z ))), + lerp(v, lerp(u, grad(p[AA + 1], x , y , z - 1), + grad(p[BA + 1], x-1, y , z - 1)), + lerp(u, grad(p[AB + 1], x , y - 1, z - 1), + grad(p[BB + 1], x-1, y - 1, z - 1))) + ); + // Scale to range between 0 and 1 + var noise = scale(rawNoise); + return noise; }; + function fade(t) + { + return t * t * t * (t * (t * 6 - 15) + 10); + } + function lerp(t, a, b) + { + return a + t * (b - a); + } + function grad(hash, x, y, z) + { + // CONVERT TO 4 BITS OF HASH CODE + var h = hash & 0x0000000f; + // INTO 12 GRADIENT DIRECTIONS. + var u = (h < 8) ? x : y; + var v = (h < 4) ? y : (h === 12 || h === 14) ? x : z; + return (((h & 1) === 0) ? u : -1 * u) + (((h & 2) === 0) ? v : -1 * v); + } + function scale(n) + { + var scaled = (1 + n) / 2; + scaled = Math.max(0, scaled - 0.3); + return scaled; + } + algo.rgbMap = function(width, height, rgb, step, rawColors) { if (util.colorArray.length == 0) { util.initialized = false; } else if (util.colorArray.length >= algo.acceptColors - 1 && Array.isArray(rawColors)) { + // Check if the externally provided color has changed. for (var i = 0; i < Math.min(algo.acceptColors, rawColors.length); i++) { if (util.colorArray[i] !== rawColors[i]) { util.initialized = false; } } } - if (util.initialized === false) { + if (util.initialized === false) + { util.initialize(rawColors); } - var size = algo.presetSize/2; // set a scaling value + var size = algo.presetSize / 2; // set a scaling value var speed = Math.pow(100 , (algo.stepsize / 50)); // create a more uniform speed control algo.bstepcount += (speed / 500); algo.bstepcount = (algo.bstepcount % 256); // A rolling step count for the noise function - var square = width>height ? width : height; // keep the patten square + var square = (width > height) ? width : height; // keep the patten square var map = new Array(height); for (var y = 0; y < height; y++) @@ -320,8 +381,8 @@ function() { var nx = x / square; // Normalize nx & ny to 0 - 1 var ny = y / square; - var n = util.noise( size*nx, size*ny, algo.bstepcount); - var gradStep = Math.round( Math.pow(n , (algo.ramp/10)) * util.gradientData.length); + var n = util.noise(size * nx, size * ny, algo.bstepcount); + var gradStep = Math.round(Math.pow(n, (algo.ramp / 10)) * util.gradientData.length); map[y][x] = util.gradientData[gradStep]; } } @@ -331,7 +392,7 @@ function() algo.rgbMapStepCount = function(width, height) { - return 2; // This make no difference to the script ;-) + return 2; // This make no difference to the script ;-) }; // Development tool access From 8a62f6a49583dcfe8a1696ef6c66c29db166647d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Sat, 15 Apr 2023 22:14:19 +0200 Subject: [PATCH 11/63] Unify plasma.js and plasmacolor.js to make them diffable --- resources/rgbscripts/plasma.js | 154 ++++-- resources/rgbscripts/plasmacolors.js | 690 +++++++++++++-------------- 2 files changed, 447 insertions(+), 397 deletions(-) diff --git a/resources/rgbscripts/plasma.js b/resources/rgbscripts/plasma.js index 6caf7f7f8e..0b461ae7e5 100644 --- a/resources/rgbscripts/plasma.js +++ b/resources/rgbscripts/plasma.js @@ -33,13 +33,22 @@ var testAlgo; algo.gstepcount = 50; algo.bstepcount = 100; algo.presetIndex = 0; - algo.properties.push("name:presetIndex|type:list|display:Preset|values:Rainbow,Fire,Abstract,Ocean|write:setPreset|read:getPreset"); + algo.properties.push( + "name:presetIndex|type:list|display:Preset|" + + "values:Rainbow,Fire,Abstract,Ocean|" + + "write:setPreset|read:getPreset"); algo.presetSize = 5; - algo.properties.push("name:presetSize|type:range|display:Size|values:1,20|write:setSize|read:getSize"); + algo.properties.push( + "name:presetSize|type:range|display:Size|" + + "values:1,20|write:setSize|read:getSize"); algo.ramp = 20; - algo.properties.push("name:ramp|type:range|display:Ramp|values:10,30|write:setRamp|read:getRamp"); + algo.properties.push( + "name:ramp|type:range|display:Ramp|" + + "values:10,30|write:setRamp|read:getRamp"); algo.stepsize = 25; - algo.properties.push("name:stepsize|type:range|display:Speed|values:1,50|write:setStep|read:getStep"); + algo.properties.push( + "name:stepsize|type:range|display:Speed|" + + "values:1,50|write:setStep|read:getStep"); var util = new Object; util.initialized = false; @@ -57,7 +66,7 @@ var testAlgo; else if (_preset === "Abstract") { algo.presetIndex = 2; } else if (_preset === "Ocean") { algo.presetIndex = 3; } else { algo.presetIndex = 0; } - util.initialize(); + util.initialized = false; }; algo.getPreset = function() @@ -72,7 +81,7 @@ var testAlgo; algo.setSize = function(_size) { algo.presetSize = _size; - util.initialize(); + util.initialized = false; }; algo.getSize = function() @@ -83,7 +92,7 @@ var testAlgo; algo.setRamp = function(_ramp) { algo.ramp = _ramp; - util.initialize(); + util.initialized = false; }; algo.getRamp = function() @@ -94,7 +103,7 @@ var testAlgo; algo.setStep = function(_step) { algo.stepsize = _step; - util.initialize(); + util.initialized = false; }; algo.getStep = function() @@ -111,9 +120,9 @@ var testAlgo; for (var i = 0; i < util.presets[algo.presetIndex].length; i++) { var sColor = util.presets[algo.presetIndex][i]; - var eColor = util.presets[algo.presetIndex][i + 1]; - if (eColor == undefined) { - eColor = util.presets[algo.presetIndex][0]; + var eColor = util.presets[algo.presetIndex][0; + if (i < util.presets.length - 1) { + eColor = util.presets[algo.presetIndex][i + 1]; } util.gradientData[gradIdx++] = sColor; var sr = (sColor >> 16) & 0x00FF; @@ -145,42 +154,88 @@ var testAlgo; util.noise = function(x, y, z) { var p = new Array(512); - var permutation = [ 151,160,137,91,90,15,131,13,201,95,96,53,194,233, 7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190, 6,148,247,120,234,75, 0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20, 125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229, 122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54, 65,25,63,161,1, 216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100, 109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212, 207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152, 2,44,154, 163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232, 178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,49,192,214, 31,181,199,106,157,184, 84,204,176,115, 121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180]; + var permutation = [ // 256 members + 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, + 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, + 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, + 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, + 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, + 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, + 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, + 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, + 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, + 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, + 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, + 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, + 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, + 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, + 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, + 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, + 78, 66, 215, 61, 156, 180 + ]; - for (var i=0; i < 256 ; i++) { - p[256+i] = p[i] = permutation[i]; + // initialize symmetrical permutation array(512) + for (var i = 0; i < 256; i++) { + p[i] = permutation[i]; + p[256 + i] = permutation[i]; } - var X = Math.floor(x) & 255, // FIND UNIT CUBE THAT - Y = Math.floor(y) & 255, // CONTAINS POINT. - Z = Math.floor(z) & 255; - x -= Math.floor(x); // FIND RELATIVE X,Y,Z - y -= Math.floor(y); // OF POINT IN CUBE. - z -= Math.floor(z); - var u = fade(x), // COMPUTE FADE CURVES - v = fade(y), // FOR EACH OF X,Y,Z. - w = fade(z); - var A = p[X ]+Y, AA = p[A]+Z, AB = p[A+1]+Z, // HASH COORDINATES OF - B = p[X+1]+Y, BA = p[B]+Z, BB = p[B+1]+Z; // THE 8 CUBE CORNERS, - - return scale(lerp(w, lerp(v, lerp(u, grad(p[AA ], x , y , z ), // AND ADD - grad(p[BA ], x-1, y , z )), // BLENDED - lerp(u, grad(p[AB ], x , y-1, z ), // RESULTS - grad(p[BB ], x-1, y-1, z ))), // FROM 8 - lerp(v, lerp(u, grad(p[AA+1], x , y , z-1 ), // CORNERS - grad(p[BA+1], x-1, y , z-1 )), // OF CUBE - lerp(u, grad(p[AB+1], x , y-1, z-1 ), - grad(p[BB+1], x-1, y-1, z-1 ))))); + // Find unit cube that contains point. + var X = Math.floor(x) & 255; + var Y = Math.floor(y) & 255; + var Z = Math.floor(z) & 255; + // Find relative x,y,z of point in cube. + x -= Math.floor(x); + y -= Math.floor(y); + z -= Math.floor(z); + // Compute fade curves for each of y, y, z + var u = fade(x); + var v = fade(y); + var w = fade(z); + // Hash coordinates of the 8 cube corners, + var A = p[X] + Y; + var AA = p[A] + Z; + var AB = p[A + 1] + Z; + var B = p[X + 1] + Y; + var BA = p[B] + Z; + var BB = p[B + 1] + Z; + + // And add blended results from8 corners of cube + var rawNoise = lerp(w, + lerp(v, lerp(u, grad(p[AA ], x , y , z ), + grad(p[BA ], x-1, y , z )), + lerp(u, grad(p[AB ], x , y - 1, z ), + grad(p[BB ], x-1, y - 1, z ))), + lerp(v, lerp(u, grad(p[AA + 1], x , y , z - 1), + grad(p[BA + 1], x-1, y , z - 1)), + lerp(u, grad(p[AB + 1], x , y - 1, z - 1), + grad(p[BB + 1], x-1, y - 1, z - 1))) + ); + // Scale to range between 0 and 1 + var noise = scale(rawNoise); + return noise; }; - function fade(t) { return t * t * t * (t * (t * 6 - 15) + 10); } - function lerp( t, a, b) { return a + t * (b - a); } + function fade(t) + { + return t * t * t * (t * (t * 6 - 15) + 10); + } + function lerp(t, a, b) + { + return a + t * (b - a); + } function grad(hash, x, y, z) { - var h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE - var u = h<8 ? x : y, // INTO 12 GRADIENT DIRECTIONS. - v = h<4 ? y : h===12||h===14 ? x : z; - return ((h&1) === 0 ? u : -u) + ((h&2) === 0 ? v : -v); + // CONVERT TO 4 BITS OF HASH CODE + var h = hash & 0x0000000f; + // INTO 12 GRADIENT DIRECTIONS. + var u = (h < 8) ? x : y; + var v = (h < 4) ? y : (h === 12 || h === 14) ? x : z; + return (((h & 1) === 0) ? u : -1 * u) + (((h & 2) === 0) ? v : -1 * v); + } + function scale(n) + { + var scaled = (1 + n) / 2; + return scaled; } - function scale(n) { return (1 + n)/2; } algo.rgbMap = function(width, height, rgb, step) { @@ -189,11 +244,11 @@ var testAlgo; util.initialize(); } - var size = algo.presetSize/2; // set a scaling value - var speed = Math.pow(100 , (algo.stepsize / 50)); // create a more uniform speed control + var size = algo.presetSize / 2; // set a scaling value + var speed = Math.pow(100 , (algo.stepsize / 50)); // create a more uniform speed control algo.bstepcount += (speed / 500); algo.bstepcount = (algo.bstepcount % 256); // A rolling step count for the noise function - var square = width>height ? width : height; // keep the patten square + var square = (width > height) ? width : height; // keep the patten square var map = new Array(height); for (var y = 0; y < height; y++) @@ -202,10 +257,10 @@ var testAlgo; for (var x = 0; x < width; x++) { - var nx = x / square; // Normalise nx & ny to 0 - 1 + var nx = x / square; // Normalize nx & ny to 0 - 1 var ny = y / square; - var n = util.noise( size*nx, size*ny, algo.bstepcount ); - var gradStep = Math.round( Math.pow(n , (algo.ramp/10)) * util.gradientData.length); + var n = util.noise(size * nx, size * ny, algo.bstepcount); + var gradStep = Math.round(Math.pow(n, (algo.ramp / 10)) * util.gradientData.length); map[y][x] = util.gradientData[gradStep]; } } @@ -215,10 +270,7 @@ var testAlgo; algo.rgbMapStepCount = function(width, height) { - if (util.initialized === false) { - util.initialize(); - } - return width * height; // This make no diferance to the script ;-) + return 2; // This make no difference to the script ;-) }; // Development tool access diff --git a/resources/rgbscripts/plasmacolors.js b/resources/rgbscripts/plasmacolors.js index 0bdcc967c8..61ca169ea3 100644 --- a/resources/rgbscripts/plasmacolors.js +++ b/resources/rgbscripts/plasmacolors.js @@ -21,383 +21,381 @@ var testAlgo; ( -function() -{ - var colorPalette = new Object; - colorPalette.collection = new Array( - ["White" , 0xFFFFFF], // 0 - ["Cream" , 0xFFFF7F], // 1 - ["Pink" , 0xFF7F7F], // 2 - ["Rose" , 0x7F3F3F], // 3 - ["Coral" , 0x7F3F1F], // 4 - ["Dim Red" , 0x7F0000], // 5 - ["Red" , 0xFF0000], // 6 - ["Orange" , 0xFF3F00], // 7 - ["Dim Orange" , 0x7F1F00], // 8 - ["Goldenrod" , 0x7F3F00], // 9 - ["Gold" , 0xFF7F00], // 10 - ["Yellow" , 0xFFFF00], // 11 - ["Dim Yellow" , 0x7F7F00], // 12 - ["Lime" , 0x7FFF00], // 13 - ["Pale Green" , 0x3F7F00], // 14 - ["Dim Green" , 0x007F00], // 15 - ["Green" , 0x00FF00], // 16 - ["Seafoam" , 0x00FF3F], // 17 - ["Turquoise" , 0x007F3F], // 18 - ["Teal" , 0x007F7F], // 19 - ["Cyan" , 0x00FFFF], // 20 - ["Electric Blue", 0x007FFF], // 21 - ["Blue" , 0x0000FF], // 22 - ["Dim Blue" , 0x00007F], // 23 - ["Pale Blue" , 0x1F1F7F], // 24 - ["Indigo" , 0x1F00BF], // 25 - ["Purple" , 0x3F00BF], // 26 - ["Violet" , 0x7F007F], // 27 - ["Magenta" , 0xFF00FF], // 28 - ["Hot Pink" , 0xFF003F], // 29 - ["Deep Pink" , 0x7F001F], // 30 - ["OFF" , 0x000000]); // 31 - - colorPalette.makeSubArray = function(_index) + function() { - var _array = new Array(); - for (var i = 0; i < colorPalette.collection.length; i++) + var colorPalette = new Object; + colorPalette.collection = new Array( + ["White" , 0xFFFFFF], // 0 + ["Cream" , 0xFFFF7F], // 1 + ["Pink" , 0xFF7F7F], // 2 + ["Rose" , 0x7F3F3F], // 3 + ["Coral" , 0x7F3F1F], // 4 + ["Dim Red" , 0x7F0000], // 5 + ["Red" , 0xFF0000], // 6 + ["Orange" , 0xFF3F00], // 7 + ["Dim Orange" , 0x7F1F00], // 8 + ["Goldenrod" , 0x7F3F00], // 9 + ["Gold" , 0xFF7F00], // 10 + ["Yellow" , 0xFFFF00], // 11 + ["Dim Yellow" , 0x7F7F00], // 12 + ["Lime" , 0x7FFF00], // 13 + ["Pale Green" , 0x3F7F00], // 14 + ["Dim Green" , 0x007F00], // 15 + ["Green" , 0x00FF00], // 16 + ["Seafoam" , 0x00FF3F], // 17 + ["Turquoise" , 0x007F3F], // 18 + ["Teal" , 0x007F7F], // 19 + ["Cyan" , 0x00FFFF], // 20 + ["Electric Blue", 0x007FFF], // 21 + ["Blue" , 0x0000FF], // 22 + ["Dim Blue" , 0x00007F], // 23 + ["Pale Blue" , 0x1F1F7F], // 24 + ["Indigo" , 0x1F00BF], // 25 + ["Purple" , 0x3F00BF], // 26 + ["Violet" , 0x7F007F], // 27 + ["Magenta" , 0xFF00FF], // 28 + ["Hot Pink" , 0xFF003F], // 29 + ["Deep Pink" , 0x7F001F], // 30 + ["OFF" , 0x000000]); // 31 + + colorPalette.makeSubArray = function(_index) { - _array.push(colorPalette.collection[i][_index]); - } - return _array; - }; - colorPalette.names = colorPalette.makeSubArray(0); - - var algo = new Object; - algo.apiVersion = 3; - algo.name = "Plasma (Colors)"; - algo.author = "Nathan Durnan"; - algo.acceptColors = 2; - algo.properties = new Array(); - algo.rstepcount = 0; - algo.gstepcount = 50; - algo.bstepcount = 100; - algo.color3Index = 16; - algo.properties.push( - "name:color3Index|type:list|display:Color 3|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor3|read:getColor3"); - algo.color4Index = 22; - algo.properties.push( - "name:color4Index|type:list|display:Color 4|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor4|read:getColor4"); - algo.color5Index = 31; - algo.properties.push( - "name:color5Index|type:list|display:Color 5|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor5|read:getColor5"); - algo.presetSize = 5; - algo.properties.push( - "name:presetSize|type:range|display:Size|" + - "values:1,20|write:setSize|read:getSize"); - algo.ramp = 15; - algo.properties.push( - "name:ramp|type:range|display:Ramp|" + - "values:10,30|write:setRamp|read:getRamp"); - algo.stepsize = 25; - algo.properties.push( - "name:stepsize|type:range|display:Speed|" + - "values:1,50|write:setStep|read:getStep"); - algo.colorIndex = new Array( - algo.color3Index, - algo.color4Index, - algo.color5Index); - - var util = new Object; - util.initialized = false; - util.gradientData = new Array(); - util.colorArray = new Array(); - - algo.setColor = function(_index, _preset) - { - var i = colorPalette.names.indexOf(_preset); - if (i === -1) { - i = (colorPalette.collection.length - 1); - } - algo.colorIndex[_index - algo.acceptColors] = i; - return algo.colorIndex[_index - algo.acceptColors]; - }; + var _array = new Array(); + for (var i = 0; i < colorPalette.collection.length; i++) + { + _array.push(colorPalette.collection[i][_index]); + } + return _array; + }; + colorPalette.names = colorPalette.makeSubArray(0); + + var algo = new Object; + algo.apiVersion = 3; + algo.name = "Plasma (Colors)"; + algo.author = "Nathan Durnan"; + algo.acceptColors = 2; + algo.properties = new Array(); + algo.rstepcount = 0; + algo.gstepcount = 50; + algo.bstepcount = 100; + algo.color3Index = 16; + algo.properties.push( + "name:color3Index|type:list|display:Color 3|" + + "values:" + colorPalette.names.toString() + "|" + + "write:setColor3|read:getColor3"); + algo.color4Index = 22; + algo.properties.push( + "name:color4Index|type:list|display:Color 4|" + + "values:" + colorPalette.names.toString() + "|" + + "write:setColor4|read:getColor4"); + algo.color5Index = 31; + algo.properties.push( + "name:color5Index|type:list|display:Color 5|" + + "values:" + colorPalette.names.toString() + "|" + + "write:setColor5|read:getColor5"); + algo.presetSize = 5; + algo.properties.push( + "name:presetSize|type:range|display:Size|" + + "values:1,20|write:setSize|read:getSize"); + algo.ramp = 15; + algo.properties.push( + "name:ramp|type:range|display:Ramp|" + + "values:10,30|write:setRamp|read:getRamp"); + algo.stepsize = 25; + algo.properties.push( + "name:stepsize|type:range|display:Speed|" + + "values:1,50|write:setStep|read:getStep"); + algo.colorIndex = new Array( + algo.color3Index, + algo.color4Index, + algo.color5Index); + + var util = new Object; + util.initialized = false; + util.gradientData = new Array(); + util.colorArray = new Array(); - algo.getColor = function(_index) - { - var i = algo.colorIndex[_index - algo.acceptColors]; - if (i < 0) { i = 0; } - if (i >= colorPalette.collection.length) { - i = (colorPalette.collection.length - 1); - } - return colorPalette.collection[i][0]; - }; - - algo.getRawColor = function (rawColors, idx) { - if (Array.isArray(rawColors) && rawColors.length > idx && ! Number.isNaN(rawColors[idx])) { - return rawColors[idx]; - } else { - return 0; - } - } + algo.setColor = function(_index, _preset) + { + var i = colorPalette.names.indexOf(_preset); + if (i === -1) { + i = (colorPalette.collection.length - 1); + } + algo.colorIndex[_index - algo.acceptColors] = i; + return algo.colorIndex[_index - algo.acceptColors]; + }; - algo.setColor3 = function(_preset) - { - algo.color3Index = algo.setColor(2, _preset); - util.initialized = false; - }; - algo.getColor3 = function() - { - return algo.getColor(2); - }; + algo.getColor = function(_index) + { + var i = algo.colorIndex[_index - algo.acceptColors]; + if (i < 0) { i = 0; } + if (i >= colorPalette.collection.length) { + i = (colorPalette.collection.length - 1); + } + return colorPalette.collection[i][0]; + }; + + algo.getRawColor = function (rawColors, idx) { + if (Array.isArray(rawColors) && rawColors.length > idx && ! Number.isNaN(rawColors[idx])) { + return rawColors[idx]; + } else { + return 0; + } + } - algo.setColor4 = function(_preset) - { - algo.color4Index = algo.setColor(3, _preset); - util.initialized = false; - }; - algo.getColor4 = function() - { - return algo.getColor(3); - }; + algo.setColor3 = function(_preset) + { + algo.color3Index = algo.setColor(2, _preset); + util.initialized = false; + }; + algo.getColor3 = function() + { + return algo.getColor(2); + }; - algo.setColor5 = function(_preset) - { - algo.color5Index = algo.setColor(4, _preset); - util.initialized = false; - }; + algo.setColor4 = function(_preset) + { + algo.color4Index = algo.setColor(3, _preset); + util.initialized = false; + }; + algo.getColor4 = function() + { + return algo.getColor(3); + }; - algo.getColor5 = function() - { - return algo.getColor(4); - }; + algo.setColor5 = function(_preset) + { + algo.color5Index = algo.setColor(4, _preset); + util.initialized = false; + }; - algo.setSize = function(_size) - { - algo.presetSize = _size; - util.initialized = false; - }; + algo.getColor5 = function() + { + return algo.getColor(4); + }; - algo.getSize = function() - { - return algo.presetSize; - }; + algo.setSize = function(_size) + { + algo.presetSize = _size; + util.initialized = false; + }; - algo.setRamp = function(_ramp) - { - algo.ramp = _ramp; - util.initialized = false; - }; + algo.getSize = function() + { + return algo.presetSize; + }; - algo.getRamp = function() - { - return algo.ramp; - }; + algo.setRamp = function(_ramp) + { + algo.ramp = _ramp; + util.initialized = false; + }; - algo.setStep = function(_step) - { - algo.stepsize = _step; - util.initialized = false; - }; + algo.getRamp = function() + { + return algo.ramp; + }; - algo.getStep = function() - { - return algo.stepsize; - }; + algo.setStep = function(_step) + { + algo.stepsize = _step; + util.initialized = false; + }; - util.initialize = function(rawColors) - { - // Get the colors from the external preset. - for (var i = 0; i < algo.acceptColors; i++) { - util.colorArray[i] = algo.getRawColor(rawColors, i); - } - for (var i = 0; i < algo.colorIndex.length; i++) { - util.colorArray[i + algo.acceptColors] = colorPalette.collection[algo.colorIndex[i]][1]; - } - // Shift colors 1 & 2 as the outer colors are selected less in the Gauss-Noise function - var tempColor = util.colorArray[util.colorArray.length - 1]; - for (var i = util.colorArray.length - 1; i > 0; i--) { - util.colorArray[i] = util.colorArray[i - 1]; - } - util.colorArray[0] = tempColor; + algo.getStep = function() + { + return algo.stepsize; + }; - // calculate the gradient for the selected preset - // with the given width - var gradIdx = 0; - util.gradientData = new Array(); - for (var i = 0; i < util.colorArray.length; i++) + util.initialize = function(rawColors) { - var sColor = util.colorArray[i]; - var eColor = util.colorArray[0];; - if (i < util.colorArray.length - 1) { - eColor = util.colorArray[i + 1]; + // Get the colors from the external preset. + for (var i = 0; i < algo.acceptColors; i++) { + util.colorArray[i] = algo.getRawColor(rawColors, i); } - util.gradientData[gradIdx++] = sColor; - var sr = (sColor >> 16) & 0x00FF; - var sg = (sColor >> 8) & 0x00FF; - var sb = sColor & 0x00FF; - var er = (eColor >> 16) & 0x00FF; - var eg = (eColor >> 8) & 0x00FF; - var eb = eColor & 0x00FF; - - var stepR = ((er - sr) / 300); - var stepG = ((eg - sg) / 300); - var stepB = ((eb - sb) / 300); - - for (var s = 1; s < 300; s++) - { - var gradR = Math.floor(sr + (stepR * s)) & 0x00FF; - var gradG = Math.floor(sg + (stepG * s)) & 0x00FF; - var gradB = Math.floor(sb + (stepB * s)) & 0x00FF; - var gradRGB = (gradR << 16) + (gradG << 8) + gradB; - util.gradientData[gradIdx++] = gradRGB; + for (var i = 0; i < algo.colorIndex.length; i++) { + util.colorArray[i + algo.acceptColors] = colorPalette.collection[algo.colorIndex[i]][1]; } - } - util.initialized = true; - }; - - // This is a port of Ken Perlin's Java code. The - // original Java code is at http://cs.nyu.edu/%7Eperlin/noise/. - // Note that in this version, a number from 0 to 1 is returned. - util.noise = function(x, y, z) - { - var p = new Array(512); - var permutation = [ // 256 members - 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, - 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, - 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, - 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, - 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, - 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, - 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, - 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, - 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, - 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, - 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, - 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, - 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, - 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, - 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, - 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, - 78, 66, 215, 61, 156, 180 - ]; - - // initialize symmetrical permutation array(512) - for (var i = 0; i < 256; i++) { - p[i] = permutation[i]; - p[256 + i] = permutation[i]; - } - // Find unit cube that contains point. - var X = Math.floor(x) & 255; - var Y = Math.floor(y) & 255; - var Z = Math.floor(z) & 255; - // Find relative x,y,z of point in cube. - x -= Math.floor(x); - y -= Math.floor(y); - z -= Math.floor(z); - // Compute fade curves for each of y, y, z - var u = fade(x); - var v = fade(y); - var w = fade(z); - // Hash coordinates of the 8 cube corners, - var A = p[X] + Y; - var AA = p[A] + Z; - var AB = p[A + 1] + Z; - var B = p[X + 1] + Y; - var BA = p[B] + Z; - var BB = p[B + 1] + Z; - - // And add blended results from8 corners of cube - var rawNoise = lerp(w, - lerp(v, lerp(u, grad(p[AA ], x , y , z ), - grad(p[BA ], x-1, y , z )), - lerp(u, grad(p[AB ], x , y - 1, z ), - grad(p[BB ], x-1, y - 1, z ))), - lerp(v, lerp(u, grad(p[AA + 1], x , y , z - 1), - grad(p[BA + 1], x-1, y , z - 1)), - lerp(u, grad(p[AB + 1], x , y - 1, z - 1), - grad(p[BB + 1], x-1, y - 1, z - 1))) - ); - // Scale to range between 0 and 1 - var noise = scale(rawNoise); - return noise; - }; - function fade(t) - { - return t * t * t * (t * (t * 6 - 15) + 10); - } - function lerp(t, a, b) - { - return a + t * (b - a); - } - function grad(hash, x, y, z) - { - // CONVERT TO 4 BITS OF HASH CODE - var h = hash & 0x0000000f; - // INTO 12 GRADIENT DIRECTIONS. - var u = (h < 8) ? x : y; - var v = (h < 4) ? y : (h === 12 || h === 14) ? x : z; - return (((h & 1) === 0) ? u : -1 * u) + (((h & 2) === 0) ? v : -1 * v); - } - function scale(n) - { - var scaled = (1 + n) / 2; - scaled = Math.max(0, scaled - 0.3); - return scaled; - } - + // Shift colors 1 & 2 as the outer colors are selected less in the Gauss-Noise function + var tempColor = util.colorArray[util.colorArray.length - 1]; + for (var i = util.colorArray.length - 1; i > 0; i--) { + util.colorArray[i] = util.colorArray[i - 1]; + } + util.colorArray[0] = tempColor; - algo.rgbMap = function(width, height, rgb, step, rawColors) - { - if (util.colorArray.length == 0) { - util.initialized = false; - } else if (util.colorArray.length >= algo.acceptColors - 1 && Array.isArray(rawColors)) { - // Check if the externally provided color has changed. - for (var i = 0; i < Math.min(algo.acceptColors, rawColors.length); i++) { - if (util.colorArray[i] !== rawColors[i]) { - util.initialized = false; + // calculate the gradient for the selected preset + // with the given width + var gradIdx = 0; + util.gradientData = new Array(); + for (var i = 0; i < util.colorArray.length; i++) + { + var sColor = util.colorArray[i]; + var eColor = util.colorArray[0];; + if (i < util.colorArray.length - 1) { + eColor = util.colorArray[i + 1]; + } + util.gradientData[gradIdx++] = sColor; + var sr = (sColor >> 16) & 0x00FF; + var sg = (sColor >> 8) & 0x00FF; + var sb = sColor & 0x00FF; + var er = (eColor >> 16) & 0x00FF; + var eg = (eColor >> 8) & 0x00FF; + var eb = eColor & 0x00FF; + + var stepR = ((er - sr) / 300); + var stepG = ((eg - sg) / 300); + var stepB = ((eb - sb) / 300); + + for (var s = 1; s < 300; s++) + { + var gradR = Math.floor(sr + (stepR * s)) & 0x00FF; + var gradG = Math.floor(sg + (stepG * s)) & 0x00FF; + var gradB = Math.floor(sb + (stepB * s)) & 0x00FF; + var gradRGB = (gradR << 16) + (gradG << 8) + gradB; + util.gradientData[gradIdx++] = gradRGB; } } + util.initialized = true; + }; + + // This is a port of Ken Perlin's Java code. The + // original Java code is at http://cs.nyu.edu/%7Eperlin/noise/. + // Note that in this version, a number from 0 to 1 is returned. + util.noise = function(x, y, z) + { + var p = new Array(512); + var permutation = [ // 256 members + 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, + 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, + 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, + 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, + 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, + 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, + 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, + 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, + 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, + 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, + 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, + 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, + 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, + 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, + 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, + 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, + 78, 66, 215, 61, 156, 180 + ]; + + // initialize symmetrical permutation array(512) + for (var i = 0; i < 256; i++) { + p[i] = permutation[i]; + p[256 + i] = permutation[i]; + } + // Find unit cube that contains point. + var X = Math.floor(x) & 255; + var Y = Math.floor(y) & 255; + var Z = Math.floor(z) & 255; + // Find relative x,y,z of point in cube. + x -= Math.floor(x); + y -= Math.floor(y); + z -= Math.floor(z); + // Compute fade curves for each of y, y, z + var u = fade(x); + var v = fade(y); + var w = fade(z); + // Hash coordinates of the 8 cube corners, + var A = p[X] + Y; + var AA = p[A] + Z; + var AB = p[A + 1] + Z; + var B = p[X + 1] + Y; + var BA = p[B] + Z; + var BB = p[B + 1] + Z; + + // And add blended results from8 corners of cube + var rawNoise = lerp(w, + lerp(v, lerp(u, grad(p[AA ], x , y , z ), + grad(p[BA ], x-1, y , z )), + lerp(u, grad(p[AB ], x , y - 1, z ), + grad(p[BB ], x-1, y - 1, z ))), + lerp(v, lerp(u, grad(p[AA + 1], x , y , z - 1), + grad(p[BA + 1], x-1, y , z - 1)), + lerp(u, grad(p[AB + 1], x , y - 1, z - 1), + grad(p[BB + 1], x-1, y - 1, z - 1))) + ); + // Scale to range between 0 and 1 + var noise = scale(rawNoise); + return noise; + }; + function fade(t) + { + return t * t * t * (t * (t * 6 - 15) + 10); } - if (util.initialized === false) + function lerp(t, a, b) { - util.initialize(rawColors); + return a + t * (b - a); + } + function grad(hash, x, y, z) + { + // CONVERT TO 4 BITS OF HASH CODE + var h = hash & 0x0000000f; + // INTO 12 GRADIENT DIRECTIONS. + var u = (h < 8) ? x : y; + var v = (h < 4) ? y : (h === 12 || h === 14) ? x : z; + return (((h & 1) === 0) ? u : -1 * u) + (((h & 2) === 0) ? v : -1 * v); + } + function scale(n) + { + var scaled = (1 + n) / 2; + return scaled; } - var size = algo.presetSize / 2; // set a scaling value - var speed = Math.pow(100 , (algo.stepsize / 50)); // create a more uniform speed control - algo.bstepcount += (speed / 500); - algo.bstepcount = (algo.bstepcount % 256); // A rolling step count for the noise function - var square = (width > height) ? width : height; // keep the patten square - - var map = new Array(height); - for (var y = 0; y < height; y++) + algo.rgbMap = function(width, height, rgb, step, rawColors) { - map[y] = new Array(); + if (util.colorArray.length == 0) { + util.initialized = false; + } else if (util.colorArray.length >= algo.acceptColors - 1 && Array.isArray(rawColors)) { + // Check if the externally provided color has changed. + for (var i = 0; i < Math.min(algo.acceptColors, rawColors.length); i++) { + if (util.colorArray[i] !== rawColors[i]) { + util.initialized = false; + } + } + } + if (util.initialized === false) + { + util.initialize(rawColors); + } - for (var x = 0; x < width; x++) + var size = algo.presetSize / 2; // set a scaling value + var speed = Math.pow(100 , (algo.stepsize / 50)); // create a more uniform speed control + algo.bstepcount += (speed / 500); + algo.bstepcount = (algo.bstepcount % 256); // A rolling step count for the noise function + var square = (width > height) ? width : height; // keep the patten square + + var map = new Array(height); + for (var y = 0; y < height; y++) { - var nx = x / square; // Normalize nx & ny to 0 - 1 - var ny = y / square; - var n = util.noise(size * nx, size * ny, algo.bstepcount); - var gradStep = Math.round(Math.pow(n, (algo.ramp / 10)) * util.gradientData.length); - map[y][x] = util.gradientData[gradStep]; + map[y] = new Array(); + + for (var x = 0; x < width; x++) + { + var nx = x / square; // Normalize nx & ny to 0 - 1 + var ny = y / square; + var n = util.noise(size * nx, size * ny, algo.bstepcount); + var gradStep = Math.round(Math.pow(n, (algo.ramp / 10)) * util.gradientData.length); + map[y][x] = util.gradientData[gradStep]; + } } - } - return map; - }; + return map; + }; - algo.rgbMapStepCount = function(width, height) - { - return 2; // This make no difference to the script ;-) - }; + algo.rgbMapStepCount = function(width, height) + { + return 2; // This make no difference to the script ;-) + }; - // Development tool access - testAlgo = algo; + // Development tool access + testAlgo = algo; - return algo; -} + return algo; + } )(); From 24dcb0e70198e5a14aa4ce5a7f49878d6c83e6b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Sat, 15 Apr 2023 22:20:33 +0200 Subject: [PATCH 12/63] Fix lost bracket --- resources/rgbscripts/plasma.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/rgbscripts/plasma.js b/resources/rgbscripts/plasma.js index 0b461ae7e5..1492dae25a 100644 --- a/resources/rgbscripts/plasma.js +++ b/resources/rgbscripts/plasma.js @@ -120,7 +120,7 @@ var testAlgo; for (var i = 0; i < util.presets[algo.presetIndex].length; i++) { var sColor = util.presets[algo.presetIndex][i]; - var eColor = util.presets[algo.presetIndex][0; + var eColor = util.presets[algo.presetIndex][0]; if (i < util.presets.length - 1) { eColor = util.presets[algo.presetIndex][i + 1]; } From 33107b2d7938cd6c785acb160a52f0f3bb824061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Sun, 16 Apr 2023 20:40:26 +0200 Subject: [PATCH 13/63] Fix the problem of the first color being mostly suppressed - Set default ramp value to center (20) as in plasma.js - Add and improve code comments and their formatting - Make value calculation explicit to make them available for debugging - Keep plasma and plasmacolors in sync for comparability. --- resources/rgbscripts/plasma.js | 20 ++++++++++++++----- resources/rgbscripts/plasmacolors.js | 30 ++++++++++++++++------------ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/resources/rgbscripts/plasma.js b/resources/rgbscripts/plasma.js index 1492dae25a..c2afb92c6a 100644 --- a/resources/rgbscripts/plasma.js +++ b/resources/rgbscripts/plasma.js @@ -214,14 +214,20 @@ var testAlgo; var noise = scale(rawNoise); return noise; }; + // Fade function for values between 0 and 1 function fade(t) { - return t * t * t * (t * (t * 6 - 15) + 10); + // https://www.geogebra.org/calculator + // f(t)=t^(3) (t (t*6-15)+10) + var fade = t * t * t * (t * (t * 6 - 15) + 10); + return fade; } + // https://en.wikipedia.org/wiki/Linear_interpolation function lerp(t, a, b) { return a + t * (b - a); } + // https://en.wikipedia.org/wiki/Gradient function grad(hash, x, y, z) { // CONVERT TO 4 BITS OF HASH CODE @@ -244,11 +250,15 @@ var testAlgo; util.initialize(); } - var size = algo.presetSize / 2; // set a scaling value - var speed = Math.pow(100 , (algo.stepsize / 50)); // create a more uniform speed control + // set a scaling value + var size = algo.presetSize / 2; + // create a more uniform speed control + var speed = Math.pow(100, (algo.stepsize / 50)); algo.bstepcount += (speed / 500); - algo.bstepcount = (algo.bstepcount % 256); // A rolling step count for the noise function - var square = (width > height) ? width : height; // keep the patten square + // A rolling step count for the noise function + algo.bstepcount = (algo.bstepcount % 256); + // keep the patten square + var square = (width > height) ? width : height; var map = new Array(height); for (var y = 0; y < height; y++) diff --git a/resources/rgbscripts/plasmacolors.js b/resources/rgbscripts/plasmacolors.js index 61ca169ea3..6f0bf49f89 100644 --- a/resources/rgbscripts/plasmacolors.js +++ b/resources/rgbscripts/plasmacolors.js @@ -97,7 +97,7 @@ var testAlgo; algo.properties.push( "name:presetSize|type:range|display:Size|" + "values:1,20|write:setSize|read:getSize"); - algo.ramp = 15; + algo.ramp = 20; algo.properties.push( "name:ramp|type:range|display:Ramp|" + "values:10,30|write:setRamp|read:getRamp"); @@ -109,7 +109,7 @@ var testAlgo; algo.color3Index, algo.color4Index, algo.color5Index); - + var util = new Object; util.initialized = false; util.gradientData = new Array(); @@ -216,12 +216,6 @@ var testAlgo; for (var i = 0; i < algo.colorIndex.length; i++) { util.colorArray[i + algo.acceptColors] = colorPalette.collection[algo.colorIndex[i]][1]; } - // Shift colors 1 & 2 as the outer colors are selected less in the Gauss-Noise function - var tempColor = util.colorArray[util.colorArray.length - 1]; - for (var i = util.colorArray.length - 1; i > 0; i--) { - util.colorArray[i] = util.colorArray[i - 1]; - } - util.colorArray[0] = tempColor; // calculate the gradient for the selected preset // with the given width @@ -324,14 +318,20 @@ var testAlgo; var noise = scale(rawNoise); return noise; }; + // Fade function for values between 0 and 1 function fade(t) { - return t * t * t * (t * (t * 6 - 15) + 10); + // https://www.geogebra.org/calculator + // f(t)=t^(3) (t (t*6-15)+10) + var fade = t * t * t * (t * (t * 6 - 15) + 10); + return fade; } + // https://en.wikipedia.org/wiki/Linear_interpolation function lerp(t, a, b) { return a + t * (b - a); } + // https://en.wikipedia.org/wiki/Gradient function grad(hash, x, y, z) { // CONVERT TO 4 BITS OF HASH CODE @@ -364,11 +364,15 @@ var testAlgo; util.initialize(rawColors); } - var size = algo.presetSize / 2; // set a scaling value - var speed = Math.pow(100 , (algo.stepsize / 50)); // create a more uniform speed control + // set a scaling value + var size = algo.presetSize / 2; + // create a more uniform speed control + var speed = Math.pow(100, (algo.stepsize / 50)); algo.bstepcount += (speed / 500); - algo.bstepcount = (algo.bstepcount % 256); // A rolling step count for the noise function - var square = (width > height) ? width : height; // keep the patten square + // A rolling step count for the noise function + algo.bstepcount = (algo.bstepcount % 256); + // keep the patten square + var square = (width > height) ? width : height; var map = new Array(height); for (var y = 0; y < height; y++) From e6bd8c0dc5a5ded2d83e9908bc6b6c204597ade4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Mon, 17 Apr 2023 18:58:46 +0200 Subject: [PATCH 14/63] Make the rgbMap parameter an Array object. --- engine/src/rgbscript.cpp | 2 +- engine/src/rgbscriptv4.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/src/rgbscript.cpp b/engine/src/rgbscript.cpp index c115ce5040..47edb303e2 100644 --- a/engine/src/rgbscript.cpp +++ b/engine/src/rgbscript.cpp @@ -259,7 +259,7 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint if (m_apiVersion <= 2) { args << size.width() << size.height() << rgb << step; } else { - QScriptValue jsRawColors; + QScriptValue jsRawColors = s_engine->newArray(RGBAlgorithmRawColorCount); for (int i = 0; i < RGBAlgorithmRawColorCount; i++) { jsRawColors.setProperty(i, QScriptValue(rawColors[i])); } diff --git a/engine/src/rgbscriptv4.cpp b/engine/src/rgbscriptv4.cpp index 528708d08b..85eddecf50 100644 --- a/engine/src/rgbscriptv4.cpp +++ b/engine/src/rgbscriptv4.cpp @@ -241,7 +241,7 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint if (m_apiVersion <= 2) { args << size.width() << size.height() << rgb << step; } else { - QJSValue jsRawColors; + QJSValue jsRawColors = s_engine->newArray(RGBAlgorithmRawColorCount); for (int i = 0; i < RGBAlgorithmRawColorCount; i++) { jsRawColors.setProperty(i, QJSValue(rawColors[i])); } From a95439f125c13ddd8d7ad01296106f052917594c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Mon, 17 Apr 2023 18:59:56 +0200 Subject: [PATCH 15/63] Perform more robust parameter evaluation and add documentation in template empty.js --- resources/rgbscripts/alternate.js | 2 +- resources/rgbscripts/ballscolors.js | 2 +- resources/rgbscripts/empty.js | 25 ++++++++++++++++++++++--- resources/rgbscripts/plasmacolors.js | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/resources/rgbscripts/alternate.js b/resources/rgbscripts/alternate.js index 2214afd6f1..20e8a21303 100644 --- a/resources/rgbscripts/alternate.js +++ b/resources/rgbscripts/alternate.js @@ -100,7 +100,7 @@ var testAlgo; }; algo.getRawColor = function (rawColors, idx) { - if (Array.isArray(rawColors) && ! Number.isNaN(rawColors[idx])) { + if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { return rawColors[idx]; } else { return 0; diff --git a/resources/rgbscripts/ballscolors.js b/resources/rgbscripts/ballscolors.js index 4f50ead61f..80e847f5e1 100644 --- a/resources/rgbscripts/ballscolors.js +++ b/resources/rgbscripts/ballscolors.js @@ -146,7 +146,7 @@ var testAlgo; }; algo.getRawColor = function (rawColors, idx) { - if (Array.isArray(rawColors) && ! Number.isNaN(rawColors[idx])) { + if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { return rawColors[idx]; } else { return 0; diff --git a/resources/rgbscripts/empty.js b/resources/rgbscripts/empty.js index 7aa49628f1..43ce62acf2 100644 --- a/resources/rgbscripts/empty.js +++ b/resources/rgbscripts/empty.js @@ -27,15 +27,34 @@ var testAlgo; algo.apiVersion = 3; algo.name = "Script name"; algo.author = "Your Name"; + algo.acceptColors = 2; algo.properties = new Array(); + /** + * Evaluates the rawColors parameter and returns the idx value + * + * @param rawColors The array of colors + * @param idx The index of the color in the array + * @return The requested array color or zero in case of invalid input + */ + algo.getRawColor = function (rawColors, idx) { + if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { + return rawColors[idx]; + } else { + return 0; + } + } + /** * The actual "algorithm" for this RGB script. Produces a map of * size($width, $height) each time it is called. * + * @param width The width of the matrix in pixels + * @param height The height of the matrix in pixels + * @param rgb Tells the color requested by user in the UI, interpolated between stepCount. * @param step The step number that is requested (0 to (algo.rgbMapStepCount - 1)) - * @param rgb Tells the color requested by user in the UI. - * @return A two-dimensional array[height][width]. + * @param rawColors The non-interpolated algo.acceptColors user-defined colors + * @return A two-dimensional matrix array[height][width]. */ algo.rgbMap = function(width, height, rgb, step, rawColors) { @@ -44,7 +63,7 @@ var testAlgo; { map[y] = new Array(); for (var x = 0; x < width; x++) { - map[y][x] = 0; // <-- elapsed color goes here + map[y][x] = rgb; // <-- color goes here } } diff --git a/resources/rgbscripts/plasmacolors.js b/resources/rgbscripts/plasmacolors.js index 6f0bf49f89..72f6fb6e9b 100644 --- a/resources/rgbscripts/plasmacolors.js +++ b/resources/rgbscripts/plasmacolors.js @@ -136,7 +136,7 @@ var testAlgo; }; algo.getRawColor = function (rawColors, idx) { - if (Array.isArray(rawColors) && rawColors.length > idx && ! Number.isNaN(rawColors[idx])) { + if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { return rawColors[idx]; } else { return 0; From eb531093085e909b4490918559c1946061ad295a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Mon, 17 Apr 2023 19:01:33 +0200 Subject: [PATCH 16/63] Add a test to check the effectiveness of the rawColors --- engine/test/rgbscript/rgbscript_test.cpp | 29 +++++++++++++++++++++++- engine/test/rgbscript/rgbscript_test.h | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/engine/test/rgbscript/rgbscript_test.cpp b/engine/test/rgbscript/rgbscript_test.cpp index b6f7deae1e..f4fc6842bc 100644 --- a/engine/test/rgbscript/rgbscript_test.cpp +++ b/engine/test/rgbscript/rgbscript_test.cpp @@ -208,6 +208,34 @@ void RGBScript_Test::rgbMapStepCount() QCOMPARE(s.rgbMapStepCount(QSize(10, 15)), 10); } +void RGBScript_Test::rgbMapColorArray() +{ + RGBMap map; + RGBScript s = m_doc->rgbScriptsCache()->script("Alternate"); + QCOMPARE(s.evaluate(), true); + uint rawRgbColors[RGBAlgorithmRawColorCount] = { + QColor(Qt::red).rgb() & 0x00ffffff, + QColor(Qt::green).rgb() & 0x00ffffff + }; + QSize mapSize = QSize(5, 5); + qDebug() << "C1: " << hex << rawRgbColors[0] << " C2: " << hex << rawRgbColors[1]; + s.rgbMap(mapSize, 0, 0, map, rawRgbColors); + QVERIFY(map.isEmpty() == false); + + // check that both initial colors are used in the same step + for (int y = 0; y < mapSize.height(); y++) + { + for (int x = 0; x < mapSize.width(); x++) + { + // qDebug() << "y: " << y << " x: " << x << " C: " << hex << map[y][x]; + if (x % 2 == 0) + QCOMPARE(map[y][x], rawRgbColors[1]); + else + QCOMPARE(map[y][x], rawRgbColors[0]); + } + } +} + void RGBScript_Test::rgbMap() { RGBMap map; @@ -227,7 +255,6 @@ void RGBScript_Test::rgbMap() { RGBMap map; s.rgbMap(QSize(5, 5), rawRgbColors[0], step, map, rawRgbColors); - for (int y = 0; y < 5; y++) { for (int x = 0; x < 5; x++) diff --git a/engine/test/rgbscript/rgbscript_test.h b/engine/test/rgbscript/rgbscript_test.h index 60eb90b16a..c426a56469 100644 --- a/engine/test/rgbscript/rgbscript_test.h +++ b/engine/test/rgbscript/rgbscript_test.h @@ -40,6 +40,7 @@ private slots: void evaluateNoRgbMapStepCountFunction(); void evaluateInvalidApiVersion(); void rgbMapStepCount(); + void rgbMapColorArray(); void rgbMap(); void runScripts(); From 2438f654a703c5fd54cb8d952402d62d39017b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Wed, 19 Apr 2023 19:10:08 +0200 Subject: [PATCH 17/63] Fix tabs to spaces. --- engine/src/rgbalgorithm.cpp | 6 +-- engine/src/rgbalgorithm.h | 2 +- engine/src/rgbscript.cpp | 2 +- engine/src/rgbscriptv4.cpp | 4 +- engine/test/rgbscript/rgbscript_test.cpp | 18 +++---- engine/test/rgbtext/rgbtext_test.cpp | 12 ++--- resources/rgbscripts/ballscolors.js | 68 ++++++++++++------------ 7 files changed, 56 insertions(+), 56 deletions(-) diff --git a/engine/src/rgbalgorithm.cpp b/engine/src/rgbalgorithm.cpp index 174b288ceb..81b66f7731 100644 --- a/engine/src/rgbalgorithm.cpp +++ b/engine/src/rgbalgorithm.cpp @@ -42,14 +42,14 @@ RGBAlgorithm::RGBAlgorithm(Doc * doc) , m_colors{ QColor(), // was m_startColor QColor() // was m_endColor - } + } { } void RGBAlgorithm::setColors(QColor colors[RGBAlgorithmRawColorCount]) { - for (unsigned int i = 0; i < RGBAlgorithmRawColorCount; i++) - m_colors[i] = colors[i]; + for (unsigned int i = 0; i < RGBAlgorithmRawColorCount; i++) + m_colors[i] = colors[i]; } /**************************************************************************** diff --git a/engine/src/rgbalgorithm.h b/engine/src/rgbalgorithm.h index f0b123a0e0..323eca9e14 100644 --- a/engine/src/rgbalgorithm.h +++ b/engine/src/rgbalgorithm.h @@ -76,7 +76,7 @@ class RGBAlgorithm /** Load a RGBMap for the given step. */ virtual void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, - uint (&rawColors)[RGBAlgorithmRawColorCount]) = 0; + uint (&rawColors)[RGBAlgorithmRawColorCount]) = 0; /** Release resources that may have been acquired in rgbMap() */ virtual void postRun() {} diff --git a/engine/src/rgbscript.cpp b/engine/src/rgbscript.cpp index 47edb303e2..42bdaa6edb 100644 --- a/engine/src/rgbscript.cpp +++ b/engine/src/rgbscript.cpp @@ -263,7 +263,7 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint for (int i = 0; i < RGBAlgorithmRawColorCount; i++) { jsRawColors.setProperty(i, QScriptValue(rawColors[i])); } - args << size.width() << size.height() << rgb << step << jsRawColors; + args << size.width() << size.height() << rgb << step << jsRawColors; } QScriptValue yarray = m_rgbMap.call(QScriptValue(), args); if (yarray.isError()) diff --git a/engine/src/rgbscriptv4.cpp b/engine/src/rgbscriptv4.cpp index 85eddecf50..131a8d28be 100644 --- a/engine/src/rgbscriptv4.cpp +++ b/engine/src/rgbscriptv4.cpp @@ -239,14 +239,14 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint QJSValueList args; if (m_apiVersion <= 2) { - args << size.width() << size.height() << rgb << step; + args << size.width() << size.height() << rgb << step; } else { QJSValue jsRawColors = s_engine->newArray(RGBAlgorithmRawColorCount); for (int i = 0; i < RGBAlgorithmRawColorCount; i++) { jsRawColors.setProperty(i, QJSValue(rawColors[i])); } - args << size.width() << size.height() << rgb << step << jsRawColors; + args << size.width() << size.height() << rgb << step << jsRawColors; } QJSValue yarray(m_rgbMap.call(args)); if (yarray.isError()) diff --git a/engine/test/rgbscript/rgbscript_test.cpp b/engine/test/rgbscript/rgbscript_test.cpp index f4fc6842bc..ac5d5ebaaa 100644 --- a/engine/test/rgbscript/rgbscript_test.cpp +++ b/engine/test/rgbscript/rgbscript_test.cpp @@ -176,8 +176,8 @@ void RGBScript_Test::evaluateNoRgbMapFunction() s.m_contents = code; QCOMPARE(s.evaluate(), false); uint rawRgbColors[RGBAlgorithmRawColorCount] = { - QColor(Qt::red).rgb(), - QColor(Qt::green).rgb() + QColor(Qt::red).rgb(), + QColor(Qt::green).rgb() }; s.rgbMap(QSize(5, 5), 1, 0, map, rawRgbColors); QCOMPARE(map, RGBMap()); @@ -241,8 +241,8 @@ void RGBScript_Test::rgbMap() RGBMap map; RGBScript s = m_doc->rgbScriptsCache()->script("Stripes"); uint rawRgbColors[RGBAlgorithmRawColorCount] = { - QColor(Qt::red).rgb(), - uint(0) + QColor(Qt::red).rgb(), + uint(0) }; s.rgbMap(QSize(3, 4), 0, 0, map, rawRgbColors); // verify that an array within an array has been returned @@ -273,10 +273,10 @@ void RGBScript_Test::runScripts() QSize mapSize = QSize(7, 11); // Use different numbers for x and y for the test QSize mapSizePlus = QSize(12, 22); // Prepare a larger matrix to check behaviour on matrix change uint rawRgbColors[RGBAlgorithmRawColorCount] = { - // QColor(Qt::red).rgb() is 0xffff0000 due to the alpha channel - // This test also wants to test that there is no color space overrun. - QColor(Qt::red).rgb() & 0xffffff, - uint(0) + // QColor(Qt::red).rgb() is 0xffff0000 due to the alpha channel + // This test also wants to test that there is no color space overrun. + QColor(Qt::red).rgb() & 0xffffff, + uint(0) }; // Iterate the list of scripts @@ -366,7 +366,7 @@ void RGBScript_Test::runScripts() { if (s.acceptColors() > 0) { - // verify that the alpha channel is zero + // verify that the alpha channel is zero if (rgbMap[y][x] > 0x00ffffff) { uint pxr = (rgbMap[y][x] >> 16 & 0x000000ff); diff --git a/engine/test/rgbtext/rgbtext_test.cpp b/engine/test/rgbtext/rgbtext_test.cpp index 0fa478ef0e..41613c9394 100644 --- a/engine/test/rgbtext/rgbtext_test.cpp +++ b/engine/test/rgbtext/rgbtext_test.cpp @@ -325,8 +325,8 @@ void RGBText_Test::staticLetters() QRgb color(0xFFFFFFFF); RGBMap map; uint rawRgbColors[RGBAlgorithmRawColorCount] = { - QColor(Qt::red).rgb(), - QColor(Qt::green).rgb() + QColor(Qt::red).rgb(), + QColor(Qt::green).rgb() }; // Since fonts and their rendering differs from installation to installation, @@ -367,8 +367,8 @@ void RGBText_Test::horizontalScroll() text.setText("QLC"); text.setAnimationStyle(RGBText::Horizontal); uint rawRgbColors[RGBAlgorithmRawColorCount] = { - QColor(Qt::red).rgb(), - QColor(Qt::green).rgb() + QColor(Qt::red).rgb(), + QColor(Qt::green).rgb() }; QFontMetrics fm(text.font()); @@ -419,8 +419,8 @@ void RGBText_Test::verticalScroll() text.setText("QLC"); text.setAnimationStyle(RGBText::Vertical); uint rawRgbColors[RGBAlgorithmRawColorCount] = { - QColor(Qt::red).rgb(), - QColor(Qt::green).rgb() + QColor(Qt::red).rgb(), + QColor(Qt::green).rgb() }; QFontMetrics fm(text.font()); diff --git a/resources/rgbscripts/ballscolors.js b/resources/rgbscripts/ballscolors.js index 80e847f5e1..56598ecaa9 100644 --- a/resources/rgbscripts/ballscolors.js +++ b/resources/rgbscripts/ballscolors.js @@ -24,38 +24,38 @@ var testAlgo; function () { var colorPalette = new Object; colorPalette.collection = new Array( - ["White" , 0xFFFFFF], // 0 - ["Cream" , 0xFFFF7F], // 1 - ["Pink" , 0xFF7F7F], // 2 - ["Rose" , 0x7F3F3F], // 3 - ["Coral" , 0x7F3F1F], // 4 - ["Dim Red" , 0x7F0000], // 5 - ["Red" , 0xFF0000], // 6 - ["Orange" , 0xFF3F00], // 7 - ["Dim Orange" , 0x7F1F00], // 8 - ["Goldenrod" , 0x7F3F00], // 9 - ["Gold" , 0xFF7F00], // 10 - ["Yellow" , 0xFFFF00], // 11 - ["Dim Yellow" , 0x7F7F00], // 12 - ["Lime" , 0x7FFF00], // 13 - ["Pale Green" , 0x3F7F00], // 14 - ["Dim Green" , 0x007F00], // 15 - ["Green" , 0x00FF00], // 16 - ["Seafoam" , 0x00FF3F], // 17 - ["Turquoise" , 0x007F3F], // 18 - ["Teal" , 0x007F7F], // 19 - ["Cyan" , 0x00FFFF], // 20 - ["Electric Blue", 0x007FFF], // 21 - ["Blue" , 0x0000FF], // 22 - ["Dim Blue" , 0x00007F], // 23 - ["Pale Blue" , 0x1F1F7F], // 24 - ["Indigo" , 0x1F00BF], // 25 - ["Purple" , 0x3F00BF], // 26 - ["Violet" , 0x7F007F], // 27 - ["Magenta" , 0xFF00FF], // 28 - ["Hot Pink" , 0xFF003F], // 29 - ["Deep Pink" , 0x7F001F], // 30 - ["Black" , 0x000000]); // 31 + ["White" , 0xFFFFFF], // 0 + ["Cream" , 0xFFFF7F], // 1 + ["Pink" , 0xFF7F7F], // 2 + ["Rose" , 0x7F3F3F], // 3 + ["Coral" , 0x7F3F1F], // 4 + ["Dim Red" , 0x7F0000], // 5 + ["Red" , 0xFF0000], // 6 + ["Orange" , 0xFF3F00], // 7 + ["Dim Orange" , 0x7F1F00], // 8 + ["Goldenrod" , 0x7F3F00], // 9 + ["Gold" , 0xFF7F00], // 10 + ["Yellow" , 0xFFFF00], // 11 + ["Dim Yellow" , 0x7F7F00], // 12 + ["Lime" , 0x7FFF00], // 13 + ["Pale Green" , 0x3F7F00], // 14 + ["Dim Green" , 0x007F00], // 15 + ["Green" , 0x00FF00], // 16 + ["Seafoam" , 0x00FF3F], // 17 + ["Turquoise" , 0x007F3F], // 18 + ["Teal" , 0x007F7F], // 19 + ["Cyan" , 0x00FFFF], // 20 + ["Electric Blue", 0x007FFF], // 21 + ["Blue" , 0x0000FF], // 22 + ["Dim Blue" , 0x00007F], // 23 + ["Pale Blue" , 0x1F1F7F], // 24 + ["Indigo" , 0x1F00BF], // 25 + ["Purple" , 0x3F00BF], // 26 + ["Violet" , 0x7F007F], // 27 + ["Magenta" , 0xFF00FF], // 28 + ["Hot Pink" , 0xFF003F], // 29 + ["Deep Pink" , 0x7F001F], // 30 + ["Black" , 0x000000]); // 31 colorPalette.makeSubArray = function (_index) { var _array = new Array(); @@ -206,7 +206,7 @@ var testAlgo; algo.colour[i] = algo.getRawColor(rawColors, i); } - var map = new Array(height); // Clear map data + var map = new Array(height); // Clear map data for (var y = 0; y < height; y++) { map[y] = new Array(); @@ -231,7 +231,7 @@ var testAlgo; for (var rx = mx - boxSize; rx < mx + boxSize + 2; rx++) { // to display ball if (rx < width && rx > -1 && ry < height && ry > -1) { // if edges are off the map dont draw - var pointRGB = map[ry][rx]; // get curent colour on the map + var pointRGB = map[ry][rx]; // get curent colour on the map var pointr = (pointRGB >> 16) & 0x00FF;// so that colours mix and don't over var pointg = (pointRGB >> 8) & 0x00FF; // write. var pointb = pointRGB & 0x00FF; // splt rgb in to components From 7a43f123a380da305ee230ed9e6799a8edfb420d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Thu, 20 Apr 2023 20:11:42 +0200 Subject: [PATCH 18/63] Fix reasonable Codacy remarks. --- resources/rgbscripts/plasmacolors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/rgbscripts/plasmacolors.js b/resources/rgbscripts/plasmacolors.js index 72f6fb6e9b..b49306793a 100644 --- a/resources/rgbscripts/plasmacolors.js +++ b/resources/rgbscripts/plasmacolors.js @@ -224,7 +224,7 @@ var testAlgo; for (var i = 0; i < util.colorArray.length; i++) { var sColor = util.colorArray[i]; - var eColor = util.colorArray[0];; + var eColor = util.colorArray[0]; if (i < util.colorArray.length - 1) { eColor = util.colorArray[i + 1]; } @@ -349,7 +349,7 @@ var testAlgo; algo.rgbMap = function(width, height, rgb, step, rawColors) { - if (util.colorArray.length == 0) { + if (util.colorArray.length === 0) { util.initialized = false; } else if (util.colorArray.length >= algo.acceptColors - 1 && Array.isArray(rawColors)) { // Check if the externally provided color has changed. From 55b36b060ae3216492b9f3e9a8551616b2011126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Wed, 26 Apr 2023 22:34:08 +0200 Subject: [PATCH 19/63] Use the second raw Color for the highlights in marquee.js Also fix several off-by-one errors, such as the edges being out of sync and evaluation of integer properties. Also let the marquee color take effect and not just add to the existing RGB values. --- resources/rgbscripts/marquee.js | 122 ++++++++------------------------ 1 file changed, 30 insertions(+), 92 deletions(-) diff --git a/resources/rgbscripts/marquee.js b/resources/rgbscripts/marquee.js index 5266056c80..5e76a135c6 100644 --- a/resources/rgbscripts/marquee.js +++ b/resources/rgbscripts/marquee.js @@ -21,59 +21,11 @@ var testAlgo; (function () { - var colorPalette = new Object(); - colorPalette.collection = new Array( - ["White" , 0xFFFFFF], - ["LightGrey" , 0xAAAAAA], - ["MediumGrey" , 0x999999], - ["DarkGrey" , 0x666666], - ["Cream" , 0xFFFF7F], - ["Pink" , 0xFF7F7F], - ["Rose" , 0x7F3F3F], - ["Coral" , 0x7F3F1F], - ["Dim Red" , 0x7F0000], - ["Red" , 0xFF0000], - ["Orange" , 0xFF3F00], - ["Dim Orange" , 0x7F1F00], - ["Goldenrod" , 0x7F3F00], - ["Gold" , 0xFF7F00], - ["Yellow" , 0xFFFF00], - ["Dim Yellow" , 0x7F7F00], - ["Lime" , 0x7FFF00], - ["Pale Green" , 0x3F7F00], - ["Dim Green" , 0x007F00], - ["Green" , 0x00FF00], - ["Seafoam" , 0x00FF3F], - ["Turquoise" , 0x007F3F], - ["Teal" , 0x007F7F], - ["Cyan" , 0x00FFFF], - ["Electric Blue", 0x007FFF], - ["Blue" , 0x0000FF], - ["Dim Blue" , 0x00007F], - ["Pale Blue" , 0x1F1F7F], - ["Indigo" , 0x1F00BF], - ["Purple" , 0x3F00BF], - ["Violet" , 0x7F007F], - ["Magenta" , 0xFF00FF], - ["Hot Pink" , 0xFF003F], - ["Deep Pink" , 0x7F001F], - ["Black" , 0x000000] - ); - - colorPalette.makeSubArray = function (_index) { - var _array = new Array(); - for (var i = 0; i < colorPalette.collection.length; i++) { - _array.push(colorPalette.collection[i][_index]); - } - return _array; - }; - colorPalette.names = colorPalette.makeSubArray(0); - var algo = new Object(); - algo.apiVersion = 2; + algo.apiVersion = 3; algo.name = "Marquee"; algo.author = "Branson Matheson"; - algo.acceptColors = 1; + algo.acceptColors = 2; algo.properties = new Array(); algo.edgeDepth = 2; algo.properties.push( @@ -87,14 +39,6 @@ var testAlgo; algo.properties.push( "name:marqueeCount|type:range|display:Marquee Spaces|values:1,10|write:setMarqueeCount|read:getMarqueeCount" ); - algo.marqueeColorIndex = 0; - algo.properties.push( - "name:marqueColor|type:list|display:Marquee Light Color|" + - "values:" + - colorPalette.names.toString() + - "|" + - "write:setMarqueeColorIndex|read:getMarqueeColorIndex" - ); var util = new Object(); util.initialized = false; @@ -106,7 +50,7 @@ var testAlgo; util.feature = new Array(); algo.setDepth = function (_amount) { - algo.edgeDepth = _amount; + algo.edgeDepth = parseInt(_amount, 10); util.initialized = false; }; @@ -140,7 +84,7 @@ var testAlgo; }; algo.setMarqueeCount = function (_amount) { - algo.marqueeCount = _amount; + algo.marqueeCount = parseInt(_amount, 10); util.initialized = false; }; @@ -148,16 +92,7 @@ var testAlgo; return algo.marqueeCount; }; - algo.setMarqueeColorIndex = function (_preset) { - algo.marqueeColorIndex = colorPalette.names.indexOf(_preset); - util.initialized = false; - }; - - algo.getMarqueeColorIndex = function () { - return colorPalette.collection[algo.marqueeColorIndex][0]; - }; - - util.initialize = function (width, height, rgb) { + util.initialize = function (width, height, rawColors) { // initialize feature util.feature = new Array(); for (var y = 0; y <= height - 1; y++) { @@ -182,21 +117,21 @@ var testAlgo; distance = Math.min(x_distance, y_distance); if (distance <= algo.edgeDepth) { var percent = ((algo.edgeDepth - distance) / algo.edgeDepth) * 100; - util.feature[y][x] = util.fadeColor(rgb, percent); + util.feature[y][x] = util.fadeColor(algo.getRawColor(rawColors, 0), percent); } else { util.feature[y][x] = 0; } } } - // initialize lights array - var length = height * 2 + width * 2; - util.lights = new Array(length + algo.marqueeCount + 1); - var count = algo.marqueeCount; - count++; - for (var i = length + count + 1; i >= 0; i--) { - util.lights[i] = 0; - if (i % count === 1) { + // initialize lights array: 2 heights, 2 widths, 4 duplicate corner pixels + var length = height * 2 + width * 2 - 4; + var count = length + parseInt(algo.marqueeCount, 10) + 1; + util.lights = new Array(count); + for (var i = 0; i < count; i++) { + if (i % (parseInt(algo.marqueeCount, 10) + 1) === 0) { util.lights[i] = 1; + } else { + util.lights[i] = 0; } } // for testing for change @@ -238,7 +173,7 @@ var testAlgo; return (r << 16) + (g << 8) + b; }; - util.getNextStep = function (width, height, step) { + util.getNextStep = function (width, height, rawColors) { var map = new Array(height); for (var y = 0; y <= height - 1; y++) { map[y] = new Array(width); @@ -258,7 +193,7 @@ var testAlgo; } // create light map add lights, go around the outside - var marqueeColor = colorPalette.collection[algo.marqueeColorIndex][1]; + var marqueeColor = algo.getRawColor(rawColors, 1); var p = 0; // left for (var y = 0; y < height; y++) { @@ -269,7 +204,7 @@ var testAlgo; p += 1; } // bottom - for (var x = 0; x < width; x++) { + for (var x = 1; x < width; x++) { var y = height - 1; if (util.lights[p] === 1) { map[y][x] = marqueeColor; @@ -277,7 +212,7 @@ var testAlgo; p += 1; } // right - for (var y = height - 1; y >= 0; y--) { + for (var y = height - 2; y >= 0; y--) { var x = width - 1; if (util.lights[p] === 1) { map[y][x] = marqueeColor; @@ -285,30 +220,33 @@ var testAlgo; p += 1; } // top - for (var x = width - 1; x >= 0; x--) { + for (var x = width - 2; x >= 0; x--) { var y = 0; if (util.lights[p] === 1) { map[y][x] = marqueeColor; } p += 1; } - for (var y = 0; y <= height - 1; y++) { - for (var x = 0; x <= width - 1; x++) { - map[y][x] = util.mergeRgb(map[y][x], util.feature[y][x]); - } - } return map; }; - algo.rgbMap = function (width, height, rgb, step) { + algo.getRawColor = function (rawColors, idx) { + if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { + return rawColors[idx]; + } else { + return 0; + } + } + + algo.rgbMap = function(width, height, rgb, step, rawColors) { if ( util.initialized === false || util.width !== width || util.height !== height ) { - util.initialize(width, height, rgb); + util.initialize(width, height, rawColors); } - var map = util.getNextStep(width, height, step); + var map = util.getNextStep(width, height, rawColors); return map; }; From 486bf924110614c8ab79ffd1d296623c8194252f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Wed, 26 Apr 2023 23:45:55 +0200 Subject: [PATCH 20/63] Initialize background feature when the color changes. --- resources/rgbscripts/marquee.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/resources/rgbscripts/marquee.js b/resources/rgbscripts/marquee.js index 5e76a135c6..219cccaa4e 100644 --- a/resources/rgbscripts/marquee.js +++ b/resources/rgbscripts/marquee.js @@ -44,6 +44,7 @@ var testAlgo; util.initialized = false; util.width = 0; util.height = 0; + util.featureColor = 0; util.step = algo.marqueeCount; util.lights = new Array(); @@ -94,6 +95,7 @@ var testAlgo; util.initialize = function (width, height, rawColors) { // initialize feature + util.featureColor = algo.getRawColor(rawColors, 0); util.feature = new Array(); for (var y = 0; y <= height - 1; y++) { util.feature[y] = new Array(); @@ -117,12 +119,13 @@ var testAlgo; distance = Math.min(x_distance, y_distance); if (distance <= algo.edgeDepth) { var percent = ((algo.edgeDepth - distance) / algo.edgeDepth) * 100; - util.feature[y][x] = util.fadeColor(algo.getRawColor(rawColors, 0), percent); + util.feature[y][x] = util.fadeColor(util.featureColor, percent); } else { util.feature[y][x] = 0; } } } + // initialize lights array: 2 heights, 2 widths, 4 duplicate corner pixels var length = height * 2 + width * 2 - 4; var count = length + parseInt(algo.marqueeCount, 10) + 1; @@ -240,12 +243,14 @@ var testAlgo; algo.rgbMap = function(width, height, rgb, step, rawColors) { if ( - util.initialized === false || - util.width !== width || - util.height !== height + util.width !== width || + util.height !== height || + util.featureColor != algo.getRawColor(rawColors, 0) || + util.initialized === false ) { util.initialize(width, height, rawColors); } + var map = util.getNextStep(width, height, rawColors); return map; }; From 1dbf566e571d7f05b1beb839baf261b084099063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Thu, 27 Apr 2023 07:53:31 +0200 Subject: [PATCH 21/63] Recalculate & reset marquee only on dimension change. --- resources/rgbscripts/marquee.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/resources/rgbscripts/marquee.js b/resources/rgbscripts/marquee.js index 219cccaa4e..5550c2851c 100644 --- a/resources/rgbscripts/marquee.js +++ b/resources/rgbscripts/marquee.js @@ -127,14 +127,17 @@ var testAlgo; } // initialize lights array: 2 heights, 2 widths, 4 duplicate corner pixels - var length = height * 2 + width * 2 - 4; - var count = length + parseInt(algo.marqueeCount, 10) + 1; - util.lights = new Array(count); - for (var i = 0; i < count; i++) { - if (i % (parseInt(algo.marqueeCount, 10) + 1) === 0) { - util.lights[i] = 1; - } else { - util.lights[i] = 0; + // only if the dimensions have changes (not on color change) + if (util.width != width || util.height != height) { + var length = height * 2 + width * 2 - 4; + var count = length + parseInt(algo.marqueeCount, 10) + 1; + util.lights = new Array(count); + for (var i = 0; i < count; i++) { + if (i % (parseInt(algo.marqueeCount, 10) + 1) === 0) { + util.lights[i] = 1; + } else { + util.lights[i] = 0; + } } } // for testing for change From ffc2b85f09fbef89562a6ce612c5fe2db36244eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Thu, 27 Apr 2023 08:39:27 +0200 Subject: [PATCH 22/63] remove unused function --- resources/rgbscripts/marquee.js | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/resources/rgbscripts/marquee.js b/resources/rgbscripts/marquee.js index 5550c2851c..0aa95b04ab 100644 --- a/resources/rgbscripts/marquee.js +++ b/resources/rgbscripts/marquee.js @@ -157,28 +157,6 @@ var testAlgo; return newRGB; }; - util.mergeRgb = function (rgb1, rgb2) { - if (rgb1 === 0) { - return rgb2; - } else if (rgb2 === 0) { - return rgb1; - } - // split rgb into components - var r1 = (rgb1 >> 16) & 0x00ff; - var g1 = (rgb1 >> 8) & 0x00ff; - var b1 = rgb1 & 0x00ff; - - var r2 = (rgb2 >> 16) & 0x00ff; - var g2 = (rgb2 >> 8) & 0x00ff; - var b2 = rgb2 & 0x00ff; - - var r = Math.max(r1, r2); - var g = Math.max(g1, g2); - var b = Math.max(b1, b2); - - return (r << 16) + (g << 8) + b; - }; - util.getNextStep = function (width, height, rawColors) { var map = new Array(height); for (var y = 0; y <= height - 1; y++) { From 03200b0c76e957e0e7e7800bb9a14f561c905afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Thu, 27 Apr 2023 19:31:08 +0200 Subject: [PATCH 23/63] Initialize the marquee also when pattern width changes. --- resources/rgbscripts/marquee.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/rgbscripts/marquee.js b/resources/rgbscripts/marquee.js index 0aa95b04ab..022d7c2b2a 100644 --- a/resources/rgbscripts/marquee.js +++ b/resources/rgbscripts/marquee.js @@ -128,9 +128,9 @@ var testAlgo; // initialize lights array: 2 heights, 2 widths, 4 duplicate corner pixels // only if the dimensions have changes (not on color change) - if (util.width != width || util.height != height) { + if (util.width != width || util.height != height || util.initialized !== true) { var length = height * 2 + width * 2 - 4; - var count = length + parseInt(algo.marqueeCount, 10) + 1; + var count = length + algo.marqueeCount + 1; util.lights = new Array(count); for (var i = 0; i < count; i++) { if (i % (parseInt(algo.marqueeCount, 10) + 1) === 0) { @@ -224,10 +224,10 @@ var testAlgo; algo.rgbMap = function(width, height, rgb, step, rawColors) { if ( - util.width !== width || - util.height !== height || - util.featureColor != algo.getRawColor(rawColors, 0) || - util.initialized === false + util.initialized === false || + util.featureColor != algo.getRawColor(rawColors, 0) || + util.width !== width || + util.height !== height ) { util.initialize(width, height, rawColors); } From 7d0fdb94044c14a1607cc3b0c4ec00fb2cd2644d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Thu, 14 Sep 2023 07:38:22 +0200 Subject: [PATCH 24/63] Fix Windows build of tests --- engine/test/rgbscript/rgbscript_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/test/rgbscript/rgbscript_test.cpp b/engine/test/rgbscript/rgbscript_test.cpp index ac5d5ebaaa..9a28b2a2b5 100644 --- a/engine/test/rgbscript/rgbscript_test.cpp +++ b/engine/test/rgbscript/rgbscript_test.cpp @@ -218,7 +218,7 @@ void RGBScript_Test::rgbMapColorArray() QColor(Qt::green).rgb() & 0x00ffffff }; QSize mapSize = QSize(5, 5); - qDebug() << "C1: " << hex << rawRgbColors[0] << " C2: " << hex << rawRgbColors[1]; + qDebug() << "C1: " << Qt::hex << rawRgbColors[0] << " C2: " << Qt::hex << rawRgbColors[1]; s.rgbMap(mapSize, 0, 0, map, rawRgbColors); QVERIFY(map.isEmpty() == false); @@ -227,7 +227,7 @@ void RGBScript_Test::rgbMapColorArray() { for (int x = 0; x < mapSize.width(); x++) { - // qDebug() << "y: " << y << " x: " << x << " C: " << hex << map[y][x]; + // qDebug() << "y: " << y << " x: " << x << " C: " << Qt::hex << map[y][x]; if (x % 2 == 0) QCOMPARE(map[y][x], rawRgbColors[1]); else From e8f0e12f07a7267fc87c0afc70fb714bc8b23a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Thu, 16 Nov 2023 20:41:45 +0100 Subject: [PATCH 25/63] Implement five colors support in ui code. --- engine/src/rgbalgorithm.h | 2 +- engine/src/rgbmatrix.cpp | 20 +- qmlui/rgbmatrixeditor.cpp | 5 +- resources/rgbscripts/ballscolors.js | 104 +---- resources/rgbscripts/plasmacolors.js | 133 +----- ui/src/rgbmatrixeditor.cpp | 246 ++++++++-- ui/src/rgbmatrixeditor.h | 12 +- ui/src/rgbmatrixeditor.ui | 109 ++++- ui/src/virtualconsole/vcmatrix.cpp | 449 ++++++++++++++++--- ui/src/virtualconsole/vcmatrix.h | 30 +- ui/src/virtualconsole/vcmatrixcontrol.cpp | 70 ++- ui/src/virtualconsole/vcmatrixcontrol.h | 21 +- ui/src/virtualconsole/vcmatrixproperties.cpp | 236 ++++++++-- ui/src/virtualconsole/vcmatrixproperties.h | 19 +- ui/src/virtualconsole/vcmatrixproperties.ui | 140 +++++- 15 files changed, 1167 insertions(+), 429 deletions(-) diff --git a/engine/src/rgbalgorithm.h b/engine/src/rgbalgorithm.h index 323eca9e14..a0eef212df 100644 --- a/engine/src/rgbalgorithm.h +++ b/engine/src/rgbalgorithm.h @@ -40,7 +40,7 @@ typedef QVector > RGBMap; #define KXMLQLCRGBAlgorithm QString("Algorithm") #define KXMLQLCRGBAlgorithmType QString("Type") -#define RGBAlgorithmRawColorCount 2 +#define RGBAlgorithmRawColorCount 5 class RGBAlgorithm { diff --git a/engine/src/rgbmatrix.cpp b/engine/src/rgbmatrix.cpp index 67cc89a913..8b072b89be 100644 --- a/engine/src/rgbmatrix.cpp +++ b/engine/src/rgbmatrix.cpp @@ -281,10 +281,13 @@ void RGBMatrix::previewMap(int step, RGBMatrixStep *handler) m_group = doc()->fixtureGroup(fixtureGroup()); if (m_group != NULL) { - Q_ASSERT(2 == RGBAlgorithmRawColorCount); + Q_ASSERT(5 == RGBAlgorithmRawColorCount); uint rawColors[] = { - m_rgbColors[0].rgb(), - m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0}; + m_rgbColors[0].rgb() + ,m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0 + ,m_rgbColors[2].isValid() ? m_rgbColors[2].rgb() : 0 + ,m_rgbColors[3].isValid() ? m_rgbColors[3].rgb() : 0 + ,m_rgbColors[4].isValid() ? m_rgbColors[4].rgb() : 0}; m_algorithm->rgbMap(m_group->size(), handler->stepColor().rgb(), step, handler->m_map, rawColors); } } @@ -394,7 +397,7 @@ bool RGBMatrix::loadXML(QXmlStreamReader &root) { loadXMLRunOrder(root); } -#if (2 != RGBAlgorithmRawColorCount) +#if (5 != RGBAlgorithmRawColorCount) #error "Further colors need to be read." #endif else if (root.name() == KXMLQLCRGBMatrixStartColor) @@ -463,7 +466,7 @@ bool RGBMatrix::saveXML(QXmlStreamWriter *doc) /* End Color */ if (getColor(1).isValid()) doc->writeTextElement(KXMLQLCRGBMatrixEndColor, QString::number(getColor(1).rgb())); -#if (2 != RGBAlgorithmRawColorCount) +#if (5 != RGBAlgorithmRawColorCount) #error "Further colors need to be written." #endif @@ -573,10 +576,13 @@ void RGBMatrix::write(MasterTimer *timer, QList universes) if (tempoType() == Beats) m_stepBeatDuration = beatsToTime(duration(), timer->beatTimeDuration()); - Q_ASSERT(2 == RGBAlgorithmRawColorCount); + Q_ASSERT(5 == RGBAlgorithmRawColorCount); uint rawColors[] = { m_rgbColors[0].rgb() - ,m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0}; + ,m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0 + ,m_rgbColors[2].isValid() ? m_rgbColors[2].rgb() : 0 + ,m_rgbColors[3].isValid() ? m_rgbColors[3].rgb() : 0 + ,m_rgbColors[4].isValid() ? m_rgbColors[4].rgb() : 0}; //qDebug() << "RGBMatrix step" << m_stepHandler->currentStepIndex() << ", color:" << QString::number(m_stepHandler->stepColor().rgb(), 16); m_algorithm->rgbMap(m_group->size(), m_stepHandler->stepColor().rgb(), m_stepHandler->currentStepIndex(), m_stepHandler->m_map, rawColors); diff --git a/qmlui/rgbmatrixeditor.cpp b/qmlui/rgbmatrixeditor.cpp index 281f1e70ff..4cb3819d13 100644 --- a/qmlui/rgbmatrixeditor.cpp +++ b/qmlui/rgbmatrixeditor.cpp @@ -136,7 +136,10 @@ void RGBMatrixEditor::setAlgorithmIndex(int algoIndex) return; QColor colors[RGBAlgorithmRawColorCount] = { m_matrix->getColor(0), - m_matrix->getColor(1) + m_matrix->getColor(1), + m_matrix->getColor(2), + m_matrix->getColor(3), + m_matrix->getColor(4) }; algo->setColors(colors); } diff --git a/resources/rgbscripts/ballscolors.js b/resources/rgbscripts/ballscolors.js index 56598ecaa9..2a3b7ed4ce 100644 --- a/resources/rgbscripts/ballscolors.js +++ b/resources/rgbscripts/ballscolors.js @@ -22,55 +22,11 @@ var testAlgo; ( function () { - var colorPalette = new Object; - colorPalette.collection = new Array( - ["White" , 0xFFFFFF], // 0 - ["Cream" , 0xFFFF7F], // 1 - ["Pink" , 0xFF7F7F], // 2 - ["Rose" , 0x7F3F3F], // 3 - ["Coral" , 0x7F3F1F], // 4 - ["Dim Red" , 0x7F0000], // 5 - ["Red" , 0xFF0000], // 6 - ["Orange" , 0xFF3F00], // 7 - ["Dim Orange" , 0x7F1F00], // 8 - ["Goldenrod" , 0x7F3F00], // 9 - ["Gold" , 0xFF7F00], // 10 - ["Yellow" , 0xFFFF00], // 11 - ["Dim Yellow" , 0x7F7F00], // 12 - ["Lime" , 0x7FFF00], // 13 - ["Pale Green" , 0x3F7F00], // 14 - ["Dim Green" , 0x007F00], // 15 - ["Green" , 0x00FF00], // 16 - ["Seafoam" , 0x00FF3F], // 17 - ["Turquoise" , 0x007F3F], // 18 - ["Teal" , 0x007F7F], // 19 - ["Cyan" , 0x00FFFF], // 20 - ["Electric Blue", 0x007FFF], // 21 - ["Blue" , 0x0000FF], // 22 - ["Dim Blue" , 0x00007F], // 23 - ["Pale Blue" , 0x1F1F7F], // 24 - ["Indigo" , 0x1F00BF], // 25 - ["Purple" , 0x3F00BF], // 26 - ["Violet" , 0x7F007F], // 27 - ["Magenta" , 0xFF00FF], // 28 - ["Hot Pink" , 0xFF003F], // 29 - ["Deep Pink" , 0x7F001F], // 30 - ["Black" , 0x000000]); // 31 - - colorPalette.makeSubArray = function (_index) { - var _array = new Array(); - for (var i = 0; i < colorPalette.collection.length; i++) { - _array.push(colorPalette.collection[i][_index]); - } - return _array; - }; - colorPalette.names = colorPalette.makeSubArray(0); - var algo = new Object; algo.apiVersion = 3; algo.name = "Balls (Colors)"; algo.author = "Rob Nieuwenhuizen"; - algo.acceptColors = 2; + algo.acceptColors = 5; algo.properties = new Array(); algo.presetSize = 1; algo.properties.push("name:presetSize|type:range|display:Size|values:1,20|write:setSize|read:getSize"); @@ -78,23 +34,6 @@ var testAlgo; algo.properties.push("name:presetNumber|type:range|display:Number|values:1,5|write:setNumber|read:getNumber"); algo.presetCollision = 0; algo.properties.push("name:presetCollision|type:list|display:Self Collision|values:No,Yes|write:setCollision|read:getCollision"); - algo.color1Rgb = 0xff0000; - algo.color2Rgb = 0x00ff00; - algo.color3Index = 16; - algo.properties.push( - "name:color3Index|type:list|display:Color 3|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor3|read:getColor3"); - algo.color4Index = 22; - algo.properties.push( - "name:color4Index|type:list|display:Color 4|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor4|read:getColor4"); - algo.color5Index = 7; - algo.properties.push( - "name:color5Index|type:list|display:Color 5|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor5|read:getColor5"); algo.presetSize = 5; algo.colorIndex = new Array( @@ -128,23 +67,6 @@ var testAlgo; else if (algo.presetCollision === 1) { return "No"; } }; - algo.setColor = function (_index, _preset) { - var i = colorPalette.names.indexOf(_preset); - if (i === -1) { - i = (colorPalette.collection.length - 1); - } - algo.colorIndex[_index - algo.acceptColors] = i; - return algo.colorIndex[_index - algo.acceptColors]; - }; - algo.getColor = function (_index) { - var i = algo.colorIndex[_index- algo.acceptColors]; - if (i < 0) { i = 0; } - if (i >= colorPalette.collection.length) { - i = (colorPalette.collection.length - 1); - } - return colorPalette.collection[i][0]; - }; - algo.getRawColor = function (rawColors, idx) { if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { return rawColors[idx]; @@ -153,30 +75,6 @@ var testAlgo; } } - algo.setColor3 = function (_preset) { - algo.color3Index = algo.setColor(2, _preset); - algo.initialized = false; - }; - algo.getColor3 = function () { - return algo.getColor(2); - }; - - algo.setColor4 = function (_preset) { - algo.color4Index = algo.setColor(3, _preset); - algo.initialized = false; - }; - algo.getColor4 = function () { - return algo.getColor(3); - }; - - algo.setColor5 = function (_preset) { - algo.color5Index = algo.setColor(4, _preset); - algo.initialized = false; - }; - algo.getColor5 = function () { - return algo.getColor(4); - }; - util.initialize = function (width, height) { algo.ball = new Array(algo.presetNumber); algo.direction = new Array(algo.presetNumber); diff --git a/resources/rgbscripts/plasmacolors.js b/resources/rgbscripts/plasmacolors.js index b49306793a..6cbce6d2e3 100644 --- a/resources/rgbscripts/plasmacolors.js +++ b/resources/rgbscripts/plasmacolors.js @@ -23,118 +23,21 @@ var testAlgo; ( function() { - var colorPalette = new Object; - colorPalette.collection = new Array( - ["White" , 0xFFFFFF], // 0 - ["Cream" , 0xFFFF7F], // 1 - ["Pink" , 0xFF7F7F], // 2 - ["Rose" , 0x7F3F3F], // 3 - ["Coral" , 0x7F3F1F], // 4 - ["Dim Red" , 0x7F0000], // 5 - ["Red" , 0xFF0000], // 6 - ["Orange" , 0xFF3F00], // 7 - ["Dim Orange" , 0x7F1F00], // 8 - ["Goldenrod" , 0x7F3F00], // 9 - ["Gold" , 0xFF7F00], // 10 - ["Yellow" , 0xFFFF00], // 11 - ["Dim Yellow" , 0x7F7F00], // 12 - ["Lime" , 0x7FFF00], // 13 - ["Pale Green" , 0x3F7F00], // 14 - ["Dim Green" , 0x007F00], // 15 - ["Green" , 0x00FF00], // 16 - ["Seafoam" , 0x00FF3F], // 17 - ["Turquoise" , 0x007F3F], // 18 - ["Teal" , 0x007F7F], // 19 - ["Cyan" , 0x00FFFF], // 20 - ["Electric Blue", 0x007FFF], // 21 - ["Blue" , 0x0000FF], // 22 - ["Dim Blue" , 0x00007F], // 23 - ["Pale Blue" , 0x1F1F7F], // 24 - ["Indigo" , 0x1F00BF], // 25 - ["Purple" , 0x3F00BF], // 26 - ["Violet" , 0x7F007F], // 27 - ["Magenta" , 0xFF00FF], // 28 - ["Hot Pink" , 0xFF003F], // 29 - ["Deep Pink" , 0x7F001F], // 30 - ["OFF" , 0x000000]); // 31 - - colorPalette.makeSubArray = function(_index) - { - var _array = new Array(); - for (var i = 0; i < colorPalette.collection.length; i++) - { - _array.push(colorPalette.collection[i][_index]); - } - return _array; - }; - colorPalette.names = colorPalette.makeSubArray(0); - var algo = new Object; algo.apiVersion = 3; algo.name = "Plasma (Colors)"; algo.author = "Nathan Durnan"; - algo.acceptColors = 2; + algo.acceptColors = 5; algo.properties = new Array(); algo.rstepcount = 0; algo.gstepcount = 50; algo.bstepcount = 100; - algo.color3Index = 16; - algo.properties.push( - "name:color3Index|type:list|display:Color 3|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor3|read:getColor3"); - algo.color4Index = 22; - algo.properties.push( - "name:color4Index|type:list|display:Color 4|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor4|read:getColor4"); - algo.color5Index = 31; - algo.properties.push( - "name:color5Index|type:list|display:Color 5|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor5|read:getColor5"); - algo.presetSize = 5; - algo.properties.push( - "name:presetSize|type:range|display:Size|" + - "values:1,20|write:setSize|read:getSize"); - algo.ramp = 20; - algo.properties.push( - "name:ramp|type:range|display:Ramp|" + - "values:10,30|write:setRamp|read:getRamp"); - algo.stepsize = 25; - algo.properties.push( - "name:stepsize|type:range|display:Speed|" + - "values:1,50|write:setStep|read:getStep"); - algo.colorIndex = new Array( - algo.color3Index, - algo.color4Index, - algo.color5Index); var util = new Object; util.initialized = false; util.gradientData = new Array(); util.colorArray = new Array(); - algo.setColor = function(_index, _preset) - { - var i = colorPalette.names.indexOf(_preset); - if (i === -1) { - i = (colorPalette.collection.length - 1); - } - algo.colorIndex[_index - algo.acceptColors] = i; - return algo.colorIndex[_index - algo.acceptColors]; - }; - - algo.getColor = function(_index) - { - var i = algo.colorIndex[_index - algo.acceptColors]; - if (i < 0) { i = 0; } - if (i >= colorPalette.collection.length) { - i = (colorPalette.collection.length - 1); - } - return colorPalette.collection[i][0]; - }; - algo.getRawColor = function (rawColors, idx) { if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { return rawColors[idx]; @@ -143,37 +46,6 @@ var testAlgo; } } - algo.setColor3 = function(_preset) - { - algo.color3Index = algo.setColor(2, _preset); - util.initialized = false; - }; - algo.getColor3 = function() - { - return algo.getColor(2); - }; - - algo.setColor4 = function(_preset) - { - algo.color4Index = algo.setColor(3, _preset); - util.initialized = false; - }; - algo.getColor4 = function() - { - return algo.getColor(3); - }; - - algo.setColor5 = function(_preset) - { - algo.color5Index = algo.setColor(4, _preset); - util.initialized = false; - }; - - algo.getColor5 = function() - { - return algo.getColor(4); - }; - algo.setSize = function(_size) { algo.presetSize = _size; @@ -213,9 +85,6 @@ var testAlgo; for (var i = 0; i < algo.acceptColors; i++) { util.colorArray[i] = algo.getRawColor(rawColors, i); } - for (var i = 0; i < algo.colorIndex.length; i++) { - util.colorArray[i + algo.acceptColors] = colorPalette.collection[algo.colorIndex[i]][1]; - } // calculate the gradient for the selected preset // with the given width diff --git a/ui/src/rgbmatrixeditor.cpp b/ui/src/rgbmatrixeditor.cpp index ebf8d824ed..fa77aa048a 100644 --- a/ui/src/rgbmatrixeditor.cpp +++ b/ui/src/rgbmatrixeditor.cpp @@ -175,13 +175,31 @@ void RGBMatrixEditor::init() QPixmap pm(50, 26); pm.fill(m_matrix->getColor(0)); - m_startColorButton->setIcon(QIcon(pm)); + m_mtxColor1Button->setIcon(QIcon(pm)); if (m_matrix->getColor(1).isValid()) pm.fill(m_matrix->getColor(1)); else pm.fill(Qt::transparent); - m_endColorButton->setIcon(QIcon(pm)); + m_mtxColor2Button->setIcon(QIcon(pm)); + + if (m_matrix->getColor(2).isValid()) + pm.fill(m_matrix->getColor(2)); + else + pm.fill(Qt::transparent); + m_mtxColor3Button->setIcon(QIcon(pm)); + + if (m_matrix->getColor(3).isValid()) + pm.fill(m_matrix->getColor(3)); + else + pm.fill(Qt::transparent); + m_mtxColor4Button->setIcon(QIcon(pm)); + + if (m_matrix->getColor(4).isValid()) + pm.fill(m_matrix->getColor(4)); + else + pm.fill(Qt::transparent); + m_mtxColor5Button->setIcon(QIcon(pm)); updateExtraOptions(); updateSpeedDials(); @@ -202,12 +220,24 @@ void RGBMatrixEditor::init() this, SLOT(slotBlendModeChanged(int))); connect(m_controlModeCombo, SIGNAL(activated(int)), this, SLOT(slotControlModeChanged(int))); - connect(m_startColorButton, SIGNAL(clicked()), - this, SLOT(slotStartColorButtonClicked())); - connect(m_endColorButton, SIGNAL(clicked()), - this, SLOT(slotEndColorButtonClicked())); - connect(m_resetEndColorButton, SIGNAL(clicked()), - this, SLOT(slotResetEndColorButtonClicked())); + connect(m_mtxColor1Button, SIGNAL(clicked()), + this, SLOT(slotMtxColorButton1Clicked())); + connect(m_mtxColor2Button, SIGNAL(clicked()), + this, SLOT(slotMtxColor2ButtonClicked())); + connect(m_resetMtxColor2Button, SIGNAL(clicked()), + this, SLOT(slotResetMtxColor2ButtonClicked())); + connect(m_mtxColor3Button, SIGNAL(clicked()), + this, SLOT(slotMtxColor2ButtonClicked())); + connect(m_resetMtxColor3Button, SIGNAL(clicked()), + this, SLOT(slotResetMtxColor2ButtonClicked())); + connect(m_mtxColor4Button, SIGNAL(clicked()), + this, SLOT(slotMtxColor2ButtonClicked())); + connect(m_resetMtxColor4Button, SIGNAL(clicked()), + this, SLOT(slotResetMtxColor2ButtonClicked())); + connect(m_mtxColor5Button, SIGNAL(clicked()), + this, SLOT(slotMtxColor2ButtonClicked())); + connect(m_resetMtxColor5Button, SIGNAL(clicked()), + this, SLOT(slotResetMtxColor2ButtonClicked())); connect(m_textEdit, SIGNAL(textEdited(const QString&)), this, SLOT(slotTextEdited(const QString&))); connect(m_fontButton, SIGNAL(clicked()), @@ -370,25 +400,76 @@ void RGBMatrixEditor::updateExtraOptions() int accColors = m_matrix->algorithm()->acceptColors(); if (accColors == 0) { - m_startColorButton->hide(); - m_endColorButton->hide(); - m_resetEndColorButton->hide(); + m_mtxColor1Button->hide(); + m_mtxColor2Button->hide(); + m_resetMtxColor2Button->hide(); + m_mtxColor3Button->hide(); + m_resetMtxColor3Button->hide(); + m_mtxColor4Button->hide(); + m_resetMtxColor4Button->hide(); + m_mtxColor5Button->hide(); + m_resetMtxColor5Button->hide(); m_blendModeLabel->hide(); m_blendModeCombo->hide(); } else { - m_startColorButton->show(); + m_mtxColor1Button->show(); if (accColors == 1 || m_blendModeCombo->currentIndex() == Universe::MaskBlend) { - m_endColorButton->hide(); - m_resetEndColorButton->hide(); + m_mtxColor2Button->hide(); + m_resetMtxColor2Button->hide(); + m_mtxColor3Button->hide(); + m_resetMtxColor3Button->hide(); + m_mtxColor4Button->hide(); + m_resetMtxColor4Button->hide(); + m_mtxColor5Button->hide(); + m_resetMtxColor5Button->hide(); + } + else if (accColors == 2) + { + m_mtxColor2Button->show(); + m_resetMtxColor2Button->show(); + m_mtxColor3Button->hide(); + m_resetMtxColor3Button->hide(); + m_mtxColor4Button->hide(); + m_resetMtxColor4Button->hide(); + m_mtxColor5Button->hide(); + m_resetMtxColor5Button->hide(); + } + else if (accColors == 3) + { + m_mtxColor2Button->show(); + m_resetMtxColor2Button->show(); + m_mtxColor3Button->show(); + m_resetMtxColor3Button->show(); + m_mtxColor4Button->hide(); + m_resetMtxColor4Button->hide(); + m_mtxColor5Button->hide(); + m_resetMtxColor5Button->hide(); + } + else if (accColors == 4) + { + m_mtxColor2Button->show(); + m_resetMtxColor2Button->show(); + m_mtxColor3Button->show(); + m_resetMtxColor3Button->show(); + m_mtxColor4Button->show(); + m_resetMtxColor4Button->show(); + m_mtxColor5Button->hide(); + m_resetMtxColor5Button->hide(); } - else // accColors > 1 + else { - m_endColorButton->show(); - m_resetEndColorButton->show(); + m_mtxColor2Button->show(); + m_resetMtxColor2Button->show(); + m_mtxColor3Button->show(); + m_resetMtxColor3Button->show(); + m_mtxColor4Button->show(); + m_resetMtxColor4Button->show(); + m_mtxColor5Button->show(); + m_resetMtxColor5Button->show(); } m_blendModeLabel->show(); m_blendModeCombo->show(); @@ -407,12 +488,21 @@ void RGBMatrixEditor::updateColors() { m_matrix->setColor(0, Qt::white); m_matrix->setColor(1, QColor()); + m_matrix->setColor(2, QColor()); + m_matrix->setColor(3, QColor()); + m_matrix->setColor(4, QColor()); m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); QPixmap pm(50, 26); pm.fill(Qt::white); - m_startColorButton->setIcon(QIcon(pm)); + m_mtxColor1Button->setIcon(QIcon(pm)); + + pm.fill(Qt::transparent); + m_mtxColor2Button->setIcon(QIcon(pm)); + m_mtxColor3Button->setIcon(QIcon(pm)); + m_mtxColor4Button->setIcon(QIcon(pm)); + m_mtxColor5Button->setIcon(QIcon(pm)); } else if (m_controlModeCombo->currentIndex() != RGBMatrix::ControlModeRgb) { @@ -420,7 +510,7 @@ void RGBMatrixEditor::updateColors() uchar gray = qGray(m_matrix->getColor(0).rgb()); QPixmap pm(50, 26); pm.fill(QColor(gray, gray, gray)); - m_startColorButton->setIcon(QIcon(pm)); + m_mtxColor1Button->setIcon(QIcon(pm)); m_matrix->setColor(0, QColor(gray, gray, gray)); if (accColors > 1) @@ -428,13 +518,35 @@ void RGBMatrixEditor::updateColors() // Convert endColor to grayscale for single color modes gray = qGray(m_matrix->getColor(1).rgb()); m_matrix->setColor(1, QColor(gray, gray, gray)); - if (m_matrix->getColor(1) == QColor()) pm.fill(Qt::transparent); else pm.fill(QColor(gray, gray, gray)); + m_mtxColor2Button->setIcon(QIcon(pm)); - m_endColorButton->setIcon(QIcon(pm)); + gray = qGray(m_matrix->getColor(2).rgb()); + m_matrix->setColor(2, QColor(gray, gray, gray)); + if (m_matrix->getColor(2) == QColor()) + pm.fill(Qt::transparent); + else + pm.fill(QColor(gray, gray, gray)); + m_mtxColor3Button->setIcon(QIcon(pm)); + + gray = qGray(m_matrix->getColor(3).rgb()); + m_matrix->setColor(3, QColor(gray, gray, gray)); + if (m_matrix->getColor(3) == QColor()) + pm.fill(Qt::transparent); + else + pm.fill(QColor(gray, gray, gray)); + m_mtxColor4Button->setIcon(QIcon(pm)); + + gray = qGray(m_matrix->getColor(4).rgb()); + m_matrix->setColor(4, QColor(gray, gray, gray)); + if (m_matrix->getColor(4) == QColor()) + pm.fill(Qt::transparent); + else + pm.fill(QColor(gray, gray, gray)); + m_mtxColor5Button->setIcon(QIcon(pm)); } m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); } @@ -442,7 +554,7 @@ void RGBMatrixEditor::updateColors() { QPixmap pm(50, 26); pm.fill(m_matrix->getColor(0)); - m_startColorButton->setIcon(QIcon(pm)); + m_mtxColor1Button->setIcon(QIcon(pm)); if (accColors > 1) { @@ -452,8 +564,25 @@ void RGBMatrixEditor::updateColors() pm.fill(Qt::transparent); else pm.fill(m_matrix->getColor(1)); + m_mtxColor2Button->setIcon(QIcon(pm)); - m_endColorButton->setIcon(QIcon(pm)); + if (m_matrix->getColor(2) == QColor()) + pm.fill(Qt::transparent); + else + pm.fill(m_matrix->getColor(2)); + m_mtxColor3Button->setIcon(QIcon(pm)); + + if (m_matrix->getColor(3) == QColor()) + pm.fill(Qt::transparent); + else + pm.fill(m_matrix->getColor(3)); + m_mtxColor4Button->setIcon(QIcon(pm)); + + if (m_matrix->getColor(4) == QColor()) + pm.fill(Qt::transparent); + else + pm.fill(m_matrix->getColor(4)); + m_mtxColor4Button->setIcon(QIcon(pm)); } } } @@ -679,7 +808,10 @@ void RGBMatrixEditor::slotPatternActivated(const QString& text) if (algo != NULL) { QColor colors[RGBAlgorithmRawColorCount] = { m_matrix->getColor(0), - m_matrix->getColor(1) + m_matrix->getColor(1), + m_matrix->getColor(2), + m_matrix->getColor(3), + m_matrix->getColor(4) }; algo->setColors(colors); } @@ -712,11 +844,11 @@ void RGBMatrixEditor::slotBlendModeChanged(int index) if (index == Universe::MaskBlend) { - m_startColorButton->setEnabled(false); + m_mtxColor1Button->setEnabled(false); } else { - m_startColorButton->setEnabled(true); + m_mtxColor1Button->setEnabled(true); } updateExtraOptions(); updateColors(); @@ -731,7 +863,7 @@ void RGBMatrixEditor::slotControlModeChanged(int index) slotRestartTest(); } -void RGBMatrixEditor::slotStartColorButtonClicked() +void RGBMatrixEditor::slotMtxColor1ButtonClicked() { QColor col = QColorDialog::getColor(m_matrix->getColor(0)); if (col.isValid() == true) @@ -742,7 +874,7 @@ void RGBMatrixEditor::slotStartColorButtonClicked() } } -void RGBMatrixEditor::slotEndColorButtonClicked() +void RGBMatrixEditor::slotMtxColor2ButtonClicked() { QColor col = QColorDialog::getColor(m_matrix->getColor(1)); if (col.isValid() == true) @@ -753,10 +885,64 @@ void RGBMatrixEditor::slotEndColorButtonClicked() } } -void RGBMatrixEditor::slotResetEndColorButtonClicked() +void RGBMatrixEditor::slotResetMtxColor2ButtonClicked() { m_matrix->setColor(1, QColor()); - m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); + updateColors(); + slotRestartTest(); +} + +void RGBMatrixEditor::slotMtxColor3ButtonClicked() +{ + QColor col = QColorDialog::getColor(m_matrix->getColor(2)); + if (col.isValid() == true) + { + m_matrix->setColor(2, col); + updateColors(); + slotRestartTest(); + } +} + +void RGBMatrixEditor::slotResetMtxColor3ButtonClicked() +{ + m_matrix->setColor(2, QColor()); + updateColors(); + slotRestartTest(); +} + +void RGBMatrixEditor::slotMtxColor4ButtonClicked() +{ + QColor col = QColorDialog::getColor(m_matrix->getColor(3)); + if (col.isValid() == true) + { + m_matrix->setColor(3, col); + updateColors(); + slotRestartTest(); + } +} + +void RGBMatrixEditor::slotResetMtxColor4ButtonClicked() +{ + m_matrix->setColor(3, QColor()); + updateColors(); + slotRestartTest(); +} + +void RGBMatrixEditor::slotMtxColor5ButtonClicked() +{ + QColor col = QColorDialog::getColor(m_matrix->getColor(4)); + if (col.isValid() == true) + { + m_matrix->setColor(4, col); + updateColors(); + slotRestartTest(); + } +} + +void RGBMatrixEditor::slotResetMtxColor5ButtonClicked() +{ + m_matrix->setColor(4, QColor()); + m_previewHandler->calculateColorDelta(m_matrix->getColor(3), m_matrix->getColor(4)); updateColors(); slotRestartTest(); } diff --git a/ui/src/rgbmatrixeditor.h b/ui/src/rgbmatrixeditor.h index e8d471e848..6c421e6b1a 100644 --- a/ui/src/rgbmatrixeditor.h +++ b/ui/src/rgbmatrixeditor.h @@ -77,9 +77,15 @@ private slots: void slotFixtureGroupActivated(int index); void slotBlendModeChanged(int index); void slotControlModeChanged(int index); - void slotStartColorButtonClicked(); - void slotEndColorButtonClicked(); - void slotResetEndColorButtonClicked(); + void slotMtxColor1ButtonClicked(); + void slotMtxColor2ButtonClicked(); + void slotResetMtxColor2ButtonClicked(); + void slotMtxColor3ButtonClicked(); + void slotResetMtxColor3ButtonClicked(); + void slotMtxColor4ButtonClicked(); + void slotResetMtxColor4ButtonClicked(); + void slotMtxColor5ButtonClicked(); + void slotResetMtxColor5ButtonClicked(); void slotTextEdited(const QString& text); void slotFontButtonClicked(); diff --git a/ui/src/rgbmatrixeditor.ui b/ui/src/rgbmatrixeditor.ui index 2f3209edd7..4aedda5445 100644 --- a/ui/src/rgbmatrixeditor.ui +++ b/ui/src/rgbmatrixeditor.ui @@ -42,7 +42,7 @@ 5 - + @@ -68,10 +68,10 @@ 4 - - + + - Matrix start color + Matrix color 1 @@ -82,9 +82,9 @@ - + - Matrix end color + Matrix color 2 @@ -97,15 +97,59 @@ - - + + - The RGB matrix pattern + Reset the end color + + + + :/fileclose.png:/fileclose.png - - + + + + Matrix color 3 + + + + 50 + 26 + + + + + + + + Reset the end color + + + + :/fileclose.png:/fileclose.png + + + + + + + Matrix color 4 + + + + + + + 50 + 26 + + + + + + Reset the end color @@ -115,7 +159,38 @@ - + + + + Matrix color 5 + + + + 50 + 26 + + + + + + + + Reset the end color + + + + :/fileclose.png:/fileclose.png + + + + + + + The RGB matrix pattern + + + + @@ -153,7 +228,7 @@ - + @@ -311,7 +386,7 @@ - + @@ -421,7 +496,7 @@ - + @@ -451,7 +526,7 @@ - + @@ -561,7 +636,7 @@ - + diff --git a/ui/src/virtualconsole/vcmatrix.cpp b/ui/src/virtualconsole/vcmatrix.cpp index e89360da70..6dd99557fc 100644 --- a/ui/src/virtualconsole/vcmatrix.cpp +++ b/ui/src/virtualconsole/vcmatrix.cpp @@ -80,36 +80,89 @@ VCMatrix::VCMatrix(QWidget *parent, Doc *doc) QVBoxLayout *vbox = new QVBoxLayout(); - m_startColorButton = new QToolButton(this); - m_startColorButton->setFixedSize(48, 48); - m_startColorButton->setIconSize(QSize(42, 42)); + /* Start Color Button */ + m_mtxColorButton1 = new QToolButton(this); + m_mtxColorButton1->setFixedSize(48, 48); + m_mtxColorButton1->setIconSize(QSize(42, 42)); QWidgetAction* scAction = new QWidgetAction(this); - m_scCnGWidget = new ClickAndGoWidget(); - m_scCnGWidget->setType(ClickAndGoWidget::RGB, NULL); - scAction->setDefaultWidget(m_scCnGWidget); - QMenu *startColorMenu = new QMenu(); - startColorMenu->addAction(scAction); - m_startColorButton->setMenu(startColorMenu); - m_startColorButton->setPopupMode(QToolButton::InstantPopup); - - connect(m_scCnGWidget, SIGNAL(colorChanged(QRgb)), + m_mtxCnGWidget1 = new ClickAndGoWidget(); + m_mtxCnGWidget1->setType(ClickAndGoWidget::RGB, NULL); + scAction->setDefaultWidget(m_mtxCnGWidget1); + QMenu *color1Menu = new QMenu(); + color1Menu->addAction(scAction); + m_mtxColorButton1->setMenu(color1Menu); + m_mtxColorButton1->setPopupMode(QToolButton::InstantPopup); + + connect(m_mtxCnGWidget1, SIGNAL(colorChanged(QRgb)), this, SLOT(slotStartColorChanged(QRgb))); - m_endColorButton = new QToolButton(this); - m_endColorButton->setFixedSize(48, 48); - m_endColorButton->setIconSize(QSize(42, 42)); + /* End Color Button */ + m_mtxColorButton2 = new QToolButton(this); + m_mtxColorButton2->setFixedSize(48, 48); + m_mtxColorButton2->setIconSize(QSize(42, 42)); + + QWidgetAction* ecAction2 = new QWidgetAction(this); + m_mtxCnGWidget2 = new ClickAndGoWidget(); + m_mtxCnGWidget2->setType(ClickAndGoWidget::RGB, NULL); + ecAction2->setDefaultWidget(m_mtxCnGWidget2); + QMenu *color2Menu = new QMenu(); + color2Menu->addAction(ecAction2); + m_mtxColorButton2->setMenu(color2Menu); + m_mtxColorButton2->setPopupMode(QToolButton::InstantPopup); + + connect(m_mtxCnGWidget2, SIGNAL(colorChanged(QRgb)), + this, SLOT(slotEndColorChanged(QRgb))); + + /* 3rd Color Button */ + m_mtxColorButton3 = new QToolButton(this); + m_mtxColorButton3->setFixedSize(48, 48); + m_mtxColorButton3->setIconSize(QSize(42, 42)); + + QWidgetAction* ecAction3 = new QWidgetAction(this); + m_mtxCnGWidget3 = new ClickAndGoWidget(); + m_mtxCnGWidget3->setType(ClickAndGoWidget::RGB, NULL); + ecAction3->setDefaultWidget(m_mtxCnGWidget3); + QMenu *color3Menu = new QMenu(); + color3Menu->addAction(ecAction3); + m_mtxColorButton3->setMenu(color3Menu); + m_mtxColorButton3->setPopupMode(QToolButton::InstantPopup); + + connect(m_mtxCnGWidget3, SIGNAL(colorChanged(QRgb)), + this, SLOT(slotEndColorChanged(QRgb))); - QWidgetAction* ecAction = new QWidgetAction(this); - m_ecCnGWidget = new ClickAndGoWidget(); - m_ecCnGWidget->setType(ClickAndGoWidget::RGB, NULL); - ecAction->setDefaultWidget(m_ecCnGWidget); - QMenu *endColorMenu = new QMenu(); - endColorMenu->addAction(ecAction); - m_endColorButton->setMenu(endColorMenu); - m_endColorButton->setPopupMode(QToolButton::InstantPopup); + /* 4th Color Button */ + m_mtxColorButton4 = new QToolButton(this); + m_mtxColorButton4->setFixedSize(48, 48); + m_mtxColorButton4->setIconSize(QSize(42, 42)); + + QWidgetAction* ecAction4 = new QWidgetAction(this); + m_mtxCnGWidget4 = new ClickAndGoWidget(); + m_mtxCnGWidget4->setType(ClickAndGoWidget::RGB, NULL); + ecAction4->setDefaultWidget(m_mtxCnGWidget4); + QMenu *color4Menu = new QMenu(); + color4Menu->addAction(ecAction4); + m_mtxColorButton4->setMenu(color4Menu); + m_mtxColorButton4->setPopupMode(QToolButton::InstantPopup); + + connect(m_mtxCnGWidget4, SIGNAL(colorChanged(QRgb)), + this, SLOT(slotEndColorChanged(QRgb))); - connect(m_ecCnGWidget, SIGNAL(colorChanged(QRgb)), + /* 5th Color Button */ + m_mtxColorButton5 = new QToolButton(this); + m_mtxColorButton5->setFixedSize(48, 48); + m_mtxColorButton5->setIconSize(QSize(42, 42)); + + QWidgetAction* ecAction5 = new QWidgetAction(this); + m_mtxCnGWidget5 = new ClickAndGoWidget(); + m_mtxCnGWidget5->setType(ClickAndGoWidget::RGB, NULL); + ecAction5->setDefaultWidget(m_mtxCnGWidget5); + QMenu *color5Menu = new QMenu(); + color5Menu->addAction(ecAction5); + m_mtxColorButton5->setMenu(color5Menu); + m_mtxColorButton5->setPopupMode(QToolButton::InstantPopup); + + connect(m_mtxCnGWidget5, SIGNAL(colorChanged(QRgb)), this, SLOT(slotEndColorChanged(QRgb))); m_label = new QLabel(this); @@ -119,8 +172,11 @@ VCMatrix::VCMatrix(QWidget *parent, Doc *doc) QHBoxLayout *btnHbox = new QHBoxLayout(); - btnHbox->addWidget(m_startColorButton); - btnHbox->addWidget(m_endColorButton); + btnHbox->addWidget(m_mtxColorButton1); + btnHbox->addWidget(m_mtxColorButton2); + btnHbox->addWidget(m_mtxColorButton3); + btnHbox->addWidget(m_mtxColorButton4); + btnHbox->addWidget(m_mtxColorButton5); vbox->addLayout(btnHbox); @@ -225,8 +281,11 @@ void VCMatrix::setCaption(const QString &text) void VCMatrix::enableWidgetUI(bool enable) { m_slider->setEnabled(enable); - m_startColorButton->setEnabled(enable); - m_endColorButton->setEnabled(enable); + m_mtxColorButton1->setEnabled(enable); + m_mtxColorButton2->setEnabled(enable); + m_mtxColorButton3->setEnabled(enable); + m_mtxColorButton4->setEnabled(enable); + m_mtxColorButton5->setEnabled(enable); m_presetCombo->setEnabled(enable); foreach(QWidget *ctlBtn, m_controls.keys()) @@ -269,12 +328,12 @@ void VCMatrix::slotSliderMoved(int value) } } -void VCMatrix::slotStartColorChanged(QRgb color) +void VCMatrix::slotColorChanged1(QRgb color) { QColor col(color); QPixmap px(42, 42); px.fill(col); - m_startColorButton->setIcon(px); + m_mtxColorButton1->setIcon(px); RGBMatrix* matrix = qobject_cast(m_doc->function(m_matrixID)); if (matrix == NULL || mode() == Doc::Design) @@ -285,12 +344,60 @@ void VCMatrix::slotStartColorChanged(QRgb color) matrix->updateColorDelta(); } -void VCMatrix::slotEndColorChanged(QRgb color) +void VCMatrix::slotColorChanged2(QRgb color) +{ + QColor col(color); + QPixmap px(42, 42); + px.fill(col); + m_mtxColorButton2->setIcon(px); + + RGBMatrix* matrix = qobject_cast(m_doc->function(m_matrixID)); + if (matrix == NULL || mode() == Doc::Design) + return; + + matrix->setColor(1, col); + if (instantChanges() == true) + matrix->updateColorDelta(); +} + +void VCMatrix::slotColorChanged3(QRgb color) +{ + QColor col(color); + QPixmap px(42, 42); + px.fill(col); + m_mtxColorButton3->setIcon(px); + + RGBMatrix* matrix = qobject_cast(m_doc->function(m_matrixID)); + if (matrix == NULL || mode() == Doc::Design) + return; + + matrix->setColor(1, col); + if (instantChanges() == true) + matrix->updateColorDelta(); +} + +void VCMatrix::slotColorChanged4(QRgb color) +{ + QColor col(color); + QPixmap px(42, 42); + px.fill(col); + m_mtxColorButton4->setIcon(px); + + RGBMatrix* matrix = qobject_cast(m_doc->function(m_matrixID)); + if (matrix == NULL || mode() == Doc::Design) + return; + + matrix->setColor(1, col); + if (instantChanges() == true) + matrix->updateColorDelta(); +} + +void VCMatrix::slotColorChanged5(QRgb color) { QColor col(color); QPixmap px(42, 42); px.fill(col); - m_endColorButton->setIcon(px); + m_mtxColorButton5->setIcon(px); RGBMatrix* matrix = qobject_cast(m_doc->function(m_matrixID)); if (matrix == NULL || mode() == Doc::Design) @@ -321,11 +428,20 @@ void VCMatrix::setVisibilityMask(quint32 mask) if (mask & ShowLabel) m_label->show(); else m_label->hide(); - if (mask & ShowStartColorButton) m_startColorButton->show(); - else m_startColorButton->hide(); + if (mask & ShowColor1Button) m_mtxColorButton1->show(); + else m_mtxColorButton1->hide(); + + if (mask & ShowColor2Button) m_mtxColorButton2->show(); + else m_mtxColorButton2->hide(); + + if (mask & ShowColor3Button) m_mtxColorButton3->show(); + else m_mtxColorButton2->hide(); + + if (mask & ShowColor4Button) m_mtxColorButton3->show(); + else m_mtxColorButton2->hide(); - if (mask & ShowEndColorButton) m_endColorButton->show(); - else m_endColorButton->hide(); + if (mask & ShowColor5Button) m_mtxColorButton5->show(); + else m_mtxColorButton2->hide(); if (mask & ShowPresetCombo) m_presetCombo->show(); else m_presetCombo->hide(); @@ -342,9 +458,12 @@ quint32 VCMatrix::defaultVisibilityMask() { return ShowSlider | ShowLabel - | ShowStartColorButton - | ShowEndColorButton | ShowPresetCombo + | ShowColor1Button + | ShowColor2Button + | ShowColor3Button + | ShowColor4Button + | ShowColor5Button ; } @@ -487,12 +606,12 @@ void VCMatrix::slotUpdate() // Start / End color buttons QPixmap px(42, 42); px.fill(startColor); - m_startColorButton->setIcon(px); + m_mtxColorButton1->setIcon(px); if (endColor == QColor()) px.fill(Qt::transparent); else px.fill(endColor); - m_endColorButton->setIcon(px); + m_mtxColorButton2->setIcon(px); // Algo combo box if (algorithmName != QString()) @@ -509,26 +628,62 @@ void VCMatrix::slotUpdate() QWidget* widget = it.key(); VCMatrixControl* control = it.value(); - if (control->m_type == VCMatrixControl::StartColorKnob) + if (control->m_type == VCMatrixControl::Color1Knob) { KnobWidget* knob = reinterpret_cast(widget); knob->blockSignals(true); knob->setValue(control->rgbToValue(startColor.rgb())); knob->blockSignals(false); } - else if (control->m_type == VCMatrixControl::EndColorKnob) + else if (control->m_type == VCMatrixControl::Color2Knob) + { + KnobWidget* knob = reinterpret_cast(widget); + knob->blockSignals(true); + knob->setValue(control->rgbToValue(endColor.rgb())); + knob->blockSignals(false); + } + else if (control->m_type == VCMatrixControl::Color3Knob) + { + KnobWidget* knob = reinterpret_cast(widget); + knob->blockSignals(true); + knob->setValue(control->rgbToValue(endColor.rgb())); + knob->blockSignals(false); + } + else if (control->m_type == VCMatrixControl::Color4Knob) + { + KnobWidget* knob = reinterpret_cast(widget); + knob->blockSignals(true); + knob->setValue(control->rgbToValue(endColor.rgb())); + knob->blockSignals(false); + } + else if (control->m_type == VCMatrixControl::Color5Knob) { KnobWidget* knob = reinterpret_cast(widget); knob->blockSignals(true); knob->setValue(control->rgbToValue(endColor.rgb())); knob->blockSignals(false); } - else if (control->m_type == VCMatrixControl::StartColor) + else if (control->m_type == VCMatrixControl::Color1) { QPushButton* button = reinterpret_cast(it.key()); button->setDown(startColor == control->m_color); } - else if (control->m_type == VCMatrixControl::EndColor) + else if (control->m_type == VCMatrixControl::Color2) + { + QPushButton* button = reinterpret_cast(it.key()); + button->setDown(endColor == control->m_color); + } + else if (control->m_type == VCMatrixControl::Color3) + { + QPushButton* button = reinterpret_cast(it.key()); + button->setDown(endColor == control->m_color); + } + else if (control->m_type == VCMatrixControl::Color4) + { + QPushButton* button = reinterpret_cast(it.key()); + button->setDown(endColor == control->m_color); + } + else if (control->m_type == VCMatrixControl::Color5) { QPushButton* button = reinterpret_cast(it.key()); button->setDown(endColor == control->m_color); @@ -597,25 +752,64 @@ void VCMatrix::addCustomControl(VCMatrixControl const& control) { QWidget *controlWidget = NULL; - if (control.m_type == VCMatrixControl::StartColor) + if (control.m_type == VCMatrixControl::Color1) + { + QPushButton *controlButton = new QPushButton(this); + controlWidget = controlButton; + controlButton->setStyleSheet(controlBtnSS.arg(control.m_color.name())); + controlButton->setFixedWidth(36); + controlButton->setFocusPolicy(Qt::TabFocus); + controlButton->setText("1"); + } + else if (control.m_type == VCMatrixControl::Color2) + { + QPushButton *controlButton = new QPushButton(this); + controlWidget = controlButton; + controlButton->setStyleSheet(controlBtnSS.arg(control.m_color.name())); + controlButton->setFixedWidth(36); + controlButton->setFocusPolicy(Qt::TabFocus); + controlButton->setText("2"); + } + else if (control.m_type == VCMatrixControl::Color3) + { + QPushButton *controlButton = new QPushButton(this); + controlWidget = controlButton; + controlButton->setStyleSheet(controlBtnSS.arg(control.m_color.name())); + controlButton->setFixedWidth(36); + controlButton->setFocusPolicy(Qt::TabFocus); + controlButton->setText("3"); + } + else if (control.m_type == VCMatrixControl::Color4) { QPushButton *controlButton = new QPushButton(this); controlWidget = controlButton; controlButton->setStyleSheet(controlBtnSS.arg(control.m_color.name())); controlButton->setFixedWidth(36); controlButton->setFocusPolicy(Qt::TabFocus); - controlButton->setText("S"); + controlButton->setText("4"); } - else if (control.m_type == VCMatrixControl::EndColor) + else if (control.m_type == VCMatrixControl::Color5) { QPushButton *controlButton = new QPushButton(this); controlWidget = controlButton; controlButton->setStyleSheet(controlBtnSS.arg(control.m_color.name())); controlButton->setFixedWidth(36); controlButton->setFocusPolicy(Qt::TabFocus); - controlButton->setText("E"); + controlButton->setText("5"); + } + else if (control.m_type == VCMatrixControl::ResetColor2) + { + QPushButton *controlButton = new QPushButton(this); + controlWidget = controlButton; + controlButton->setStyleSheet(controlBtnSS.arg("#BBBBBB")); + controlButton->setMinimumWidth(36); + controlButton->setMaximumWidth(80); + controlButton->setFocusPolicy(Qt::TabFocus); + QString btnLabel = tr("Color 2 Reset"); + controlButton->setToolTip(btnLabel); + controlButton->setText(fontMetrics().elidedText(btnLabel, Qt::ElideRight, 72)); } - else if (control.m_type == VCMatrixControl::ResetEndColor) + else if (control.m_type == VCMatrixControl::ResetColor3) { QPushButton *controlButton = new QPushButton(this); controlWidget = controlButton; @@ -623,7 +817,31 @@ void VCMatrix::addCustomControl(VCMatrixControl const& control) controlButton->setMinimumWidth(36); controlButton->setMaximumWidth(80); controlButton->setFocusPolicy(Qt::TabFocus); - QString btnLabel = tr("End Color Reset"); + QString btnLabel = tr("Color 3 Reset"); + controlButton->setToolTip(btnLabel); + controlButton->setText(fontMetrics().elidedText(btnLabel, Qt::ElideRight, 72)); + } + else if (control.m_type == VCMatrixControl::ResetColor4) + { + QPushButton *controlButton = new QPushButton(this); + controlWidget = controlButton; + controlButton->setStyleSheet(controlBtnSS.arg("#BBBBBB")); + controlButton->setMinimumWidth(36); + controlButton->setMaximumWidth(80); + controlButton->setFocusPolicy(Qt::TabFocus); + QString btnLabel = tr("Color 4 Reset"); + controlButton->setToolTip(btnLabel); + controlButton->setText(fontMetrics().elidedText(btnLabel, Qt::ElideRight, 72)); + } + else if (control.m_type == VCMatrixControl::ResetColor5) + { + QPushButton *controlButton = new QPushButton(this); + controlWidget = controlButton; + controlButton->setStyleSheet(controlBtnSS.arg("#BBBBBB")); + controlButton->setMinimumWidth(36); + controlButton->setMaximumWidth(80); + controlButton->setFocusPolicy(Qt::TabFocus); + QString btnLabel = tr("Color 5 Reset"); controlButton->setToolTip(btnLabel); controlButton->setText(fontMetrics().elidedText(btnLabel, Qt::ElideRight, 72)); } @@ -653,7 +871,7 @@ void VCMatrix::addCustomControl(VCMatrixControl const& control) controlButton->setToolTip(btnLabel); controlButton->setText(fontMetrics().elidedText(btnLabel, Qt::ElideRight, 72)); } - else if (control.m_type == VCMatrixControl::StartColorKnob) + else if (control.m_type == VCMatrixControl::Color1Knob) { KnobWidget *controlKnob = new KnobWidget(this); controlWidget = controlKnob; @@ -669,7 +887,55 @@ void VCMatrix::addCustomControl(VCMatrixControl const& control) knobLabel = tr("Start color Blue component"); controlKnob->setToolTip(knobLabel); } - else if (control.m_type == VCMatrixControl::EndColorKnob) + else if (control.m_type == VCMatrixControl::Color2Knob) + { + KnobWidget *controlKnob = new KnobWidget(this); + controlWidget = controlKnob; + controlKnob->setColor(control.m_color.darker(250)); + controlKnob->setFixedWidth(36); + controlKnob->setFixedHeight(36); + QString knobLabel; + if (control.m_color == Qt::red) + knobLabel = tr("End color Red component"); + else if (control.m_color == Qt::green) + knobLabel = tr("End color Green component"); + else if (control.m_color == Qt::blue) + knobLabel = tr("End color Blue component"); + controlKnob->setToolTip(knobLabel); + } + else if (control.m_type == VCMatrixControl::Color3Knob) + { + KnobWidget *controlKnob = new KnobWidget(this); + controlWidget = controlKnob; + controlKnob->setColor(control.m_color.darker(250)); + controlKnob->setFixedWidth(36); + controlKnob->setFixedHeight(36); + QString knobLabel; + if (control.m_color == Qt::red) + knobLabel = tr("End color Red component"); + else if (control.m_color == Qt::green) + knobLabel = tr("End color Green component"); + else if (control.m_color == Qt::blue) + knobLabel = tr("End color Blue component"); + controlKnob->setToolTip(knobLabel); + } + else if (control.m_type == VCMatrixControl::Color4Knob) + { + KnobWidget *controlKnob = new KnobWidget(this); + controlWidget = controlKnob; + controlKnob->setColor(control.m_color.darker(250)); + controlKnob->setFixedWidth(36); + controlKnob->setFixedHeight(36); + QString knobLabel; + if (control.m_color == Qt::red) + knobLabel = tr("End color Red component"); + else if (control.m_color == Qt::green) + knobLabel = tr("End color Green component"); + else if (control.m_color == Qt::blue) + knobLabel = tr("End color Blue component"); + controlKnob->setToolTip(knobLabel); + } + else if (control.m_type == VCMatrixControl::Color5Knob) { KnobWidget *controlKnob = new KnobWidget(this); controlWidget = controlKnob; @@ -748,26 +1014,65 @@ void VCMatrix::slotCustomControlClicked() if (matrix == NULL || mode() == Doc::Design) return; - if (control->m_type == VCMatrixControl::StartColor) + if (control->m_type == VCMatrixControl::Color1) { matrix->setColor(0, control->m_color); if (instantChanges() == true) matrix->updateColorDelta(); btn->setDown(true); } - else if (control->m_type == VCMatrixControl::EndColor) + else if (control->m_type == VCMatrixControl::Color2) { matrix->setColor(1, control->m_color); if (instantChanges() == true) matrix->updateColorDelta(); btn->setDown(true); } - else if (control->m_type == VCMatrixControl::ResetEndColor) + else if (control->m_type == VCMatrixControl::Color3) + { + matrix->setColor(2, control->m_color); + if (instantChanges() == true) + matrix->updateColorDelta(); + btn->setDown(true); + } + else if (control->m_type == VCMatrixControl::Color4) + { + matrix->setColor(3, control->m_color); + if (instantChanges() == true) + matrix->updateColorDelta(); + btn->setDown(true); + } + else if (control->m_type == VCMatrixControl::Color5) + { + matrix->setColor(4, control->m_color); + if (instantChanges() == true) + matrix->updateColorDelta(); + btn->setDown(true); + } + else if (control->m_type == VCMatrixControl::ResetColor2) { matrix->setColor(1, QColor()); if (instantChanges() == true) matrix->updateColorDelta(); } + else if (control->m_type == VCMatrixControl::ResetColor3) + { + matrix->setColor(2, QColor()); + if (instantChanges() == true) + matrix->updateColorDelta(); + } + else if (control->m_type == VCMatrixControl::ResetColor4) + { + matrix->setColor(3, QColor()); + if (instantChanges() == true) + matrix->updateColorDelta(); + } + else if (control->m_type == VCMatrixControl::ResetColor5) + { + matrix->setColor(4, QColor()); + if (instantChanges() == true) + matrix->updateColorDelta(); + } else if (control->m_type == VCMatrixControl::Animation) { RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, control->m_resource); @@ -810,7 +1115,7 @@ void VCMatrix::slotCustomControlValueChanged() if (matrix == NULL || mode() == Doc::Design) return; - if (control->m_type == VCMatrixControl::StartColorKnob) + if (control->m_type == VCMatrixControl::Color1Knob) { QRgb color = matrix->getColor(0).rgb(); QRgb knobValueColor = control->valueToRgb(knob->value()); @@ -820,7 +1125,7 @@ void VCMatrix::slotCustomControlValueChanged() if (instantChanges() == true) matrix->updateColorDelta(); } - else if (control->m_type == VCMatrixControl::EndColorKnob) + else if (control->m_type == VCMatrixControl::Color2Knob) { QRgb color = matrix->getColor(1).rgb(); QRgb knobValueColor = control->valueToRgb(knob->value()); @@ -830,6 +1135,36 @@ void VCMatrix::slotCustomControlValueChanged() if (instantChanges() == true) matrix->updateColorDelta(); } + else if (control->m_type == VCMatrixControl::Color3Knob) + { + QRgb color = matrix->getColor(2).rgb(); + QRgb knobValueColor = control->valueToRgb(knob->value()); + color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb()); + + matrix->setColor(2, color); + if (instantChanges() == true) + matrix->updateColorDelta(); + } + else if (control->m_type == VCMatrixControl::Color4Knob) + { + QRgb color = matrix->getColor(3).rgb(); + QRgb knobValueColor = control->valueToRgb(knob->value()); + color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb()); + + matrix->setColor(3, color); + if (instantChanges() == true) + matrix->updateColorDelta(); + } + else if (control->m_type == VCMatrixControl::Color5Knob) + { + QRgb color = matrix->getColor(4).rgb(); + QRgb knobValueColor = control->valueToRgb(knob->value()); + color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb()); + + matrix->setColor(4, color); + if (instantChanges() == true) + matrix->updateColorDelta(); + } else { // We are not supposed to be here diff --git a/ui/src/virtualconsole/vcmatrix.h b/ui/src/virtualconsole/vcmatrix.h index 743a260a02..dbcedc4408 100644 --- a/ui/src/virtualconsole/vcmatrix.h +++ b/ui/src/virtualconsole/vcmatrix.h @@ -63,9 +63,12 @@ class VCMatrix : public VCWidget None = 0, ShowSlider = 1 << 0, ShowLabel = 1 << 1, - ShowStartColorButton = 1 << 2, - ShowEndColorButton = 1 << 3, - ShowPresetCombo = 1 << 4, + ShowPresetCombo = 1 << 2, + ShowColor1Button = 1 << 3, + ShowColor2Button = 1 << 4, + ShowColor3Button = 1 << 5, + ShowColor4Button = 1 << 6, + ShowColor5Button = 1 << 7 }; public: @@ -86,10 +89,16 @@ class VCMatrix : public VCWidget ClickAndGoSlider *m_slider; bool m_sliderExternalMovement; QLabel *m_label; - QToolButton *m_startColorButton; - ClickAndGoWidget *m_scCnGWidget; - QToolButton *m_endColorButton; - ClickAndGoWidget *m_ecCnGWidget; + QToolButton *m_mtxColorButton1; + ClickAndGoWidget *m_mtxCnGWidget1; + QToolButton *m_mtxColorButton2; + ClickAndGoWidget *m_mtxCnGWidget2; + QToolButton *m_mtxColorButton3; + ClickAndGoWidget *m_mtxCnGWidget3; + QToolButton *m_mtxColorButton4; + ClickAndGoWidget *m_mtxCnGWidget4; + QToolButton *m_mtxColorButton5; + ClickAndGoWidget *m_mtxCnGWidget5; QComboBox *m_presetCombo; FlowLayout *m_controlsLayout; @@ -114,8 +123,11 @@ class VCMatrix : public VCWidget private slots: void slotSliderMoved(int value); - void slotStartColorChanged(QRgb color); - void slotEndColorChanged(QRgb color); + void slotColorChanged1(QRgb color); + void slotColorChanged2(QRgb color); + void slotColorChanged3(QRgb color); + void slotColorChanged4(QRgb color); + void slotColorChanged5(QRgb color); void slotAnimationChanged(QString name); /********************************************************************* diff --git a/ui/src/virtualconsole/vcmatrixcontrol.cpp b/ui/src/virtualconsole/vcmatrixcontrol.cpp index 609ea0e8ed..c53b7fe427 100644 --- a/ui/src/virtualconsole/vcmatrixcontrol.cpp +++ b/ui/src/virtualconsole/vcmatrixcontrol.cpp @@ -94,15 +94,24 @@ VCMatrixControl::WidgetType VCMatrixControl::widgetType() const { switch(m_type) { - case StartColor: - case EndColor: + case Color1: + case Color2: + case Color3: + case Color4: + case Color5: case Animation: case Image: case Text: - case ResetEndColor: + case ResetColor2: + case ResetColor3: + case ResetColor4: + case ResetColor5: return Button; - case StartColorKnob: - case EndColorKnob: + case Color1Knob: + case Color2Knob: + case Color3Knob: + case Color4Knob: + case Color5Knob: return Knob; } @@ -115,30 +124,48 @@ QString VCMatrixControl::typeToString(VCMatrixControl::ControlType type) { switch(type) { - case StartColor: return "StartColor"; break; - case EndColor: return "EndColor"; break; - case ResetEndColor: return "ResetEndColor"; break; + case Color1: return "Color1"; break; + case Color2: return "Color2"; break; + case Color3: return "Color3"; break; + case Color4: return "Color4"; break; + case Color5: return "Color5"; break; + case ResetColor2: return "ResetColor2"; break; + case ResetColor3: return "ResetColor3"; break; + case ResetColor4: return "ResetColor4"; break; + case ResetColor5: return "ResetColor5"; break; case Animation: return "Animation"; break; case Image: return "Image"; break; case Text: return "Text"; break; - case StartColorKnob: return "StartColorKnob"; break; - case EndColorKnob: return "EndColorKnob"; break; + case Color1Knob: return "Color1Knob"; break; + case Color2Knob: return "Color2Knob"; break; + case Color3Knob: return "Color3Knob"; break; + case Color4Knob: return "Color4Knob"; break; + case Color5Knob: return "Color5Knob"; break; } return QString(); } VCMatrixControl::ControlType VCMatrixControl::stringToType(QString str) { - if (str == "StartColor") return StartColor; - else if (str == "EndColor") return EndColor; - else if (str == "ResetEndColor") return ResetEndColor; + if (str == "Color1") return Color1; + else if (str == "Color2") return Color2; + else if (str == "Color3") return Color3; + else if (str == "Color4") return Color4; + else if (str == "Color5") return Color5; + else if (str == "ResetColor2") return ResetColor2; + else if (str == "ResetColor3") return ResetColor3; + else if (str == "ResetColor4") return ResetColor4; + else if (str == "ResetColor5") return ResetColor5; else if (str == "Animation") return Animation; else if (str == "Image") return Image; else if (str == "Text") return Text; - else if (str == "StartColorKnob") return StartColorKnob; - else if (str == "EndColorKnob") return EndColorKnob; + else if (str == "Color1Knob") return Color1Knob; + else if (str == "Color2Knob") return Color2Knob; + else if (str == "Color3Knob") return Color3Knob; + else if (str == "Color4Knob") return Color4Knob; + else if (str == "Color5Knob") return Color5Knob; else - return StartColor; + return Color1; } bool VCMatrixControl::operator<(VCMatrixControl const& right) const @@ -219,7 +246,16 @@ bool VCMatrixControl::saveXML(QXmlStreamWriter *doc) doc->writeTextElement(KXMLQLCVCMatrixControlType, typeToString(m_type)); - if (m_type == StartColor || m_type == EndColor || m_type == StartColorKnob || m_type == EndColorKnob) + if (m_type == Color1 + || m_type == Color2 + || m_type == Color3 + || m_type == Color4 + || m_type == Color5 + || m_type == Color1Knob + || m_type == Color2Knob + || m_type == Color3Knob + || m_type == Color4Knob + || m_type == Color5Knob) { doc->writeTextElement(KXMLQLCVCMatrixControlColor, m_color.name()); } diff --git a/ui/src/virtualconsole/vcmatrixcontrol.h b/ui/src/virtualconsole/vcmatrixcontrol.h index dc718eb499..d275d00c31 100644 --- a/ui/src/virtualconsole/vcmatrixcontrol.h +++ b/ui/src/virtualconsole/vcmatrixcontrol.h @@ -56,14 +56,23 @@ class VCMatrixControl enum ControlType { - StartColor = 0, - EndColor, + Color1 = 0, + Color1Knob, + Color2, + Color2Knob, + ResetColor2, + Color3, + Color3Knob, + ResetColor3, + Color4, + Color4Knob, + ResetColor4, + Color5, + Color5Knob, + ResetColor5, Animation, Image, - Text, - ResetEndColor, - StartColorKnob, - EndColorKnob + Text }; enum WidgetType diff --git a/ui/src/virtualconsole/vcmatrixproperties.cpp b/ui/src/virtualconsole/vcmatrixproperties.cpp index cbeaea950f..4490d04581 100644 --- a/ui/src/virtualconsole/vcmatrixproperties.cpp +++ b/ui/src/virtualconsole/vcmatrixproperties.cpp @@ -70,8 +70,11 @@ VCMatrixProperties::VCMatrixProperties(VCMatrix* matrix, Doc* doc) quint32 visibilityMask = m_matrix->visibilityMask(); if (visibilityMask & VCMatrix::ShowSlider) m_sliderCheck->setChecked(true); if (visibilityMask & VCMatrix::ShowLabel) m_labelCheck->setChecked(true); - if (visibilityMask & VCMatrix::ShowStartColorButton) m_startColorButtonCheck->setChecked(true); - if (visibilityMask & VCMatrix::ShowEndColorButton) m_endColorButtonCheck->setChecked(true); + if (visibilityMask & VCMatrix::ShowColor1Button) m_mtxColor1ButtonCheck->setChecked(true); + if (visibilityMask & VCMatrix::ShowColor1Button) m_mtxColor2ButtonCheck->setChecked(true); + if (visibilityMask & VCMatrix::ShowColor1Button) m_mtxColor3ButtonCheck->setChecked(true); + if (visibilityMask & VCMatrix::ShowColor1Button) m_mtxColor4ButtonCheck->setChecked(true); + if (visibilityMask & VCMatrix::ShowColor1Button) m_mtxColor5ButtonCheck->setChecked(true); if (visibilityMask & VCMatrix::ShowPresetCombo) m_presetComboCheck->setChecked(true); /* Custom controls */ @@ -89,15 +92,33 @@ VCMatrixProperties::VCMatrixProperties(VCMatrix* matrix, Doc* doc) connect(m_controlsTree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(slotTreeSelectionChanged())); - connect(m_addStartColorButton, SIGNAL(clicked()), + connect(m_addMtxColor1Button, SIGNAL(clicked()), this, SLOT(slotAddStartColorClicked())); - connect(m_addStartColorKnobsButton, SIGNAL(clicked()), + connect(m_addMtxColor1KnobsButton, SIGNAL(clicked()), this, SLOT(slotAddStartColorKnobsClicked())); - connect(m_addEndColorButton, SIGNAL(clicked()), + connect(m_addMtxColor2Button, SIGNAL(clicked()), this, SLOT(slotAddEndColorClicked())); - connect(m_addEndColorKnobsButton, SIGNAL(clicked()), + connect(m_addMtxColor2KnobsButton, SIGNAL(clicked()), this, SLOT(slotAddEndColorKnobsClicked())); - connect(m_addEndColorResetButton, SIGNAL(clicked()), + connect(m_addMtxColor2ResetButton, SIGNAL(clicked()), + this, SLOT(slotAddEndColorResetClicked())); + connect(m_addMtxColor3Button, SIGNAL(clicked()), + this, SLOT(slotAddEndColorClicked())); + connect(m_addMtxColor3KnobsButton, SIGNAL(clicked()), + this, SLOT(slotAddEndColorKnobsClicked())); + connect(m_addMtxColor3ResetButton, SIGNAL(clicked()), + this, SLOT(slotAddEndColorResetClicked())); + connect(m_addMtxColor4Button, SIGNAL(clicked()), + this, SLOT(slotAddEndColorClicked())); + connect(m_addMtxColor4KnobsButton, SIGNAL(clicked()), + this, SLOT(slotAddEndColorKnobsClicked())); + connect(m_addMtxColor4ResetButton, SIGNAL(clicked()), + this, SLOT(slotAddEndColorResetClicked())); + connect(m_addMtxColor5Button, SIGNAL(clicked()), + this, SLOT(slotAddEndColorClicked())); + connect(m_addMtxColor5KnobsButton, SIGNAL(clicked()), + this, SLOT(slotAddEndColorKnobsClicked())); + connect(m_addMtxColor5ResetButton, SIGNAL(clicked()), this, SLOT(slotAddEndColorResetClicked())); connect(m_addPresetButton, SIGNAL(clicked()), this, SLOT(slotAddAnimationClicked())); @@ -225,33 +246,81 @@ void VCMatrixProperties::updateTree() switch(control->m_type) { - case VCMatrixControl::StartColor: + case VCMatrixControl::Color1: + item->setIcon(0, QIcon(":/color.png")); + item->setText(0, tr("Color 1")); + item->setText(1, control->m_color.name()); + item->setBackground(1, QBrush(control->m_color)); + break; + case VCMatrixControl::Color1Knob: + item->setIcon(0, QIcon(":/knob.png")); + item->setText(0, tr("Color 1 Knob")); + item->setText(1, control->m_color.name()); + item->setBackground(1, QBrush(control->m_color)); + break; + case VCMatrixControl::Color2: + item->setIcon(0, QIcon(":/color.png")); + item->setText(0, tr("Color 2")); + item->setText(1, control->m_color.name()); + item->setBackground(1, QBrush(control->m_color)); + break; + case VCMatrixControl::Color2Knob: + item->setIcon(0, QIcon(":/knob.png")); + item->setText(0, tr("Color 2 Knob")); + item->setText(1, control->m_color.name()); + item->setBackground(1, QBrush(control->m_color)); + break; + case VCMatrixControl::ResetColor2: + item->setIcon(0, QIcon(":/fileclose.png")); + item->setText(0, tr("Color 2 Reset")); + break; + case VCMatrixControl::Color3: + item->setIcon(0, QIcon(":/color.png")); + item->setText(0, tr("Color 3")); + item->setText(1, control->m_color.name()); + item->setBackground(1, QBrush(control->m_color)); + break; + case VCMatrixControl::Color3Knob: + item->setIcon(0, QIcon(":/knob.png")); + item->setText(0, tr("Color 3 Knob")); + item->setText(1, control->m_color.name()); + item->setBackground(1, QBrush(control->m_color)); + break; + case VCMatrixControl::ResetColor3: + item->setIcon(0, QIcon(":/fileclose.png")); + item->setText(0, tr("Color 3 Reset")); + break; + case VCMatrixControl::Color4: item->setIcon(0, QIcon(":/color.png")); - item->setText(0, tr("Start Color")); + item->setText(0, tr("Color 4")); item->setText(1, control->m_color.name()); item->setBackground(1, QBrush(control->m_color)); break; - case VCMatrixControl::StartColorKnob: + case VCMatrixControl::Color4Knob: item->setIcon(0, QIcon(":/knob.png")); - item->setText(0, tr("Start Color Knob")); + item->setText(0, tr("Color 4 Knob")); item->setText(1, control->m_color.name()); item->setBackground(1, QBrush(control->m_color)); break; - case VCMatrixControl::EndColor: + case VCMatrixControl::ResetColor4: + item->setIcon(0, QIcon(":/fileclose.png")); + item->setText(0, tr("Color 4 Reset")); + break; + case VCMatrixControl::Color5: item->setIcon(0, QIcon(":/color.png")); - item->setText(0, tr("End Color")); + item->setText(0, tr("Color 5")); item->setText(1, control->m_color.name()); item->setBackground(1, QBrush(control->m_color)); break; - case VCMatrixControl::EndColorKnob: + case VCMatrixControl::Color5Knob: item->setIcon(0, QIcon(":/knob.png")); - item->setText(0, tr("End Color Knob")); + item->setText(0, tr("Color 5 Knob")); item->setText(1, control->m_color.name()); item->setBackground(1, QBrush(control->m_color)); break; - case VCMatrixControl::ResetEndColor: + case VCMatrixControl::ResetColor5: item->setIcon(0, QIcon(":/fileclose.png")); - item->setText(0, tr("End Color Reset")); + item->setText(0, tr("Color 5 Reset")); break; case VCMatrixControl::Animation: { @@ -333,60 +402,159 @@ void VCMatrixProperties::removeControl(quint8 id) } } -void VCMatrixProperties::slotAddStartColorClicked() +void VCMatrixProperties::slotAddMtxColor1Clicked() +{ + QColor col = QColorDialog::getColor(); + if (col.isValid() == true) + { + VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); + newControl->m_type = VCMatrixControl::Color1; + newControl->m_color = col; + addControl(newControl); + updateTree(); + } +} + +void VCMatrixProperties::slotAddMtxColor1KnobsClicked() +{ + foreach (QColor col, VCMatrixProperties::rgbColorList()) + { + VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); + newControl->m_type = VCMatrixControl::Color1Knob; + newControl->m_color = col; + addControl(newControl); + } + updateTree(); +} + +void VCMatrixProperties::slotAddMtxColor2Clicked() +{ + QColor col = QColorDialog::getColor(); + if (col.isValid() == true) + { + VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); + newControl->m_type = VCMatrixControl::Color2; + newControl->m_color = col; + addControl(newControl); + updateTree(); + } +} + +void VCMatrixProperties::slotAddMtxColor2KnobsClicked() +{ + foreach (QColor col, VCMatrixProperties::rgbColorList()) + { + VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); + newControl->m_type = VCMatrixControl::Color2Knob; + newControl->m_color = col; + addControl(newControl); + } + updateTree(); +} + +void VCMatrixProperties::slotAddMtxColor2ResetClicked() +{ + VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); + newControl->m_type = VCMatrixControl::ResetColor2; + addControl(newControl); + updateTree(); +} + +void VCMatrixProperties::slotAddMtxColor3Clicked() +{ + QColor col = QColorDialog::getColor(); + if (col.isValid() == true) + { + VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); + newControl->m_type = VCMatrixControl::Color3; + newControl->m_color = col; + addControl(newControl); + updateTree(); + } +} + +void VCMatrixProperties::slotAddMtxColor3KnobsClicked() +{ + foreach (QColor col, VCMatrixProperties::rgbColorList()) + { + VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); + newControl->m_type = VCMatrixControl::Color3Knob; + newControl->m_color = col; + addControl(newControl); + } + updateTree(); +} + +void VCMatrixProperties::slotAddMtxColor3ResetClicked() +{ + VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); + newControl->m_type = VCMatrixControl::ResetColor3; + addControl(newControl); + updateTree(); +} + +void VCMatrixProperties::slotAddMtxColor4Clicked() { QColor col = QColorDialog::getColor(); if (col.isValid() == true) { VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); - newControl->m_type = VCMatrixControl::StartColor; + newControl->m_type = VCMatrixControl::Color4; newControl->m_color = col; addControl(newControl); updateTree(); } } -void VCMatrixProperties::slotAddStartColorKnobsClicked() +void VCMatrixProperties::slotAddMtxColor4KnobsClicked() { foreach (QColor col, VCMatrixProperties::rgbColorList()) { VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); - newControl->m_type = VCMatrixControl::StartColorKnob; + newControl->m_type = VCMatrixControl::Color4Knob; newControl->m_color = col; addControl(newControl); } updateTree(); } -void VCMatrixProperties::slotAddEndColorClicked() +void VCMatrixProperties::slotAddMtxColor4ResetClicked() +{ + VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); + newControl->m_type = VCMatrixControl::ResetColor4; + addControl(newControl); + updateTree(); +} + +void VCMatrixProperties::slotAddMtxColor5Clicked() { QColor col = QColorDialog::getColor(); if (col.isValid() == true) { VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); - newControl->m_type = VCMatrixControl::EndColor; + newControl->m_type = VCMatrixControl::Color5; newControl->m_color = col; addControl(newControl); updateTree(); } } -void VCMatrixProperties::slotAddEndColorKnobsClicked() +void VCMatrixProperties::slotAddMtxColor5KnobsClicked() { foreach (QColor col, VCMatrixProperties::rgbColorList()) { VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); - newControl->m_type = VCMatrixControl::EndColorKnob; + newControl->m_type = VCMatrixControl::Color5Knob; newControl->m_color = col; addControl(newControl); } updateTree(); } -void VCMatrixProperties::slotAddEndColorResetClicked() +void VCMatrixProperties::slotAddMtxColor5ResetClicked() { VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); - newControl->m_type = VCMatrixControl::ResetEndColor; + newControl->m_type = VCMatrixControl::ResetColor5; addControl(newControl); updateTree(); } @@ -435,8 +603,11 @@ void VCMatrixProperties::slotRemoveClicked() VCMatrixControl *control = getSelectedControl(); if (control != NULL) { - if (control->m_type == VCMatrixControl::StartColorKnob - || control->m_type == VCMatrixControl::EndColorKnob) + if (control->m_type == VCMatrixControl::Color1Knob + || control->m_type == VCMatrixControl::Color2Knob + || control->m_type == VCMatrixControl::Color3Knob + || control->m_type == VCMatrixControl::Color4Knob + || control->m_type == VCMatrixControl::Color5Knob) { if (control->m_color == Qt::red) { @@ -523,8 +694,11 @@ void VCMatrixProperties::accept() quint32 visibilityMask = 0; if (m_sliderCheck->isChecked()) visibilityMask |= VCMatrix::ShowSlider; if (m_labelCheck->isChecked()) visibilityMask |= VCMatrix::ShowLabel; - if (m_startColorButtonCheck->isChecked()) visibilityMask |= VCMatrix::ShowStartColorButton; - if (m_endColorButtonCheck->isChecked()) visibilityMask |= VCMatrix::ShowEndColorButton; + if (m_mtxColor1ButtonCheck->isChecked()) visibilityMask |= VCMatrix::ShowColor1Button; + if (m_mtxColor2ButtonCheck->isChecked()) visibilityMask |= VCMatrix::ShowColor2Button; + if (m_mtxColor3ButtonCheck->isChecked()) visibilityMask |= VCMatrix::ShowColor3Button; + if (m_mtxColor4ButtonCheck->isChecked()) visibilityMask |= VCMatrix::ShowColor4Button; + if (m_mtxColor5ButtonCheck->isChecked()) visibilityMask |= VCMatrix::ShowColor5Button; if (m_presetComboCheck->isChecked()) visibilityMask |= VCMatrix::ShowPresetCombo; m_matrix->setVisibilityMask(visibilityMask); diff --git a/ui/src/virtualconsole/vcmatrixproperties.h b/ui/src/virtualconsole/vcmatrixproperties.h index 35f5a02639..6e4356ee8d 100644 --- a/ui/src/virtualconsole/vcmatrixproperties.h +++ b/ui/src/virtualconsole/vcmatrixproperties.h @@ -84,11 +84,20 @@ protected slots: protected slots: void slotTreeSelectionChanged(); - void slotAddStartColorClicked(); - void slotAddStartColorKnobsClicked(); - void slotAddEndColorClicked(); - void slotAddEndColorKnobsClicked(); - void slotAddEndColorResetClicked(); + void slotAddMtxColor1Clicked(); + void slotAddMtxColor1KnobsClicked(); + void slotAddMtxColor2Clicked(); + void slotAddMtxColor2KnobsClicked(); + void slotAddMtxColor2ResetClicked(); + void slotAddMtxColor3Clicked(); + void slotAddMtxColor3KnobsClicked(); + void slotAddMtxColor3ResetClicked(); + void slotAddMtxColor4Clicked(); + void slotAddMtxColor4KnobsClicked(); + void slotAddMtxColor4ResetClicked(); + void slotAddMtxColor5Clicked(); + void slotAddMtxColor5KnobsClicked(); + void slotAddMtxColor5ResetClicked(); void slotAddAnimationClicked(); void slotAddTextClicked(); void slotRemoveClicked(); diff --git a/ui/src/virtualconsole/vcmatrixproperties.ui b/ui/src/virtualconsole/vcmatrixproperties.ui index 10cb36f07f..1d99dbc075 100644 --- a/ui/src/virtualconsole/vcmatrixproperties.ui +++ b/ui/src/virtualconsole/vcmatrixproperties.ui @@ -152,20 +152,41 @@ - + - Show Start Color Button + Show Color 1 Button - + - Show End Color Button + Show Color 2 Button + + + Show Color 3 Button + + + + + + + Show Color 4 Button + + + + + + + Show Color 5 Button + + + + Show Preset Combo @@ -276,9 +297,42 @@ - + + + Add color 2 knobs + + + + :/knob.png:/knob.png + + + + + + + Add color 3 knobs + + + + :/knob.png:/knob.png + + + + + + + Add color 4 knobs + + + + :/knob.png:/knob.png + + + + + - Add end color knobs + Add color 5 knobs @@ -332,7 +386,40 @@ - + + + Add end color reset + + + + :/fileclose.png:/fileclose.png + + + + + + + Add end color reset + + + + :/fileclose.png:/fileclose.png + + + + + + + Add end color reset + + + + :/fileclose.png:/fileclose.png + + + + + Add end color reset @@ -354,7 +441,7 @@ - + Add start color @@ -365,7 +452,7 @@ - + Add start color knobs @@ -376,7 +463,40 @@ - + + + Add end color + + + + :/color.png:/color.png + + + + + + + Add end color + + + + :/color.png:/color.png + + + + + + + Add end color + + + + :/color.png:/color.png + + + + + Add end color From b36df53cfe98b264e9ccba9c9a89aeaffe99c3c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Fri, 17 Nov 2023 12:04:12 +0100 Subject: [PATCH 26/63] Implement five colors in qmlui --- .../qml/fixturesfunctions/RGBMatrixEditor.qml | 176 ++++++++++++++++-- qmlui/rgbmatrixeditor.cpp | 150 +++++++++++++-- qmlui/rgbmatrixeditor.h | 62 ++++-- qmlui/tardis/tardis.cpp | 22 ++- qmlui/tardis/tardis.h | 7 +- 5 files changed, 366 insertions(+), 51 deletions(-) diff --git a/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml b/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml index 4aadd60170..1e2cecdc96 100644 --- a/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml +++ b/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml @@ -267,13 +267,13 @@ Rectangle Rectangle { - id: startColButton + id: Color1Button width: UISettings.iconSizeDefault * 2 height: editorColumn.itemsHeight radius: 5 border.color: scMouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 - color: rgbMatrixEditor.startColor + color: rgbMatrixEditor.color1 visible: rgbMatrixEditor.algoColors > 0 ? true : false MouseArea @@ -281,36 +281,36 @@ Rectangle id: scMouseArea anchors.fill: parent hoverEnabled: true - onClicked: startColTool.visible = !startColTool.visible + onClicked: color1Tool.visible = !color1Tool.visible } ColorTool { - id: startColTool + id: color1Tool parent: rgbmeContainer x: -width - (UISettings.iconSizeDefault * 1.25) y: UISettings.bigItemHeight visible: false closeOnSelect: true - currentRGB: rgbMatrixEditor.startColor + currentRGB: rgbMatrixEditor.color1 onColorChanged: { - startColButton.color = Qt.rgba(r, g, b, 1.0) - rgbMatrixEditor.startColor = startColButton.color + color1Button.color = Qt.rgba(r, g, b, 1.0) + rgbMatrixEditor.color1 = color1Button.color } onClose: visible = false } } Rectangle { - id: endColButton + id: color2Button width: UISettings.iconSizeDefault * 2 height: editorColumn.itemsHeight radius: 5 border.color: ecMouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 - color: rgbMatrixEditor.hasEndColor ? rgbMatrixEditor.endColor : "transparent" + color: rgbMatrixEditor.hasColor2 ? rgbMatrixEditor.color2 : "transparent" visible: rgbMatrixEditor.algoColors > 1 ? true : false MouseArea @@ -318,20 +318,20 @@ Rectangle id: ecMouseArea anchors.fill: parent hoverEnabled: true - onClicked: endColTool.visible = !endColTool.visible + onClicked: color2Tool.visible = !color2Tool.visible } ColorTool { - id: endColTool + id: color2Tool parent: rgbmeContainer x: -width - (UISettings.iconSizeDefault * 1.25) y: UISettings.bigItemHeight visible: false closeOnSelect: true - currentRGB: rgbMatrixEditor.endColor + currentRGB: rgbMatrixEditor.color2 - onColorChanged: rgbMatrixEditor.endColor = Qt.rgba(r, g, b, 1.0) + onColorChanged: rgbMatrixEditor.color2 = Qt.rgba(r, g, b, 1.0) onClose: visible = false } } @@ -341,7 +341,155 @@ Rectangle height: width imgSource: "qrc:/cancel.svg" visible: rgbMatrixEditor.algoColors > 1 ? true : false - onClicked: rgbMatrixEditor.hasEndColor = false + onClicked: rgbMatrixEditor.hasColor2 = false + } + // filler + //Rectangle { Layout.fillWidth: true; height: parent.height; color: "transparent" } + } + + // row 7 + Row + { + width: editorColumn.colWidth + height: editorColumn.itemsHeight + spacing: 4 + + Rectangle + { + id: color3Button + width: UISettings.iconSizeDefault * 2 + height: editorColumn.itemsHeight + radius: 5 + border.color: ecMouseArea.containsMouse ? "white" : UISettings.bgLight + border.width: 2 + color: rgbMatrixEditor.hasColor3 ? rgbMatrixEditor.color3 : "transparent" + visible: rgbMatrixEditor.algoColors > 1 ? true : false + + MouseArea + { + id: ecMouseArea + anchors.fill: parent + hoverEnabled: true + onClicked: color3Tool.visible = !color3Tool.visible + } + + ColorTool + { + id: color3Tool + parent: rgbmeContainer + x: -width - (UISettings.iconSizeDefault * 1.25) + y: UISettings.bigItemHeight + visible: false + closeOnSelect: true + currentRGB: rgbMatrixEditor.color3 + + onColorChanged: rgbMatrixEditor.color3 = Qt.rgba(r, g, b, 1.0) + onClose: visible = false + } + } + IconButton + { + width: UISettings.listItemHeight + height: width + imgSource: "qrc:/cancel.svg" + visible: rgbMatrixEditor.algoColors > 1 ? true : false + onClicked: rgbMatrixEditor.hasColor3 = false + } + + Rectangle + { + id: color4Button + width: UISettings.iconSizeDefault * 2 + height: editorColumn.itemsHeight + radius: 5 + border.color: ecMouseArea.containsMouse ? "white" : UISettings.bgLight + border.width: 2 + color: rgbMatrixEditor.hasColor4 ? rgbMatrixEditor.color4 : "transparent" + visible: rgbMatrixEditor.algoColors > 1 ? true : false + + MouseArea + { + id: ecMouseArea + anchors.fill: parent + hoverEnabled: true + onClicked: color4Tool.visible = !color4Tool.visible + } + + ColorTool + { + id: color4Tool + parent: rgbmeContainer + x: -width - (UISettings.iconSizeDefault * 1.25) + y: UISettings.bigItemHeight + visible: false + closeOnSelect: true + currentRGB: rgbMatrixEditor.color4 + + onColorChanged: rgbMatrixEditor.color4 = Qt.rgba(r, g, b, 1.0) + onClose: visible = false + } + } + IconButton + { + width: UISettings.listItemHeight + height: width + imgSource: "qrc:/cancel.svg" + visible: rgbMatrixEditor.algoColors > 1 ? true : false + onClicked: rgbMatrixEditor.hasColor4 = false + } + // filler + //Rectangle { Layout.fillWidth: true; height: parent.height; color: "transparent" } + // filler + //Rectangle { Layout.fillWidth: true; height: parent.height; color: "transparent" } + } + + // row 8 + Row + { + width: editorColumn.colWidth + height: editorColumn.itemsHeight + spacing: 4 + + Rectangle + { + id: color5Button + width: UISettings.iconSizeDefault * 2 + height: editorColumn.itemsHeight + radius: 5 + border.color: ecMouseArea.containsMouse ? "white" : UISettings.bgLight + border.width: 2 + color: rgbMatrixEditor.hasColor5 ? rgbMatrixEditor.color5 : "transparent" + visible: rgbMatrixEditor.algoColors > 1 ? true : false + + MouseArea + { + id: ecMouseArea + anchors.fill: parent + hoverEnabled: true + onClicked: color5Tool.visible = !color5Tool.visible + } + + ColorTool + { + id: color5Tool + parent: rgbmeContainer + x: -width - (UISettings.iconSizeDefault * 1.25) + y: UISettings.bigItemHeight + visible: false + closeOnSelect: true + currentRGB: rgbMatrixEditor.color5 + + onColorChanged: rgbMatrixEditor.color5 = Qt.rgba(r, g, b, 1.0) + onClose: visible = false + } + } + IconButton + { + width: UISettings.listItemHeight + height: width + imgSource: "qrc:/cancel.svg" + visible: rgbMatrixEditor.algoColors > 1 ? true : false + onClicked: rgbMatrixEditor.hasColor5 = false } // filler //Rectangle { Layout.fillWidth: true; height: parent.height; color: "transparent" } diff --git a/qmlui/rgbmatrixeditor.cpp b/qmlui/rgbmatrixeditor.cpp index 4cb3819d13..2af5bc5d77 100644 --- a/qmlui/rgbmatrixeditor.cpp +++ b/qmlui/rgbmatrixeditor.cpp @@ -161,7 +161,7 @@ int RGBMatrixEditor::algoColors() return m_matrix->algorithm()->acceptColors(); } -QColor RGBMatrixEditor::startColor() const +QColor RGBMatrixEditor::color1() const { if (m_matrix == nullptr) return Qt::red; @@ -169,19 +169,19 @@ QColor RGBMatrixEditor::startColor() const return m_matrix->getColor(0); } -void RGBMatrixEditor::setStartColor(QColor algoStartColor) +void RGBMatrixEditor::setColor1(QColor algoColor) { - if (m_matrix == nullptr || m_matrix->getColor(0) == algoStartColor) + if (m_matrix == nullptr || m_matrix->getColor(0) == algoColor) return; - Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetStartColor, m_matrix->id(), m_matrix->getColor(0), algoStartColor); - m_matrix->setColor(0, algoStartColor); + Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor1, m_matrix->id(), m_matrix->getColor(0), algoColor); + m_matrix->setColor(0, algoColor); m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); - emit startColorChanged(algoStartColor); + emit color1Changed(algoColor); } -QColor RGBMatrixEditor::endColor() const +QColor RGBMatrixEditor::color2() const { if (m_matrix == nullptr) return QColor(); @@ -189,21 +189,84 @@ QColor RGBMatrixEditor::endColor() const return m_matrix->getColor(1); } -void RGBMatrixEditor::setEndColor(QColor algoEndColor) +void RGBMatrixEditor::setColor2(QColor algoColor) { - if (m_matrix == nullptr || m_matrix->getColor(1) == algoEndColor) + if (m_matrix == nullptr || m_matrix->getColor(1) == algoColor) return; - Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetEndColor, m_matrix->id(), m_matrix->getColor(1), algoEndColor); - m_matrix->setColor(1, algoEndColor); + Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor2, m_matrix->id(), m_matrix->getColor(1), algoColor); + m_matrix->setColor(1, algoColor); m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); - emit endColorChanged(algoEndColor); - if (algoEndColor.isValid()) - emit hasEndColorChanged(true); + emit color2Changed(algoColor); + if (algoColor.isValid()) + emit hasColor2Changed(true); } -bool RGBMatrixEditor::hasEndColor() const +QColor RGBMatrixEditor::color3() const +{ + if (m_matrix == nullptr) + return QColor(); + + return m_matrix->getColor(1); +} + +void RGBMatrixEditor::setColor3(QColor algoColor) +{ + if (m_matrix == nullptr || m_matrix->getColor(1) == algoColor) + return; + + Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor3, m_matrix->id(), m_matrix->getColor(2), algoColor); + m_matrix->setColor(2, algoColor); + + emit color3Changed(algoColor); + if (algoColor.isValid()) + emit hasColor3Changed(true); +} + +QColor RGBMatrixEditor::color4() const +{ + if (m_matrix == nullptr) + return QColor(); + + return m_matrix->getColor(1); +} + +void RGBMatrixEditor::setColor4(QColor algoColor) +{ + if (m_matrix == nullptr || m_matrix->getColor(1) == algoColor) + return; + + Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor4, m_matrix->id(), m_matrix->getColor(3), algoColor); + m_matrix->setColor(3, algoColor); + + emit color4Changed(algoColor); + if (algoColor.isValid()) + emit hasColor4Changed(true); +} + +QColor RGBMatrixEditor::color5() const +{ + if (m_matrix == nullptr) + return QColor(); + + return m_matrix->getColor(1); +} + +void RGBMatrixEditor::setColor5(QColor algoColor) +{ + if (m_matrix == nullptr || m_matrix->getColor(1) == algoColor) + return; + + Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor5, m_matrix->id(), m_matrix->getColor(4), algoColor); + m_matrix->setColor(4, algoColor); + + emit color5Changed(algoColor); + if (algoColor.isValid()) + emit hasColor5Changed(true); +} + +bool RGBMatrixEditor::hasColor2() const { if (m_matrix == nullptr || m_matrix->getColor(1).isValid() == false) return false; @@ -211,14 +274,65 @@ bool RGBMatrixEditor::hasEndColor() const return true; } -void RGBMatrixEditor::setHasEndColor(bool hasEndCol) +void RGBMatrixEditor::setHasColor2(bool hasColor) { - if (m_matrix && hasEndCol == false) + if (m_matrix && hasColor == false) { m_matrix->setColor(1, QColor()); m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); } - emit hasEndColorChanged(hasEndCol); + emit hasColor2Changed(hasColor); +} + +bool RGBMatrixEditor::hasColor3() const +{ + if (m_matrix == nullptr || m_matrix->getColor(2).isValid() == false) + return false; + + return true; +} + +void RGBMatrixEditor::setHasColor3(bool hasColor) +{ + if (m_matrix && hasColor == false) + { + m_matrix->setColor(2, QColor()); + } + emit hasColor3Changed(hasColor); +} + +bool RGBMatrixEditor::hasColor4() const +{ + if (m_matrix == nullptr || m_matrix->getColor(3).isValid() == false) + return false; + + return true; +} + +void RGBMatrixEditor::setHasColor4(bool hasColor) +{ + if (m_matrix && hasColor == false) + { + m_matrix->setColor(3, QColor()); + } + emit hasColor4Changed(hasColor); +} + +bool RGBMatrixEditor::hasColor5() const +{ + if (m_matrix == nullptr || m_matrix->getColor(4).isValid() == false) + return false; + + return true; +} + +void RGBMatrixEditor::setHasColor5(bool hasColor) +{ + if (m_matrix && hasColor == false) + { + m_matrix->setColor(4, QColor()); + } + emit hasColor5Changed(hasColor); } QString RGBMatrixEditor::algoText() const diff --git a/qmlui/rgbmatrixeditor.h b/qmlui/rgbmatrixeditor.h index f530a3e7a1..6f6812a561 100644 --- a/qmlui/rgbmatrixeditor.h +++ b/qmlui/rgbmatrixeditor.h @@ -39,12 +39,17 @@ class RGBMatrixEditor : public FunctionEditor Q_PROPERTY(QStringList algorithms READ algorithms CONSTANT) Q_PROPERTY(int algorithmIndex READ algorithmIndex WRITE setAlgorithmIndex NOTIFY algorithmIndexChanged) Q_PROPERTY(int algoColors READ algoColors NOTIFY algoColorsChanged) - Q_PROPERTY(QColor startColor READ startColor WRITE setStartColor NOTIFY startColorChanged) - Q_PROPERTY(QColor endColor READ endColor WRITE setEndColor NOTIFY endColorChanged) - Q_PROPERTY(bool hasEndColor READ hasEndColor WRITE setHasEndColor NOTIFY hasEndColorChanged) + Q_PROPERTY(QColor color1 READ color1 WRITE setColor1 NOTIFY color1Changed) + Q_PROPERTY(QColor color2 READ color2 WRITE setColor2 NOTIFY color2Changed) + Q_PROPERTY(bool hasColor2 READ hasColor2 WRITE setHasColor2 NOTIFY hasColor2Changed) + Q_PROPERTY(QColor color3 READ color3 WRITE setColor3 NOTIFY color3Changed) + Q_PROPERTY(bool hasColor3 READ hasColor3 WRITE setHasColor3 NOTIFY hasColor3Changed) + Q_PROPERTY(QColor color4 READ color4 WRITE setColor4 NOTIFY color4Changed) + Q_PROPERTY(bool hasColor4 READ hasColor4 WRITE setHasColor4 NOTIFY hasColor4Changed) + Q_PROPERTY(QColor color5 READ color5 WRITE setColor5 NOTIFY color5Changed) + Q_PROPERTY(bool hasColor5 READ hasColor5 WRITE setHasColor5 NOTIFY hasColor5Changed) Q_PROPERTY(int blendMode READ blendMode WRITE setBlendMode NOTIFY blendModeChanged) - Q_PROPERTY(int controlMode READ controlMode WRITE setControlMode NOTIFY controlModeChanged) // Text Algorithm specific properties Q_PROPERTY(QString algoText READ algoText WRITE setAlgoText NOTIFY algoTextChanged) @@ -87,16 +92,37 @@ class RGBMatrixEditor : public FunctionEditor /** Return the accepted colors of the current algorithm */ int algoColors(); - /** Get/set the start color of the current algorithm */ - QColor startColor() const; - void setStartColor(QColor startColor); + /** Get/set the color 1 of the current algorithm */ + QColor color1() const; + void setColor1(QColor algoColor); - /** Get/set the end color of the current algorithm */ - QColor endColor() const; - void setEndColor(QColor algoEndColor); + /** Get/set the color 2 of the current algorithm */ + QColor color2() const; + void setColor2(QColor algoColor); - bool hasEndColor() const; - void setHasEndColor(bool hasEndCol); + bool hasColor2() const; + void setHasColor2(bool hasColor); + + /** Get/set the color 2 of the current algorithm */ + QColor color3() const; + void setColor3(QColor algoColor); + + bool hasColor3() const; + void setHasColor3(bool hasColor); + + /** Get/set the color 2 of the current algorithm */ + QColor color4() const; + void setColor4(QColor algoColor); + + bool hasColor4() const; + void setHasColor4(bool hasColor); + + /** Get/set the color 2 of the current algorithm */ + QColor color5() const; + void setColor5(QColor algoColor); + + bool hasColor5() const; + void setHasColor5(bool hasColor); QString algoText() const; void setAlgoText(QString text); @@ -129,9 +155,15 @@ class RGBMatrixEditor : public FunctionEditor signals: void algorithmIndexChanged(); void algoColorsChanged(); - void startColorChanged(QColor startColor); - void endColorChanged(QColor endColor); - void hasEndColorChanged(bool hasEndColor); + void color1Changed(QColor color); + void color2Changed(QColor color); + void hasColor2Changed(bool hasColor); + void color3Changed(QColor color); + void hasColor3Changed(bool hasColor); + void color4Changed(QColor color); + void hasColor4Changed(bool hasColor); + void color5Changed(QColor color); + void hasColor5Changed(bool hasColor); void algoTextChanged(QString text); void algoTextFontChanged(QFont algoTextFont); diff --git a/qmlui/tardis/tardis.cpp b/qmlui/tardis/tardis.cpp index 4ff2212658..6c6b453ada 100644 --- a/qmlui/tardis/tardis.cpp +++ b/qmlui/tardis/tardis.cpp @@ -833,18 +833,36 @@ int Tardis::processAction(TardisAction &action, bool undo) matrix->setAlgorithm(algo); } break; - case RGBMatrixSetStartColor: + case RGBMatrixSetColor1: { auto member = std::mem_fn(&RGBMatrix::setColor); member(qobject_cast(m_doc->function(action.m_objID)), 0, value->value()); } break; - case RGBMatrixSetEndColor: + case RGBMatrixSetColor2: { auto member = std::mem_fn(&RGBMatrix::setColor); member(qobject_cast(m_doc->function(action.m_objID)), 1, value->value()); } break; + case RGBMatrixSetColor3: + { + auto member = std::mem_fn(&RGBMatrix::setColor); + member(qobject_cast(m_doc->function(action.m_objID)), 2, value->value()); + } + break; + case RGBMatrixSetColor4: + { + auto member = std::mem_fn(&RGBMatrix::setColor); + member(qobject_cast(m_doc->function(action.m_objID)), 3, value->value()); + } + break; + case RGBMatrixSetColor5: + { + auto member = std::mem_fn(&RGBMatrix::setColor); + member(qobject_cast(m_doc->function(action.m_objID)), 4, value->value()); + } + break; case RGBMatrixSetScriptIntValue: { RGBMatrix *matrix = qobject_cast(m_doc->function(action.m_objID)); diff --git a/qmlui/tardis/tardis.h b/qmlui/tardis/tardis.h index 25423569b1..a0b49ac087 100644 --- a/qmlui/tardis/tardis.h +++ b/qmlui/tardis/tardis.h @@ -124,8 +124,11 @@ class Tardis : public QThread RGBMatrixSetFixtureGroup, RGBMatrixSetAlgorithmIndex, - RGBMatrixSetStartColor, - RGBMatrixSetEndColor, + RGBMatrixSetColor1, + RGBMatrixSetColor2, + RGBMatrixSetColor3, + RGBMatrixSetColor4, + RGBMatrixSetColor5, RGBMatrixSetScriptIntValue, RGBMatrixSetScriptStringValue, RGBMatrixSetText, From 6d81e14fe443c29a44b8cb6097c83e12ecef65d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Fri, 17 Nov 2023 17:50:21 +0100 Subject: [PATCH 27/63] Update test to cope with up to 5 colors in apiVersion 3. --- engine/test/rgbscript/rgbscript_test.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/engine/test/rgbscript/rgbscript_test.cpp b/engine/test/rgbscript/rgbscript_test.cpp index 9a28b2a2b5..2e0bfc9b21 100644 --- a/engine/test/rgbscript/rgbscript_test.cpp +++ b/engine/test/rgbscript/rgbscript_test.cpp @@ -320,7 +320,10 @@ void RGBScript_Test::runScripts() QVERIFY(!s.author().isEmpty()); QVERIFY(!s.name().isEmpty()); QVERIFY(s.type() == RGBAlgorithm::Script); - QVERIFY(s.acceptColors() >= 0 && s.acceptColors() <= 2); + if (s.apiVersion() <= 2) + QVERIFY(s.acceptColors() >= 0 && s.acceptColors() <= 2); + else + QVERIFY(s.acceptColors() >= 0 && s.acceptColors() <= 5); int steps = s.rgbMapStepCount(mapSize); //qDebug() << "steps: " << steps; From b020f90cdcb68dfe9b1ffb7ce9a77a8d04e13cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Fri, 17 Nov 2023 19:34:53 +0100 Subject: [PATCH 28/63] Correct some errors in qml --- .../qml/fixturesfunctions/RGBMatrixEditor.qml | 66 +++++++++++++------ qmlui/rgbmatrixeditor.cpp | 12 ++-- 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml b/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml index 1e2cecdc96..16fbc41792 100644 --- a/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml +++ b/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml @@ -267,18 +267,18 @@ Rectangle Rectangle { - id: Color1Button + id: color1Button width: UISettings.iconSizeDefault * 2 height: editorColumn.itemsHeight radius: 5 - border.color: scMouseArea.containsMouse ? "white" : UISettings.bgLight + border.color: color1MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 color: rgbMatrixEditor.color1 visible: rgbMatrixEditor.algoColors > 0 ? true : false MouseArea { - id: scMouseArea + id: color1MouseArea anchors.fill: parent hoverEnabled: true onClicked: color1Tool.visible = !color1Tool.visible @@ -308,14 +308,14 @@ Rectangle width: UISettings.iconSizeDefault * 2 height: editorColumn.itemsHeight radius: 5 - border.color: ecMouseArea.containsMouse ? "white" : UISettings.bgLight + border.color: color2MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 color: rgbMatrixEditor.hasColor2 ? rgbMatrixEditor.color2 : "transparent" visible: rgbMatrixEditor.algoColors > 1 ? true : false MouseArea { - id: ecMouseArea + id: color2MouseArea anchors.fill: parent hoverEnabled: true onClicked: color2Tool.visible = !color2Tool.visible @@ -353,6 +353,21 @@ Rectangle width: editorColumn.colWidth height: editorColumn.itemsHeight spacing: 4 + visible: rgbMatrixEditor.algoColors > 4 ? true : false + + //leftPadding: Qt.binding(function() { return editorColumn.firstColumnWidth }) + Rectangle + { + id: colorRow1 + height: editorColumn.itemsHeight + color: "transparent" + visible: rgbMatrixEditor.algoColors > 4 ? true : false + onWidthChanged: + { + editorColumn.checkLabelWidth(width) + width = Qt.binding(function() { return editorColumn.firstColumnWidth }) + } + } Rectangle { @@ -360,14 +375,14 @@ Rectangle width: UISettings.iconSizeDefault * 2 height: editorColumn.itemsHeight radius: 5 - border.color: ecMouseArea.containsMouse ? "white" : UISettings.bgLight + border.color: color3MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 color: rgbMatrixEditor.hasColor3 ? rgbMatrixEditor.color3 : "transparent" - visible: rgbMatrixEditor.algoColors > 1 ? true : false + visible: rgbMatrixEditor.algoColors > 2 ? true : false MouseArea { - id: ecMouseArea + id: color3MouseArea anchors.fill: parent hoverEnabled: true onClicked: color3Tool.visible = !color3Tool.visible @@ -392,7 +407,7 @@ Rectangle width: UISettings.listItemHeight height: width imgSource: "qrc:/cancel.svg" - visible: rgbMatrixEditor.algoColors > 1 ? true : false + visible: rgbMatrixEditor.algoColors > 2 ? true : false onClicked: rgbMatrixEditor.hasColor3 = false } @@ -402,14 +417,14 @@ Rectangle width: UISettings.iconSizeDefault * 2 height: editorColumn.itemsHeight radius: 5 - border.color: ecMouseArea.containsMouse ? "white" : UISettings.bgLight + border.color: color4MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 color: rgbMatrixEditor.hasColor4 ? rgbMatrixEditor.color4 : "transparent" - visible: rgbMatrixEditor.algoColors > 1 ? true : false + visible: rgbMatrixEditor.algoColors > 3 ? true : false MouseArea { - id: ecMouseArea + id: color4MouseArea anchors.fill: parent hoverEnabled: true onClicked: color4Tool.visible = !color4Tool.visible @@ -434,13 +449,11 @@ Rectangle width: UISettings.listItemHeight height: width imgSource: "qrc:/cancel.svg" - visible: rgbMatrixEditor.algoColors > 1 ? true : false + visible: rgbMatrixEditor.algoColors > 3 ? true : false onClicked: rgbMatrixEditor.hasColor4 = false } // filler //Rectangle { Layout.fillWidth: true; height: parent.height; color: "transparent" } - // filler - //Rectangle { Layout.fillWidth: true; height: parent.height; color: "transparent" } } // row 8 @@ -449,6 +462,21 @@ Rectangle width: editorColumn.colWidth height: editorColumn.itemsHeight spacing: 4 + visible: rgbMatrixEditor.algoColors > 4 ? true : false + + //leftPadding: Qt.binding(function() { return editorColumn.firstColumnWidth }) + Rectangle + { + id: colorRow2 + height: editorColumn.itemsHeight + color: "transparent" + visible: rgbMatrixEditor.algoColors > 4 ? true : false + onWidthChanged: + { + editorColumn.checkLabelWidth(width) + width = Qt.binding(function() { return editorColumn.firstColumnWidth }) + } + } Rectangle { @@ -456,14 +484,14 @@ Rectangle width: UISettings.iconSizeDefault * 2 height: editorColumn.itemsHeight radius: 5 - border.color: ecMouseArea.containsMouse ? "white" : UISettings.bgLight + border.color: color5MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 color: rgbMatrixEditor.hasColor5 ? rgbMatrixEditor.color5 : "transparent" - visible: rgbMatrixEditor.algoColors > 1 ? true : false + visible: rgbMatrixEditor.algoColors > 4 ? true : false MouseArea { - id: ecMouseArea + id: color5MouseArea anchors.fill: parent hoverEnabled: true onClicked: color5Tool.visible = !color5Tool.visible @@ -488,7 +516,7 @@ Rectangle width: UISettings.listItemHeight height: width imgSource: "qrc:/cancel.svg" - visible: rgbMatrixEditor.algoColors > 1 ? true : false + visible: rgbMatrixEditor.algoColors > 4 ? true : false onClicked: rgbMatrixEditor.hasColor5 = false } // filler diff --git a/qmlui/rgbmatrixeditor.cpp b/qmlui/rgbmatrixeditor.cpp index 2af5bc5d77..b68ca4bddd 100644 --- a/qmlui/rgbmatrixeditor.cpp +++ b/qmlui/rgbmatrixeditor.cpp @@ -208,12 +208,12 @@ QColor RGBMatrixEditor::color3() const if (m_matrix == nullptr) return QColor(); - return m_matrix->getColor(1); + return m_matrix->getColor(2); } void RGBMatrixEditor::setColor3(QColor algoColor) { - if (m_matrix == nullptr || m_matrix->getColor(1) == algoColor) + if (m_matrix == nullptr || m_matrix->getColor(2) == algoColor) return; Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor3, m_matrix->id(), m_matrix->getColor(2), algoColor); @@ -229,12 +229,12 @@ QColor RGBMatrixEditor::color4() const if (m_matrix == nullptr) return QColor(); - return m_matrix->getColor(1); + return m_matrix->getColor(3); } void RGBMatrixEditor::setColor4(QColor algoColor) { - if (m_matrix == nullptr || m_matrix->getColor(1) == algoColor) + if (m_matrix == nullptr || m_matrix->getColor(3) == algoColor) return; Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor4, m_matrix->id(), m_matrix->getColor(3), algoColor); @@ -250,12 +250,12 @@ QColor RGBMatrixEditor::color5() const if (m_matrix == nullptr) return QColor(); - return m_matrix->getColor(1); + return m_matrix->getColor(4); } void RGBMatrixEditor::setColor5(QColor algoColor) { - if (m_matrix == nullptr || m_matrix->getColor(1) == algoColor) + if (m_matrix == nullptr || m_matrix->getColor(4) == algoColor) return; Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor5, m_matrix->id(), m_matrix->getColor(4), algoColor); From 7f6e799423b9d6f36f5b8a41c84f8c23b92a5e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Sat, 16 Dec 2023 19:54:34 +0100 Subject: [PATCH 29/63] Thorough review and related fixes. --- engine/src/rgbalgorithm.cpp | 15 +- engine/src/rgbalgorithm.h | 7 +- engine/src/rgbaudio.cpp | 14 +- qmlui/rgbmatrixeditor.cpp | 7 +- qmlui/rgbmatrixeditor.h | 1 + qmlui/tardis/tardis.h | 6 +- resources/rgbscripts/devtool.html | 24 +- resources/rgbscripts/devtool/devtool.js | 126 ++- ui/src/rgbmatrixeditor.cpp | 21 +- ui/src/rgbmatrixeditor.ui | 1010 +++++++++--------- ui/src/virtualconsole/vcmatrix.cpp | 265 +++-- ui/src/virtualconsole/vcmatrix.h | 37 +- ui/src/virtualconsole/vcmatrixcontrol.cpp | 42 +- ui/src/virtualconsole/vcmatrixcontrol.h | 14 +- ui/src/virtualconsole/vcmatrixproperties.cpp | 60 +- 15 files changed, 868 insertions(+), 781 deletions(-) diff --git a/engine/src/rgbalgorithm.cpp b/engine/src/rgbalgorithm.cpp index 81b66f7731..9d84c71a17 100644 --- a/engine/src/rgbalgorithm.cpp +++ b/engine/src/rgbalgorithm.cpp @@ -39,11 +39,13 @@ RGBAlgorithm::RGBAlgorithm(Doc * doc) : m_doc(doc) - , m_colors{ - QColor(), // was m_startColor - QColor() // was m_endColor - } { + Q_ASSERT(5 == RGBAlgorithmRawColorCount); + m_colors[0] = QColor(); + m_colors[1] = QColor(); + m_colors[2] = QColor(); + m_colors[3] = QColor(); + m_colors[4] = QColor(); } void RGBAlgorithm::setColors(QColor colors[RGBAlgorithmRawColorCount]) @@ -52,6 +54,11 @@ void RGBAlgorithm::setColors(QColor colors[RGBAlgorithmRawColorCount]) m_colors[i] = colors[i]; } +QColor RGBAlgorithm::getColor(unsigned int i) const +{ + return m_colors[i]; +} + /**************************************************************************** * Available algorithms ****************************************************************************/ diff --git a/engine/src/rgbalgorithm.h b/engine/src/rgbalgorithm.h index a0eef212df..566458e886 100644 --- a/engine/src/rgbalgorithm.h +++ b/engine/src/rgbalgorithm.h @@ -104,12 +104,11 @@ class RGBAlgorithm * RGB Colors ************************************************************************/ public: - /** Set the start/end color the algorithm can use */ + /** Set the colors the algorithm can use */ virtual void setColors(QColor[RGBAlgorithmRawColorCount]); - QColor startColor() { return m_colors[0]; } - - QColor endColor() { return m_colors[1]; } + /** Get the color which is set for the algorithm */ + virtual QColor getColor(unsigned int i) const; private: QColor m_colors[RGBAlgorithmRawColorCount]; diff --git a/engine/src/rgbaudio.cpp b/engine/src/rgbaudio.cpp index 34bf7fcf49..d531a168c8 100644 --- a/engine/src/rgbaudio.cpp +++ b/engine/src/rgbaudio.cpp @@ -86,19 +86,21 @@ void RGBAudio::calculateColors(int barsHeight) { if (barsHeight > 0) { + QColor startColor = getColor(0); + QColor endColor = getColor(1); m_barColors.clear(); - if (endColor() == QColor() + if (endColor == QColor() || barsHeight == 1) // to avoid division by 0 below { for (int i = 0; i < barsHeight; i++) - m_barColors.append(startColor().rgb()); + m_barColors.append(startColor.rgb()); } else { - int crDelta = (endColor().red() - startColor().red()) / (barsHeight - 1); - int cgDelta = (endColor().green() - startColor().green()) / (barsHeight - 1); - int cbDelta = (endColor().blue() - startColor().blue()) / (barsHeight - 1); - QColor pixelColor = startColor(); + int crDelta = (endColor.red() - startColor.red()) / (barsHeight - 1); + int cgDelta = (endColor.green() - startColor.green()) / (barsHeight - 1); + int cbDelta = (endColor.blue() - startColor.blue()) / (barsHeight - 1); + QColor pixelColor = startColor; for (int i = 0; i < barsHeight; i++) { diff --git a/qmlui/rgbmatrixeditor.cpp b/qmlui/rgbmatrixeditor.cpp index b68ca4bddd..bb542d248a 100644 --- a/qmlui/rgbmatrixeditor.cpp +++ b/qmlui/rgbmatrixeditor.cpp @@ -134,12 +134,13 @@ void RGBMatrixEditor::setAlgorithmIndex(int algoIndex) /** if we're setting the same algorithm, then there's nothing to do */ if (m_matrix->algorithm() != nullptr && m_matrix->algorithm()->name() == algo->name()) return; + Q_ASSERT(5 == RGBAlgorithmRawColorCount); QColor colors[RGBAlgorithmRawColorCount] = { m_matrix->getColor(0), m_matrix->getColor(1), - m_matrix->getColor(2), - m_matrix->getColor(3), - m_matrix->getColor(4) + m_matrix->getColor(2), + m_matrix->getColor(3), + m_matrix->getColor(4) }; algo->setColors(colors); } diff --git a/qmlui/rgbmatrixeditor.h b/qmlui/rgbmatrixeditor.h index 6f6812a561..8b3ccdf69b 100644 --- a/qmlui/rgbmatrixeditor.h +++ b/qmlui/rgbmatrixeditor.h @@ -50,6 +50,7 @@ class RGBMatrixEditor : public FunctionEditor Q_PROPERTY(bool hasColor5 READ hasColor5 WRITE setHasColor5 NOTIFY hasColor5Changed) Q_PROPERTY(int blendMode READ blendMode WRITE setBlendMode NOTIFY blendModeChanged) + Q_PROPERTY(int controlMode READ controlMode WRITE setControlMode NOTIFY controlModeChanged) // Text Algorithm specific properties Q_PROPERTY(QString algoText READ algoText WRITE setAlgoText NOTIFY algoTextChanged) diff --git a/qmlui/tardis/tardis.h b/qmlui/tardis/tardis.h index a0b49ac087..087b3d6bf5 100644 --- a/qmlui/tardis/tardis.h +++ b/qmlui/tardis/tardis.h @@ -126,9 +126,9 @@ class Tardis : public QThread RGBMatrixSetAlgorithmIndex, RGBMatrixSetColor1, RGBMatrixSetColor2, - RGBMatrixSetColor3, - RGBMatrixSetColor4, - RGBMatrixSetColor5, + RGBMatrixSetColor3, + RGBMatrixSetColor4, + RGBMatrixSetColor5, RGBMatrixSetScriptIntValue, RGBMatrixSetScriptStringValue, RGBMatrixSetText, diff --git a/resources/rgbscripts/devtool.html b/resources/rgbscripts/devtool.html index da5077dd6d..a17d71c7f5 100644 --- a/resources/rgbscripts/devtool.html +++ b/resources/rgbscripts/devtool.html @@ -128,13 +128,25 @@

Grid Size

Pixel colors

- - - + + + + + + + + + + + + + + + - - - + + +
Primary color (rrggbb)
Color 1 (rrggbb)
Color 2 (rrggbb, leave empty to disable)
Color 3 (rrggbb, leave empty to disable)
Color 4 (rrggbb, leave empty to disable)
Secondary color (rrggbb, leave empty to disable)
Color 5 (rrggbb, leave empty to disable)
diff --git a/resources/rgbscripts/devtool/devtool.js b/resources/rgbscripts/devtool/devtool.js index 8b13f2138e..4f3c7c47a4 100644 --- a/resources/rgbscripts/devtool/devtool.js +++ b/resources/rgbscripts/devtool/devtool.js @@ -178,11 +178,24 @@ devtool.initProperties = function() devtool.initPixelColors = function() { + var acceptColors = parseInt(testAlgo.acceptColors, 10); + if (isNaN(acceptColors)) { + acceptColors = 0; + } var pixelColorChooser = document.getElementById("pixelColorChooser"); - pixelColorChooser.hidden = testAlgo.acceptColors === 0; + pixelColorChooser.hidden = (acceptColors === 0); + + var color2Chooser = document.getElementById("color2Chooser"); + color2Chooser.hidden = (acceptColors <= 2); + + var color3Chooser = document.getElementById("color3Chooser"); + color3Chooser.hidden = (acceptColors <= 3); - var secondaryColorChooser = document.getElementById("secondaryColorChooser"); - secondaryColorChooser.hidden = testAlgo.acceptColors === 1; + var color4Chooser = document.getElementById("color4Chooser"); + color4Chooser.hidden = (acceptColors <= 4); + + var color5Chooser = document.getElementById("color5Chooser"); + color5Chooser.hidden = (acceptColors <= 5); } devtool.initSpeedValue = function() @@ -207,16 +220,34 @@ devtool.initAlternateValue = function() devtool.initColorValues = function() { - var primary = localStorage.getItem("devtool.primaryColor"); - if (primary === null || Number.isNaN(parseInt("0x" + primary, 16))) { - primary = "ff0000"; + var color1 = localStorage.getItem("devtool.color1"); + if (color1 === null || Number.isNaN(parseInt("0x" + color1, 16))) { + color1 = "ff0000"; + } + document.getElementById("color1").value = color1; + var color2 = localStorage.getItem("devtool.color2"); + if (color2 === null || color2 === "" || Number.isNaN(parseInt("0x" + color2, 16))) { + document.getElementById("color2").value = ""; + } else { + document.getElementById("color2").value = color2; + } + var color3 = localStorage.getItem("devtool.color3"); + if (color3 === null || color2 === "" || Number.isNaN(parseInt("0x" + color3, 16))) { + document.getElementById("color3").value = ""; + } else { + document.getElementById("color3").value = color3; + } + var color4 = localStorage.getItem("devtool.color4"); + if (color4 === null || color4 === "" || Number.isNaN(parseInt("0x" + color4, 16))) { + document.getElementById("color4").value = ""; + } else { + document.getElementById("color4").value = color2; } - document.getElementById("primaryColor").value = primary; - var secondary = localStorage.getItem("devtool.secondaryColor"); - if (secondary === null || secondary === "" || Number.isNaN(parseInt("0x" + secondary, 16))) { - document.getElementById("secondaryColor").value = ""; + var color5 = localStorage.getItem("devtool.color5"); + if (color5 === null || color5 === "" || Number.isNaN(parseInt("0x" + color5, 16))) { + document.getElementById("color5").value = ""; } else { - document.getElementById("secondaryColor").value = secondary; + document.getElementById("color5").value = color25; } } @@ -247,22 +278,40 @@ devtool.getRgbFromColorInt = function(color) return [red, green, blue]; } -devtool.getPrimaryColorInt = function() +devtool.getColor1Int = function() +{ + var colorInput = document.getElementById("color1"); + return parseInt(colorInput.value, 16); +} + +devtool.getColor2Int = function() { - var primaryColorInput = document.getElementById("primaryColor"); - return parseInt(primaryColorInput.value, 16); + var colorInput = document.getElementById("color2"); + return parseInt(colorInput.value, 16); } -devtool.getSecondaryColorInt = function() +devtool.getColor3Int = function() { - var secondaryColorInput = document.getElementById("secondaryColor"); - return parseInt(secondaryColorInput.value, 16); + var colorInput = document.getElementById("color3"); + return parseInt(colorInput.value, 16); +} + +devtool.getColor4Int = function() +{ + var colorInput = document.getElementById("color4"); + return parseInt(colorInput.value, 16); +} + +devtool.getColor5Int = function() +{ + var colorInput = document.getElementById("color5"); + return parseInt(colorInput.value, 16); } devtool.getCurrentColorInt = function() { - var primaryColor = devtool.getPrimaryColorInt(); - var secondaryColor = devtool.getSecondaryColorInt(); + var primaryColor = devtool.getcolor1Int(); + var secondaryColor = devtool.getcolor2Int(); if (testAlgo.acceptColors === 0 || Number.isNaN(primaryColor)) { return null; @@ -294,9 +343,12 @@ devtool.writeCurrentStep = function() map.deleteRow(i); } - var primaryColorRgb = devtool.getPrimaryColorInt(); - var secondaryColorRgb = devtool.getSecondaryColorInt(); - var rawColors = [primaryColorRgb, secondaryColorRgb]; + var color1Rgb = devtool.getColor1Int(); + var color2Rgb = devtool.getColor2Int(); + var color3Rgb = devtool.getColor3Int(); + var color4Rgb = devtool.getColor4Int(); + var color5Rgb = devtool.getColor5Int(); + var rawColors = [color1Rgb, color2Rgb, color3Rgb, color4Rgb, color5Rgb]; var rgb; if (testAlgo.apiVersion > 2) { @@ -363,13 +415,31 @@ devtool.onGridSizeUpdated = function() devtool.onColorChange = function() { - var primary = parseInt("0x" + document.getElementById("primaryColor").value).toString(16); - localStorage.setItem("devtool.primaryColor", primary); - var secondary = parseInt("0x" + document.getElementById("secondaryColor").value).toString(16); - if (secondary === "NaN") { // Evaluation of the string. - localStorage.setItem("devtool.secondaryColor", ""); + var color1 = parseInt("0x" + document.getElementById("color1").value).toString(16); + localStorage.setItem("devtool.color1", color1); + var color2 = parseInt("0x" + document.getElementById("color2").value).toString(16); + if (color2 === "NaN") { // Evaluation of the string. + localStorage.setItem("devtool.color2", ""); + } else { + localStorage.setItem("devtool.color2", color2); + } + var color3 = parseInt("0x" + document.getElementById("color3").value).toString(16); + if (color3 === "NaN") { // Evaluation of the string. + localStorage.setItem("devtool.color3", ""); + } else { + localStorage.setItem("devtool.color3", color3); + } + var color4 = parseInt("0x" + document.getElementById("color4").value).toString(16); + if (color4 === "NaN") { // Evaluation of the string. + localStorage.setItem("devtool.color4", ""); + } else { + localStorage.setItem("devtool.color4", color4); + } + var color5 = parseInt("0x" + document.getElementById("color5").value).toString(16); + if (color5 === "NaN") { // Evaluation of the string. + localStorage.setItem("devtool.color5", ""); } else { - localStorage.setItem("devtool.secondaryColor", secondary); + localStorage.setItem("devtool.color5", color5); } devtool.writeCurrentStep(); } diff --git a/ui/src/rgbmatrixeditor.cpp b/ui/src/rgbmatrixeditor.cpp index fa77aa048a..4227db849c 100644 --- a/ui/src/rgbmatrixeditor.cpp +++ b/ui/src/rgbmatrixeditor.cpp @@ -221,23 +221,23 @@ void RGBMatrixEditor::init() connect(m_controlModeCombo, SIGNAL(activated(int)), this, SLOT(slotControlModeChanged(int))); connect(m_mtxColor1Button, SIGNAL(clicked()), - this, SLOT(slotMtxColorButton1Clicked())); + this, SLOT(slotMtxColor1ButtonClicked())); connect(m_mtxColor2Button, SIGNAL(clicked()), this, SLOT(slotMtxColor2ButtonClicked())); connect(m_resetMtxColor2Button, SIGNAL(clicked()), this, SLOT(slotResetMtxColor2ButtonClicked())); connect(m_mtxColor3Button, SIGNAL(clicked()), - this, SLOT(slotMtxColor2ButtonClicked())); + this, SLOT(slotMtxColor3ButtonClicked())); connect(m_resetMtxColor3Button, SIGNAL(clicked()), - this, SLOT(slotResetMtxColor2ButtonClicked())); + this, SLOT(slotResetMtxColor3ButtonClicked())); connect(m_mtxColor4Button, SIGNAL(clicked()), - this, SLOT(slotMtxColor2ButtonClicked())); + this, SLOT(slotMtxColor4ButtonClicked())); connect(m_resetMtxColor4Button, SIGNAL(clicked()), - this, SLOT(slotResetMtxColor2ButtonClicked())); + this, SLOT(slotResetMtxColor4ButtonClicked())); connect(m_mtxColor5Button, SIGNAL(clicked()), - this, SLOT(slotMtxColor2ButtonClicked())); + this, SLOT(slotMtxColor5ButtonClicked())); connect(m_resetMtxColor5Button, SIGNAL(clicked()), - this, SLOT(slotResetMtxColor2ButtonClicked())); + this, SLOT(slotResetMtxColor5ButtonClicked())); connect(m_textEdit, SIGNAL(textEdited(const QString&)), this, SLOT(slotTextEdited(const QString&))); connect(m_fontButton, SIGNAL(clicked()), @@ -809,9 +809,9 @@ void RGBMatrixEditor::slotPatternActivated(const QString& text) QColor colors[RGBAlgorithmRawColorCount] = { m_matrix->getColor(0), m_matrix->getColor(1), - m_matrix->getColor(2), - m_matrix->getColor(3), - m_matrix->getColor(4) + m_matrix->getColor(2), + m_matrix->getColor(3), + m_matrix->getColor(4) }; algo->setColors(colors); } @@ -942,7 +942,6 @@ void RGBMatrixEditor::slotMtxColor5ButtonClicked() void RGBMatrixEditor::slotResetMtxColor5ButtonClicked() { m_matrix->setColor(4, QColor()); - m_previewHandler->calculateColorDelta(m_matrix->getColor(3), m_matrix->getColor(4)); updateColors(); slotRestartTest(); } diff --git a/ui/src/rgbmatrixeditor.ui b/ui/src/rgbmatrixeditor.ui index 4aedda5445..45037d0097 100644 --- a/ui/src/rgbmatrixeditor.ui +++ b/ui/src/rgbmatrixeditor.ui @@ -26,7 +26,7 @@ 0 0 575 - 728 + 798
@@ -45,10 +45,181 @@ - - + + + + + 0 + 0 + + + + Other Controls + + + + 4 + + + 4 + + + + + Set the dimmer channel of fixtures to 100% + + + Dimmer control + + + + + + + + - + + + + 0 + 0 + + + + RGB matrix name + + + + + + + + 0 + 0 + + + + The name of this RGB matrix function + + + + + + + + + + + Show/Hide speed dial window + + + + :/speed.png:/speed.png + + + + 28 + 28 + + + + true + + + + + + + Save this matrix to a sequence + + + + + + + :/sequence.png:/sequence.png + + + + 28 + 28 + + + + + + + + Toggle between circle and square preview + + + + :/square.png:/square.png + + + + 28 + 28 + + + + true + + + + + + + See what the RGB Matrix does when it is run + + + + :/player_play.png:/player_play.png + + + + 28 + 28 + + + + true + + + + + + + + 0 + 0 + + + + Fixture group + + + + + + + + 0 + 0 + + + + The fixture group to use as the pixel matrix + + + + + + + + + 0 @@ -56,113 +227,140 @@ - Pattern + Run Order - + 4 4 - - 4 - - - + + - Matrix color 1 + Run through over and over again - - - 50 - 26 - + + Loop + + + true - - + + - Matrix color 2 + Run through once and stop - - - - - 50 - 26 - + Single Shot - - + + - Reset the end color + First run forwards, then backwards, again forwards, etc. - - - :/fileclose.png:/fileclose.png + + Ping Pong - - + + + + + + + + 0 + 0 + + + + Direction + + + + 4 + + + 4 + + + - Matrix color 3 + Start from the first step - - - 50 - 26 - + + Forward + + + true - - + + - Reset the end color + Start from the last step - - - :/fileclose.png:/fileclose.png + + Backward - - - - Matrix color 4 + + + + Qt::Vertical - - + + QSizePolicy::Maximum - + - 50 - 26 + 20 + 35 - - - - - - Reset the end color - - - - :/fileclose.png:/fileclose.png - - + - - + + + + + + + + + + + + 0 + 0 + + + + Pattern + + + + 4 + + + 4 + + + 4 + + + - Matrix color 5 + Matrix color 3 @@ -172,25 +370,20 @@ - - + + - Reset the end color - - - - :/fileclose.png:/fileclose.png + Matrix color 1 - - - - - - The RGB matrix pattern + + + 50 + 26 + - + @@ -214,21 +407,56 @@ - + + + + Control mode + + + + + + + Matrix color 5 + + + + 50 + 26 + + + + + + + + Reset color 2 + + + + :/fileclose.png:/fileclose.png + + + + Blend mode - - - - Control mode + + + + Reset color 3 + + + + :/fileclose.png:/fileclose.png - + @@ -262,448 +490,203 @@ - - - - - - - Properties - - - - 4 - - - 4 - - - 4 - - - - - - - - - - - Animated Text - - - - 4 - - - 4 - - - 4 - - - - - - 0 - 0 - - - - Text to display - - - - - + + - Choose the font - - - - - - - :/fonts.png:/fonts.png - - - - 32 - 32 - + The RGB matrix pattern - - + + - Animation style - - - - - - - - - - Image - - - - 4 - - - 4 - - - 4 - - - - - - 0 - 0 - + Matrix color 2 - - - - - - - - - :/image.png:/image.png + - 32 - 32 + 50 + 26 - - - - - - - - - - Offset - - - - 4 - - - 4 - - - - - X - - - - - - - Shift the pattern X pixels horizontally - - - -255 - - - 255 - - - - - - - Y - - - - - - - Shift the pattern Y pixels vertically - - - -255 - - - 255 - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 40 - - - - - - - - - - - 0 - 0 - - - - Other Controls - - - - 4 - - - 4 - - - - - Set the dimmer channel of fixtures to 100% - - - Dimmer control - - - - - - - - - - - - - 0 - 0 - - - - RGB matrix name - - - - - - - - 0 - 0 - - - - The name of this RGB matrix function - - - - - - - - - - - Show/Hide speed dial window - - - - :/speed.png:/speed.png - - - - 28 - 28 - - - - true - - - - - - - Save this matrix to a sequence - - - - - - - :/sequence.png:/sequence.png - - - - 28 - 28 - - - - - - - - Toggle between circle and square preview - - - - :/square.png:/square.png - - - - 28 - 28 - - - - true - - - - - - - See what the RGB Matrix does when it is run - - - - :/player_play.png:/player_play.png - - - - 28 - 28 - - - - true - + + + + Matrix color 4 + + + + + + + 50 + 26 + + + + + + + + Reset color 4 + + + + :/fileclose.png:/fileclose.png + + + + + + + Reset color 5 + + + + :/fileclose.png:/fileclose.png + + + +
- - - - 0 - 0 - - - - Fixture group + + + Properties + + + 4 + + + 4 + + + 4 + + + + + - - - - 0 - 0 - - - - The fixture group to use as the pixel matrix - - - -
-
- - - - - - - 0 - 0 - - + - Run Order + Animated Text - + 4 4 - - - - Run through over and over again - - - Loop + + 4 + + + + + + 0 + 0 + - - true + + Text to display - - + + - Run through once and stop + Choose the font - Single Shot + + + + + :/fonts.png:/fonts.png + + + + 32 + 32 + - - + + - First run forwards, then backwards, again forwards, etc. + Animation style + + + + + + + + + + Image + + + + 4 + + + 4 + + + 4 + + + + + + 0 + 0 + + + + + - Ping Pong + + + + + :/image.png:/image.png + + + + 32 + 32 + + + + - - - - - 0 - 0 - - + + - Direction + Offset - + 4 @@ -711,47 +694,64 @@ 4 - - - Start from the first step - + - Forward - - - true + X - + - Start from the last step + Shift the pattern X pixels horizontally + + + -255 + + 255 + + + + + - Backward + Y - - - Qt::Vertical + + + Shift the pattern Y pixels vertically - - QSizePolicy::Maximum + + -255 - - - 20 - 35 - + + 255 - +
+ + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 40 + + + +
diff --git a/ui/src/virtualconsole/vcmatrix.cpp b/ui/src/virtualconsole/vcmatrix.cpp index 6dd99557fc..f5f8f7aab3 100644 --- a/ui/src/virtualconsole/vcmatrix.cpp +++ b/ui/src/virtualconsole/vcmatrix.cpp @@ -81,89 +81,89 @@ VCMatrix::VCMatrix(QWidget *parent, Doc *doc) QVBoxLayout *vbox = new QVBoxLayout(); /* Start Color Button */ - m_mtxColorButton1 = new QToolButton(this); - m_mtxColorButton1->setFixedSize(48, 48); - m_mtxColorButton1->setIconSize(QSize(42, 42)); + m_mtxColor1Button = new QToolButton(this); + m_mtxColor1Button->setFixedSize(48, 48); + m_mtxColor1Button->setIconSize(QSize(42, 42)); QWidgetAction* scAction = new QWidgetAction(this); - m_mtxCnGWidget1 = new ClickAndGoWidget(); - m_mtxCnGWidget1->setType(ClickAndGoWidget::RGB, NULL); - scAction->setDefaultWidget(m_mtxCnGWidget1); + m_mtxColor1CnGWidget = new ClickAndGoWidget(); + m_mtxColor1CnGWidget->setType(ClickAndGoWidget::RGB, NULL); + scAction->setDefaultWidget(m_mtxColor1CnGWidget); QMenu *color1Menu = new QMenu(); color1Menu->addAction(scAction); - m_mtxColorButton1->setMenu(color1Menu); - m_mtxColorButton1->setPopupMode(QToolButton::InstantPopup); + m_mtxColor1Button->setMenu(color1Menu); + m_mtxColor1Button->setPopupMode(QToolButton::InstantPopup); - connect(m_mtxCnGWidget1, SIGNAL(colorChanged(QRgb)), - this, SLOT(slotStartColorChanged(QRgb))); + connect(m_mtxColor1CnGWidget, SIGNAL(colorChanged(QRgb)), + this, SLOT(slotColor1Changed(QRgb))); /* End Color Button */ - m_mtxColorButton2 = new QToolButton(this); - m_mtxColorButton2->setFixedSize(48, 48); - m_mtxColorButton2->setIconSize(QSize(42, 42)); + m_mtxColor2Button = new QToolButton(this); + m_mtxColor2Button->setFixedSize(48, 48); + m_mtxColor2Button->setIconSize(QSize(42, 42)); QWidgetAction* ecAction2 = new QWidgetAction(this); - m_mtxCnGWidget2 = new ClickAndGoWidget(); - m_mtxCnGWidget2->setType(ClickAndGoWidget::RGB, NULL); - ecAction2->setDefaultWidget(m_mtxCnGWidget2); + m_mtxColor2CnGWidget = new ClickAndGoWidget(); + m_mtxColor2CnGWidget->setType(ClickAndGoWidget::RGB, NULL); + ecAction2->setDefaultWidget(m_mtxColor2CnGWidget); QMenu *color2Menu = new QMenu(); color2Menu->addAction(ecAction2); - m_mtxColorButton2->setMenu(color2Menu); - m_mtxColorButton2->setPopupMode(QToolButton::InstantPopup); + m_mtxColor2Button->setMenu(color2Menu); + m_mtxColor2Button->setPopupMode(QToolButton::InstantPopup); - connect(m_mtxCnGWidget2, SIGNAL(colorChanged(QRgb)), - this, SLOT(slotEndColorChanged(QRgb))); + connect(m_mtxColor2CnGWidget, SIGNAL(colorChanged(QRgb)), + this, SLOT(slotColor2Changed(QRgb))); /* 3rd Color Button */ - m_mtxColorButton3 = new QToolButton(this); - m_mtxColorButton3->setFixedSize(48, 48); - m_mtxColorButton3->setIconSize(QSize(42, 42)); + m_mtxColor3Button = new QToolButton(this); + m_mtxColor3Button->setFixedSize(48, 48); + m_mtxColor3Button->setIconSize(QSize(42, 42)); QWidgetAction* ecAction3 = new QWidgetAction(this); - m_mtxCnGWidget3 = new ClickAndGoWidget(); - m_mtxCnGWidget3->setType(ClickAndGoWidget::RGB, NULL); - ecAction3->setDefaultWidget(m_mtxCnGWidget3); + m_mtxColor3CnGWidget = new ClickAndGoWidget(); + m_mtxColor3CnGWidget->setType(ClickAndGoWidget::RGB, NULL); + ecAction3->setDefaultWidget(m_mtxColor3CnGWidget); QMenu *color3Menu = new QMenu(); color3Menu->addAction(ecAction3); - m_mtxColorButton3->setMenu(color3Menu); - m_mtxColorButton3->setPopupMode(QToolButton::InstantPopup); + m_mtxColor3Button->setMenu(color3Menu); + m_mtxColor3Button->setPopupMode(QToolButton::InstantPopup); - connect(m_mtxCnGWidget3, SIGNAL(colorChanged(QRgb)), - this, SLOT(slotEndColorChanged(QRgb))); + connect(m_mtxColor3CnGWidget, SIGNAL(colorChanged(QRgb)), + this, SLOT(slotColor3Changed(QRgb))); /* 4th Color Button */ - m_mtxColorButton4 = new QToolButton(this); - m_mtxColorButton4->setFixedSize(48, 48); - m_mtxColorButton4->setIconSize(QSize(42, 42)); + m_mtxColor4Button = new QToolButton(this); + m_mtxColor4Button->setFixedSize(48, 48); + m_mtxColor4Button->setIconSize(QSize(42, 42)); QWidgetAction* ecAction4 = new QWidgetAction(this); - m_mtxCnGWidget4 = new ClickAndGoWidget(); - m_mtxCnGWidget4->setType(ClickAndGoWidget::RGB, NULL); - ecAction4->setDefaultWidget(m_mtxCnGWidget4); + m_mtxColor4CnGWidget = new ClickAndGoWidget(); + m_mtxColor4CnGWidget->setType(ClickAndGoWidget::RGB, NULL); + ecAction4->setDefaultWidget(m_mtxColor4CnGWidget); QMenu *color4Menu = new QMenu(); color4Menu->addAction(ecAction4); - m_mtxColorButton4->setMenu(color4Menu); - m_mtxColorButton4->setPopupMode(QToolButton::InstantPopup); + m_mtxColor4Button->setMenu(color4Menu); + m_mtxColor4Button->setPopupMode(QToolButton::InstantPopup); - connect(m_mtxCnGWidget4, SIGNAL(colorChanged(QRgb)), - this, SLOT(slotEndColorChanged(QRgb))); + connect(m_mtxColor4CnGWidget, SIGNAL(colorChanged(QRgb)), + this, SLOT(slotColor4Changed(QRgb))); /* 5th Color Button */ - m_mtxColorButton5 = new QToolButton(this); - m_mtxColorButton5->setFixedSize(48, 48); - m_mtxColorButton5->setIconSize(QSize(42, 42)); + m_mtxColor5Button = new QToolButton(this); + m_mtxColor5Button->setFixedSize(48, 48); + m_mtxColor5Button->setIconSize(QSize(42, 42)); QWidgetAction* ecAction5 = new QWidgetAction(this); - m_mtxCnGWidget5 = new ClickAndGoWidget(); - m_mtxCnGWidget5->setType(ClickAndGoWidget::RGB, NULL); - ecAction5->setDefaultWidget(m_mtxCnGWidget5); + m_mtxColor5CnGWidget = new ClickAndGoWidget(); + m_mtxColor5CnGWidget->setType(ClickAndGoWidget::RGB, NULL); + ecAction5->setDefaultWidget(m_mtxColor5CnGWidget); QMenu *color5Menu = new QMenu(); color5Menu->addAction(ecAction5); - m_mtxColorButton5->setMenu(color5Menu); - m_mtxColorButton5->setPopupMode(QToolButton::InstantPopup); + m_mtxColor5Button->setMenu(color5Menu); + m_mtxColor5Button->setPopupMode(QToolButton::InstantPopup); - connect(m_mtxCnGWidget5, SIGNAL(colorChanged(QRgb)), - this, SLOT(slotEndColorChanged(QRgb))); + connect(m_mtxColor5CnGWidget, SIGNAL(colorChanged(QRgb)), + this, SLOT(slotColor5Changed(QRgb))); m_label = new QLabel(this); m_label->setAlignment(Qt::AlignCenter); @@ -172,11 +172,11 @@ VCMatrix::VCMatrix(QWidget *parent, Doc *doc) QHBoxLayout *btnHbox = new QHBoxLayout(); - btnHbox->addWidget(m_mtxColorButton1); - btnHbox->addWidget(m_mtxColorButton2); - btnHbox->addWidget(m_mtxColorButton3); - btnHbox->addWidget(m_mtxColorButton4); - btnHbox->addWidget(m_mtxColorButton5); + btnHbox->addWidget(m_mtxColor1Button); + btnHbox->addWidget(m_mtxColor2Button); + btnHbox->addWidget(m_mtxColor3Button); + btnHbox->addWidget(m_mtxColor4Button); + btnHbox->addWidget(m_mtxColor5Button); vbox->addLayout(btnHbox); @@ -281,11 +281,11 @@ void VCMatrix::setCaption(const QString &text) void VCMatrix::enableWidgetUI(bool enable) { m_slider->setEnabled(enable); - m_mtxColorButton1->setEnabled(enable); - m_mtxColorButton2->setEnabled(enable); - m_mtxColorButton3->setEnabled(enable); - m_mtxColorButton4->setEnabled(enable); - m_mtxColorButton5->setEnabled(enable); + m_mtxColor1Button->setEnabled(enable); + m_mtxColor2Button->setEnabled(enable); + m_mtxColor3Button->setEnabled(enable); + m_mtxColor4Button->setEnabled(enable); + m_mtxColor5Button->setEnabled(enable); m_presetCombo->setEnabled(enable); foreach(QWidget *ctlBtn, m_controls.keys()) @@ -328,12 +328,12 @@ void VCMatrix::slotSliderMoved(int value) } } -void VCMatrix::slotColorChanged1(QRgb color) +void VCMatrix::slotColor1Changed(QRgb color) { QColor col(color); QPixmap px(42, 42); px.fill(col); - m_mtxColorButton1->setIcon(px); + m_mtxColor1Button->setIcon(px); RGBMatrix* matrix = qobject_cast(m_doc->function(m_matrixID)); if (matrix == NULL || mode() == Doc::Design) @@ -344,12 +344,12 @@ void VCMatrix::slotColorChanged1(QRgb color) matrix->updateColorDelta(); } -void VCMatrix::slotColorChanged2(QRgb color) +void VCMatrix::slotColor2Changed(QRgb color) { QColor col(color); QPixmap px(42, 42); px.fill(col); - m_mtxColorButton2->setIcon(px); + m_mtxColor2Button->setIcon(px); RGBMatrix* matrix = qobject_cast(m_doc->function(m_matrixID)); if (matrix == NULL || mode() == Doc::Design) @@ -360,52 +360,46 @@ void VCMatrix::slotColorChanged2(QRgb color) matrix->updateColorDelta(); } -void VCMatrix::slotColorChanged3(QRgb color) +void VCMatrix::slotColor3Changed(QRgb color) { QColor col(color); QPixmap px(42, 42); px.fill(col); - m_mtxColorButton3->setIcon(px); + m_mtxColor3Button->setIcon(px); RGBMatrix* matrix = qobject_cast(m_doc->function(m_matrixID)); if (matrix == NULL || mode() == Doc::Design) return; - matrix->setColor(1, col); - if (instantChanges() == true) - matrix->updateColorDelta(); + matrix->setColor(2, col); } -void VCMatrix::slotColorChanged4(QRgb color) +void VCMatrix::slotColor4Changed(QRgb color) { QColor col(color); QPixmap px(42, 42); px.fill(col); - m_mtxColorButton4->setIcon(px); + m_mtxColor4Button->setIcon(px); RGBMatrix* matrix = qobject_cast(m_doc->function(m_matrixID)); if (matrix == NULL || mode() == Doc::Design) return; - matrix->setColor(1, col); - if (instantChanges() == true) - matrix->updateColorDelta(); + matrix->setColor(3, col); } -void VCMatrix::slotColorChanged5(QRgb color) +void VCMatrix::slotColor5Changed(QRgb color) { QColor col(color); QPixmap px(42, 42); px.fill(col); - m_mtxColorButton5->setIcon(px); + m_mtxColor5Button->setIcon(px); RGBMatrix* matrix = qobject_cast(m_doc->function(m_matrixID)); if (matrix == NULL || mode() == Doc::Design) return; - matrix->setColor(1, col); - if (instantChanges() == true) - matrix->updateColorDelta(); + matrix->setColor(4, col); } void VCMatrix::slotAnimationChanged(QString name) @@ -428,20 +422,20 @@ void VCMatrix::setVisibilityMask(quint32 mask) if (mask & ShowLabel) m_label->show(); else m_label->hide(); - if (mask & ShowColor1Button) m_mtxColorButton1->show(); - else m_mtxColorButton1->hide(); + if (mask & ShowColor1Button) m_mtxColor1Button->show(); + else m_mtxColor1Button->hide(); - if (mask & ShowColor2Button) m_mtxColorButton2->show(); - else m_mtxColorButton2->hide(); + if (mask & ShowColor2Button) m_mtxColor2Button->show(); + else m_mtxColor2Button->hide(); - if (mask & ShowColor3Button) m_mtxColorButton3->show(); - else m_mtxColorButton2->hide(); + if (mask & ShowColor3Button) m_mtxColor3Button->show(); + else m_mtxColor3Button->hide(); - if (mask & ShowColor4Button) m_mtxColorButton3->show(); - else m_mtxColorButton2->hide(); + if (mask & ShowColor4Button) m_mtxColor4Button->show(); + else m_mtxColor4Button->hide(); - if (mask & ShowColor5Button) m_mtxColorButton5->show(); - else m_mtxColorButton2->hide(); + if (mask & ShowColor5Button) m_mtxColor5Button->show(); + else m_mtxColor5Button->hide(); if (mask & ShowPresetCombo) m_presetCombo->show(); else m_presetCombo->hide(); @@ -461,9 +455,9 @@ quint32 VCMatrix::defaultVisibilityMask() | ShowPresetCombo | ShowColor1Button | ShowColor2Button - | ShowColor3Button - | ShowColor4Button - | ShowColor5Button + | ShowColor3Button + | ShowColor4Button + | ShowColor5Button ; } @@ -577,8 +571,6 @@ void VCMatrix::slotUpdate() if (matrix == NULL) return; - QColor startColor = matrix->getColor(0); - QColor endColor = matrix->getColor(1); QString algorithmName; RGBAlgorithm::Type algorithmType = RGBAlgorithm::Plain; QHash algorithmProperties; @@ -603,15 +595,34 @@ void VCMatrix::slotUpdate() } } - // Start / End color buttons + // Color buttons QPixmap px(42, 42); - px.fill(startColor); - m_mtxColorButton1->setIcon(px); - if (endColor == QColor()) + px.fill(matrix->getColor(0)); + m_mtxColor1Button->setIcon(px); + + if (matrix->getColor(1) == QColor()) + px.fill(Qt::transparent); + else + px.fill(matrix->getColor(1)); + m_mtxColor2Button->setIcon(px); + + if (matrix->getColor(2) == QColor()) + px.fill(Qt::transparent); + else + px.fill(matrix->getColor(2)); + m_mtxColor3Button->setIcon(px); + + if (matrix->getColor(3) == QColor()) + px.fill(Qt::transparent); + else + px.fill(matrix->getColor(3)); + m_mtxColor4Button->setIcon(px); + + if (matrix->getColor(4) == QColor()) px.fill(Qt::transparent); else - px.fill(endColor); - m_mtxColorButton2->setIcon(px); + px.fill(matrix->getColor(4)); + m_mtxColor5Button->setIcon(px); // Algo combo box if (algorithmName != QString()) @@ -632,61 +643,61 @@ void VCMatrix::slotUpdate() { KnobWidget* knob = reinterpret_cast(widget); knob->blockSignals(true); - knob->setValue(control->rgbToValue(startColor.rgb())); + knob->setValue(control->rgbToValue(matrix->getColor(0).rgb())); knob->blockSignals(false); } else if (control->m_type == VCMatrixControl::Color2Knob) { KnobWidget* knob = reinterpret_cast(widget); knob->blockSignals(true); - knob->setValue(control->rgbToValue(endColor.rgb())); + knob->setValue(control->rgbToValue(matrix->getColor(1).rgb())); knob->blockSignals(false); } else if (control->m_type == VCMatrixControl::Color3Knob) { KnobWidget* knob = reinterpret_cast(widget); knob->blockSignals(true); - knob->setValue(control->rgbToValue(endColor.rgb())); + knob->setValue(control->rgbToValue(matrix->getColor(2).rgb())); knob->blockSignals(false); } else if (control->m_type == VCMatrixControl::Color4Knob) { KnobWidget* knob = reinterpret_cast(widget); knob->blockSignals(true); - knob->setValue(control->rgbToValue(endColor.rgb())); + knob->setValue(control->rgbToValue(matrix->getColor(3).rgb())); knob->blockSignals(false); } else if (control->m_type == VCMatrixControl::Color5Knob) { KnobWidget* knob = reinterpret_cast(widget); knob->blockSignals(true); - knob->setValue(control->rgbToValue(endColor.rgb())); + knob->setValue(control->rgbToValue(matrix->getColor(4).rgb())); knob->blockSignals(false); } else if (control->m_type == VCMatrixControl::Color1) { QPushButton* button = reinterpret_cast(it.key()); - button->setDown(startColor == control->m_color); + button->setDown(matrix->getColor(0) == control->m_color); } else if (control->m_type == VCMatrixControl::Color2) { QPushButton* button = reinterpret_cast(it.key()); - button->setDown(endColor == control->m_color); + button->setDown(matrix->getColor(1) == control->m_color); } else if (control->m_type == VCMatrixControl::Color3) { QPushButton* button = reinterpret_cast(it.key()); - button->setDown(endColor == control->m_color); + button->setDown(matrix->getColor(2) == control->m_color); } else if (control->m_type == VCMatrixControl::Color4) { QPushButton* button = reinterpret_cast(it.key()); - button->setDown(endColor == control->m_color); + button->setDown(matrix->getColor(3) == control->m_color); } else if (control->m_type == VCMatrixControl::Color5) { QPushButton* button = reinterpret_cast(it.key()); - button->setDown(endColor == control->m_color); + button->setDown(matrix->getColor(4) == control->m_color); } else if (control->m_type == VCMatrixControl::Animation) { @@ -797,7 +808,7 @@ void VCMatrix::addCustomControl(VCMatrixControl const& control) controlButton->setFocusPolicy(Qt::TabFocus); controlButton->setText("5"); } - else if (control.m_type == VCMatrixControl::ResetColor2) + else if (control.m_type == VCMatrixControl::Color2Reset) { QPushButton *controlButton = new QPushButton(this); controlWidget = controlButton; @@ -809,7 +820,7 @@ void VCMatrix::addCustomControl(VCMatrixControl const& control) controlButton->setToolTip(btnLabel); controlButton->setText(fontMetrics().elidedText(btnLabel, Qt::ElideRight, 72)); } - else if (control.m_type == VCMatrixControl::ResetColor3) + else if (control.m_type == VCMatrixControl::Color3Reset) { QPushButton *controlButton = new QPushButton(this); controlWidget = controlButton; @@ -821,7 +832,7 @@ void VCMatrix::addCustomControl(VCMatrixControl const& control) controlButton->setToolTip(btnLabel); controlButton->setText(fontMetrics().elidedText(btnLabel, Qt::ElideRight, 72)); } - else if (control.m_type == VCMatrixControl::ResetColor4) + else if (control.m_type == VCMatrixControl::Color4Reset) { QPushButton *controlButton = new QPushButton(this); controlWidget = controlButton; @@ -833,7 +844,7 @@ void VCMatrix::addCustomControl(VCMatrixControl const& control) controlButton->setToolTip(btnLabel); controlButton->setText(fontMetrics().elidedText(btnLabel, Qt::ElideRight, 72)); } - else if (control.m_type == VCMatrixControl::ResetColor5) + else if (control.m_type == VCMatrixControl::Color5Reset) { QPushButton *controlButton = new QPushButton(this); controlWidget = controlButton; @@ -1031,47 +1042,35 @@ void VCMatrix::slotCustomControlClicked() else if (control->m_type == VCMatrixControl::Color3) { matrix->setColor(2, control->m_color); - if (instantChanges() == true) - matrix->updateColorDelta(); btn->setDown(true); } else if (control->m_type == VCMatrixControl::Color4) { matrix->setColor(3, control->m_color); - if (instantChanges() == true) - matrix->updateColorDelta(); btn->setDown(true); } else if (control->m_type == VCMatrixControl::Color5) { matrix->setColor(4, control->m_color); - if (instantChanges() == true) - matrix->updateColorDelta(); btn->setDown(true); } - else if (control->m_type == VCMatrixControl::ResetColor2) + else if (control->m_type == VCMatrixControl::Color2Reset) { matrix->setColor(1, QColor()); if (instantChanges() == true) matrix->updateColorDelta(); } - else if (control->m_type == VCMatrixControl::ResetColor3) + else if (control->m_type == VCMatrixControl::Color3Reset) { matrix->setColor(2, QColor()); - if (instantChanges() == true) - matrix->updateColorDelta(); } - else if (control->m_type == VCMatrixControl::ResetColor4) + else if (control->m_type == VCMatrixControl::Color4Reset) { matrix->setColor(3, QColor()); - if (instantChanges() == true) - matrix->updateColorDelta(); } - else if (control->m_type == VCMatrixControl::ResetColor5) + else if (control->m_type == VCMatrixControl::Color5Reset) { matrix->setColor(4, QColor()); - if (instantChanges() == true) - matrix->updateColorDelta(); } else if (control->m_type == VCMatrixControl::Animation) { @@ -1142,8 +1141,6 @@ void VCMatrix::slotCustomControlValueChanged() color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb()); matrix->setColor(2, color); - if (instantChanges() == true) - matrix->updateColorDelta(); } else if (control->m_type == VCMatrixControl::Color4Knob) { @@ -1152,8 +1149,6 @@ void VCMatrix::slotCustomControlValueChanged() color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb()); matrix->setColor(3, color); - if (instantChanges() == true) - matrix->updateColorDelta(); } else if (control->m_type == VCMatrixControl::Color5Knob) { @@ -1162,8 +1157,6 @@ void VCMatrix::slotCustomControlValueChanged() color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb()); matrix->setColor(4, color); - if (instantChanges() == true) - matrix->updateColorDelta(); } else { diff --git a/ui/src/virtualconsole/vcmatrix.h b/ui/src/virtualconsole/vcmatrix.h index dbcedc4408..43e46864f9 100644 --- a/ui/src/virtualconsole/vcmatrix.h +++ b/ui/src/virtualconsole/vcmatrix.h @@ -47,8 +47,11 @@ class RGBMatrix; #define KXMLQLCVCMatrixInstantApply QString("InstantApply") -#define KXMLQLCVCMatrixStartColor QString("StartColor") -#define KXMLQLCVCMatrixEndColor QString("EndColor") +#define KXMLQLCVCMatrixColor1 QString("Color 1") +#define KXMLQLCVCMatrixColor2 QString("Color 2") +#define KXMLQLCVCMatrixColor3 QString("Color 3") +#define KXMLQLCVCMatrixColor4 QString("Color 4") +#define KXMLQLCVCMatrixColor5 QString("Color 5") #define KXMLQLCVCMatrixVisibilityMask QString("Visibility") @@ -89,16 +92,16 @@ class VCMatrix : public VCWidget ClickAndGoSlider *m_slider; bool m_sliderExternalMovement; QLabel *m_label; - QToolButton *m_mtxColorButton1; - ClickAndGoWidget *m_mtxCnGWidget1; - QToolButton *m_mtxColorButton2; - ClickAndGoWidget *m_mtxCnGWidget2; - QToolButton *m_mtxColorButton3; - ClickAndGoWidget *m_mtxCnGWidget3; - QToolButton *m_mtxColorButton4; - ClickAndGoWidget *m_mtxCnGWidget4; - QToolButton *m_mtxColorButton5; - ClickAndGoWidget *m_mtxCnGWidget5; + QToolButton *m_mtxColor1Button; + ClickAndGoWidget *m_mtxColor1CnGWidget; + QToolButton *m_mtxColor2Button; + ClickAndGoWidget *m_mtxColor2CnGWidget; + QToolButton *m_mtxColor3Button; + ClickAndGoWidget *m_mtxColor3CnGWidget; + QToolButton *m_mtxColor4Button; + ClickAndGoWidget *m_mtxColor4CnGWidget; + QToolButton *m_mtxColor5Button; + ClickAndGoWidget *m_mtxColor5CnGWidget; QComboBox *m_presetCombo; FlowLayout *m_controlsLayout; @@ -123,11 +126,11 @@ class VCMatrix : public VCWidget private slots: void slotSliderMoved(int value); - void slotColorChanged1(QRgb color); - void slotColorChanged2(QRgb color); - void slotColorChanged3(QRgb color); - void slotColorChanged4(QRgb color); - void slotColorChanged5(QRgb color); + void slotColor1Changed(QRgb color); + void slotColor2Changed(QRgb color); + void slotColor3Changed(QRgb color); + void slotColor4Changed(QRgb color); + void slotColor5Changed(QRgb color); void slotAnimationChanged(QString name); /********************************************************************* diff --git a/ui/src/virtualconsole/vcmatrixcontrol.cpp b/ui/src/virtualconsole/vcmatrixcontrol.cpp index c53b7fe427..10bfee0233 100644 --- a/ui/src/virtualconsole/vcmatrixcontrol.cpp +++ b/ui/src/virtualconsole/vcmatrixcontrol.cpp @@ -102,10 +102,10 @@ VCMatrixControl::WidgetType VCMatrixControl::widgetType() const case Animation: case Image: case Text: - case ResetColor2: - case ResetColor3: - case ResetColor4: - case ResetColor5: + case Color2Reset: + case Color3Reset: + case Color4Reset: + case Color5Reset: return Button; case Color1Knob: case Color2Knob: @@ -129,10 +129,10 @@ QString VCMatrixControl::typeToString(VCMatrixControl::ControlType type) case Color3: return "Color3"; break; case Color4: return "Color4"; break; case Color5: return "Color5"; break; - case ResetColor2: return "ResetColor2"; break; - case ResetColor3: return "ResetColor3"; break; - case ResetColor4: return "ResetColor4"; break; - case ResetColor5: return "ResetColor5"; break; + case Color2Reset: return "ResetColor2"; break; + case Color3Reset: return "ResetColor3"; break; + case Color4Reset: return "ResetColor4"; break; + case Color5Reset: return "ResetColor5"; break; case Animation: return "Animation"; break; case Image: return "Image"; break; case Text: return "Text"; break; @@ -152,10 +152,10 @@ VCMatrixControl::ControlType VCMatrixControl::stringToType(QString str) else if (str == "Color3") return Color3; else if (str == "Color4") return Color4; else if (str == "Color5") return Color5; - else if (str == "ResetColor2") return ResetColor2; - else if (str == "ResetColor3") return ResetColor3; - else if (str == "ResetColor4") return ResetColor4; - else if (str == "ResetColor5") return ResetColor5; + else if (str == "ResetColor2") return Color2Reset; + else if (str == "ResetColor3") return Color3Reset; + else if (str == "ResetColor4") return Color4Reset; + else if (str == "ResetColor5") return Color5Reset; else if (str == "Animation") return Animation; else if (str == "Image") return Image; else if (str == "Text") return Text; @@ -247,15 +247,15 @@ bool VCMatrixControl::saveXML(QXmlStreamWriter *doc) doc->writeTextElement(KXMLQLCVCMatrixControlType, typeToString(m_type)); if (m_type == Color1 - || m_type == Color2 - || m_type == Color3 - || m_type == Color4 - || m_type == Color5 - || m_type == Color1Knob - || m_type == Color2Knob - || m_type == Color3Knob - || m_type == Color4Knob - || m_type == Color5Knob) + || m_type == Color2 + || m_type == Color3 + || m_type == Color4 + || m_type == Color5 + || m_type == Color1Knob + || m_type == Color2Knob + || m_type == Color3Knob + || m_type == Color4Knob + || m_type == Color5Knob) { doc->writeTextElement(KXMLQLCVCMatrixControlColor, m_color.name()); } diff --git a/ui/src/virtualconsole/vcmatrixcontrol.h b/ui/src/virtualconsole/vcmatrixcontrol.h index d275d00c31..7f9a5f91b7 100644 --- a/ui/src/virtualconsole/vcmatrixcontrol.h +++ b/ui/src/virtualconsole/vcmatrixcontrol.h @@ -60,16 +60,16 @@ class VCMatrixControl Color1Knob, Color2, Color2Knob, - ResetColor2, - Color3, + Color2Reset, + Color3, Color3Knob, - ResetColor3, - Color4, + Color3Reset, + Color4, Color4Knob, - ResetColor4, - Color5, + Color4Reset, + Color5, Color5Knob, - ResetColor5, + Color5Reset, Animation, Image, Text diff --git a/ui/src/virtualconsole/vcmatrixproperties.cpp b/ui/src/virtualconsole/vcmatrixproperties.cpp index 4490d04581..3a8e178a85 100644 --- a/ui/src/virtualconsole/vcmatrixproperties.cpp +++ b/ui/src/virtualconsole/vcmatrixproperties.cpp @@ -71,10 +71,10 @@ VCMatrixProperties::VCMatrixProperties(VCMatrix* matrix, Doc* doc) if (visibilityMask & VCMatrix::ShowSlider) m_sliderCheck->setChecked(true); if (visibilityMask & VCMatrix::ShowLabel) m_labelCheck->setChecked(true); if (visibilityMask & VCMatrix::ShowColor1Button) m_mtxColor1ButtonCheck->setChecked(true); - if (visibilityMask & VCMatrix::ShowColor1Button) m_mtxColor2ButtonCheck->setChecked(true); - if (visibilityMask & VCMatrix::ShowColor1Button) m_mtxColor3ButtonCheck->setChecked(true); - if (visibilityMask & VCMatrix::ShowColor1Button) m_mtxColor4ButtonCheck->setChecked(true); - if (visibilityMask & VCMatrix::ShowColor1Button) m_mtxColor5ButtonCheck->setChecked(true); + if (visibilityMask & VCMatrix::ShowColor2Button) m_mtxColor2ButtonCheck->setChecked(true); + if (visibilityMask & VCMatrix::ShowColor3Button) m_mtxColor3ButtonCheck->setChecked(true); + if (visibilityMask & VCMatrix::ShowColor4Button) m_mtxColor4ButtonCheck->setChecked(true); + if (visibilityMask & VCMatrix::ShowColor5Button) m_mtxColor5ButtonCheck->setChecked(true); if (visibilityMask & VCMatrix::ShowPresetCombo) m_presetComboCheck->setChecked(true); /* Custom controls */ @@ -93,33 +93,33 @@ VCMatrixProperties::VCMatrixProperties(VCMatrix* matrix, Doc* doc) this, SLOT(slotTreeSelectionChanged())); connect(m_addMtxColor1Button, SIGNAL(clicked()), - this, SLOT(slotAddStartColorClicked())); + this, SLOT(slotAddMtxColor1Clicked())); connect(m_addMtxColor1KnobsButton, SIGNAL(clicked()), - this, SLOT(slotAddStartColorKnobsClicked())); + this, SLOT(slotAddMtxColor1KnobsClicked())); connect(m_addMtxColor2Button, SIGNAL(clicked()), - this, SLOT(slotAddEndColorClicked())); + this, SLOT(slotAddMtxColor2Clicked())); connect(m_addMtxColor2KnobsButton, SIGNAL(clicked()), - this, SLOT(slotAddEndColorKnobsClicked())); + this, SLOT(slotAddMtxColor2KnobsClicked())); connect(m_addMtxColor2ResetButton, SIGNAL(clicked()), - this, SLOT(slotAddEndColorResetClicked())); + this, SLOT(slotAddMtxColor2ResetClicked())); connect(m_addMtxColor3Button, SIGNAL(clicked()), - this, SLOT(slotAddEndColorClicked())); + this, SLOT(slotAddMtxColor3Clicked())); connect(m_addMtxColor3KnobsButton, SIGNAL(clicked()), - this, SLOT(slotAddEndColorKnobsClicked())); + this, SLOT(slotAddMtxColor3KnobsClicked())); connect(m_addMtxColor3ResetButton, SIGNAL(clicked()), - this, SLOT(slotAddEndColorResetClicked())); + this, SLOT(slotAddMtxColor3ResetClicked())); connect(m_addMtxColor4Button, SIGNAL(clicked()), - this, SLOT(slotAddEndColorClicked())); + this, SLOT(slotAddMtxColor4Clicked())); connect(m_addMtxColor4KnobsButton, SIGNAL(clicked()), - this, SLOT(slotAddEndColorKnobsClicked())); + this, SLOT(slotAddMtxColor4KnobsClicked())); connect(m_addMtxColor4ResetButton, SIGNAL(clicked()), - this, SLOT(slotAddEndColorResetClicked())); + this, SLOT(slotAddMtxColor4ResetClicked())); connect(m_addMtxColor5Button, SIGNAL(clicked()), - this, SLOT(slotAddEndColorClicked())); + this, SLOT(slotAddMtxColor5Clicked())); connect(m_addMtxColor5KnobsButton, SIGNAL(clicked()), - this, SLOT(slotAddEndColorKnobsClicked())); + this, SLOT(slotAddMtxColor5KnobsClicked())); connect(m_addMtxColor5ResetButton, SIGNAL(clicked()), - this, SLOT(slotAddEndColorResetClicked())); + this, SLOT(slotAddMtxColor5ResetClicked())); connect(m_addPresetButton, SIGNAL(clicked()), this, SLOT(slotAddAnimationClicked())); connect(m_addTextButton, SIGNAL(clicked()), @@ -270,7 +270,7 @@ void VCMatrixProperties::updateTree() item->setText(1, control->m_color.name()); item->setBackground(1, QBrush(control->m_color)); break; - case VCMatrixControl::ResetColor2: + case VCMatrixControl::Color2Reset: item->setIcon(0, QIcon(":/fileclose.png")); item->setText(0, tr("Color 2 Reset")); break; @@ -286,7 +286,7 @@ void VCMatrixProperties::updateTree() item->setText(1, control->m_color.name()); item->setBackground(1, QBrush(control->m_color)); break; - case VCMatrixControl::ResetColor3: + case VCMatrixControl::Color3Reset: item->setIcon(0, QIcon(":/fileclose.png")); item->setText(0, tr("Color 3 Reset")); break; @@ -302,7 +302,7 @@ void VCMatrixProperties::updateTree() item->setText(1, control->m_color.name()); item->setBackground(1, QBrush(control->m_color)); break; - case VCMatrixControl::ResetColor4: + case VCMatrixControl::Color4Reset: item->setIcon(0, QIcon(":/fileclose.png")); item->setText(0, tr("Color 4 Reset")); break; @@ -318,7 +318,7 @@ void VCMatrixProperties::updateTree() item->setText(1, control->m_color.name()); item->setBackground(1, QBrush(control->m_color)); break; - case VCMatrixControl::ResetColor5: + case VCMatrixControl::Color5Reset: item->setIcon(0, QIcon(":/fileclose.png")); item->setText(0, tr("Color 5 Reset")); break; @@ -455,7 +455,7 @@ void VCMatrixProperties::slotAddMtxColor2KnobsClicked() void VCMatrixProperties::slotAddMtxColor2ResetClicked() { VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); - newControl->m_type = VCMatrixControl::ResetColor2; + newControl->m_type = VCMatrixControl::Color2Reset; addControl(newControl); updateTree(); } @@ -488,7 +488,7 @@ void VCMatrixProperties::slotAddMtxColor3KnobsClicked() void VCMatrixProperties::slotAddMtxColor3ResetClicked() { VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); - newControl->m_type = VCMatrixControl::ResetColor3; + newControl->m_type = VCMatrixControl::Color3Reset; addControl(newControl); updateTree(); } @@ -521,7 +521,7 @@ void VCMatrixProperties::slotAddMtxColor4KnobsClicked() void VCMatrixProperties::slotAddMtxColor4ResetClicked() { VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); - newControl->m_type = VCMatrixControl::ResetColor4; + newControl->m_type = VCMatrixControl::Color4Reset; addControl(newControl); updateTree(); } @@ -554,7 +554,7 @@ void VCMatrixProperties::slotAddMtxColor5KnobsClicked() void VCMatrixProperties::slotAddMtxColor5ResetClicked() { VCMatrixControl *newControl = new VCMatrixControl(++m_lastAssignedID); - newControl->m_type = VCMatrixControl::ResetColor5; + newControl->m_type = VCMatrixControl::Color5Reset; addControl(newControl); updateTree(); } @@ -604,10 +604,10 @@ void VCMatrixProperties::slotRemoveClicked() if (control != NULL) { if (control->m_type == VCMatrixControl::Color1Knob - || control->m_type == VCMatrixControl::Color2Knob - || control->m_type == VCMatrixControl::Color3Knob - || control->m_type == VCMatrixControl::Color4Knob - || control->m_type == VCMatrixControl::Color5Knob) + || control->m_type == VCMatrixControl::Color2Knob + || control->m_type == VCMatrixControl::Color3Knob + || control->m_type == VCMatrixControl::Color4Knob + || control->m_type == VCMatrixControl::Color5Knob) { if (control->m_color == Qt::red) { From ebc0f658d9ada3fba8e73665d6c78f5ebf7c120b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Sat, 16 Dec 2023 21:44:08 +0100 Subject: [PATCH 30/63] Load and store the additional colors. Extend the test. --- engine/src/rgbmatrix.cpp | 48 +++++++++++++++++++----- engine/test/rgbmatrix/rgbmatrix_test.cpp | 35 +++++++++++++---- ui/src/rgbmatrixeditor.cpp | 2 +- 3 files changed, 68 insertions(+), 17 deletions(-) diff --git a/engine/src/rgbmatrix.cpp b/engine/src/rgbmatrix.cpp index 8b072b89be..d89af50ef7 100644 --- a/engine/src/rgbmatrix.cpp +++ b/engine/src/rgbmatrix.cpp @@ -38,6 +38,12 @@ #define KXMLQLCRGBMatrixStartColor QString("MonoColor") #define KXMLQLCRGBMatrixEndColor QString("EndColor") +#define KXMLQLCRGBMatrixColor1 QString("Color1") +#define KXMLQLCRGBMatrixColor2 QString("Color2") +#define KXMLQLCRGBMatrixColor3 QString("Color3") +#define KXMLQLCRGBMatrixColor4 QString("Color4") +#define KXMLQLCRGBMatrixColor5 QString("Color5") + #define KXMLQLCRGBMatrixFixtureGroup QString("FixtureGroup") #define KXMLQLCRGBMatrixDimmerControl QString("DimmerControl") @@ -400,14 +406,28 @@ bool RGBMatrix::loadXML(QXmlStreamReader &root) #if (5 != RGBAlgorithmRawColorCount) #error "Further colors need to be read." #endif - else if (root.name() == KXMLQLCRGBMatrixStartColor) + else if (root.name() == KXMLQLCRGBMatrixStartColor + || root.name() == KXMLQLCRGBMatrixColor1) { setColor(0, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); } - else if (root.name() == KXMLQLCRGBMatrixEndColor) + else if (root.name() == KXMLQLCRGBMatrixEndColor + || root.name() == KXMLQLCRGBMatrixColor2) { setColor(1, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); } + else if (root.name() == KXMLQLCRGBMatrixColor3) + { + setColor(2, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); + } + else if (root.name() == KXMLQLCRGBMatrixColor4) + { + setColor(3, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); + } + else if (root.name() == KXMLQLCRGBMatrixColor5) + { + setColor(4, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); + } else if (root.name() == KXMLQLCRGBMatrixControlMode) { setControlMode(stringToControlMode(root.readElementText())); @@ -460,15 +480,25 @@ bool RGBMatrix::saveXML(QXmlStreamWriter *doc) if (dimmerControl()) doc->writeTextElement(KXMLQLCRGBMatrixDimmerControl, QString::number(dimmerControl())); - /* Start Color */ - doc->writeTextElement(KXMLQLCRGBMatrixStartColor, QString::number(getColor(0).rgb())); + /* Color 1 */ + doc->writeTextElement(KXMLQLCRGBMatrixColor1, QString::number(getColor(0).rgb())); - /* End Color */ + /* Color 2 */ if (getColor(1).isValid()) - doc->writeTextElement(KXMLQLCRGBMatrixEndColor, QString::number(getColor(1).rgb())); -#if (5 != RGBAlgorithmRawColorCount) -#error "Further colors need to be written." -#endif + doc->writeTextElement(KXMLQLCRGBMatrixColor2, QString::number(getColor(1).rgb())); + + /* Color 2 */ + if (getColor(2).isValid()) + doc->writeTextElement(KXMLQLCRGBMatrixColor3, QString::number(getColor(2).rgb())); + + /* Color 2 */ + if (getColor(3).isValid()) + doc->writeTextElement(KXMLQLCRGBMatrixColor4, QString::number(getColor(3).rgb())); + + /* Color 5 */ + if (getColor(4).isValid()) + doc->writeTextElement(KXMLQLCRGBMatrixColor5, QString::number(getColor(4).rgb())); + Q_ASSERT(5 == RGBAlgorithmRawColorCount); /* Control Mode */ doc->writeTextElement(KXMLQLCRGBMatrixControlMode, RGBMatrix::controlModeToString(m_controlMode)); diff --git a/engine/test/rgbmatrix/rgbmatrix_test.cpp b/engine/test/rgbmatrix/rgbmatrix_test.cpp index ba3a41b8f5..f34b53e017 100644 --- a/engine/test/rgbmatrix/rgbmatrix_test.cpp +++ b/engine/test/rgbmatrix/rgbmatrix_test.cpp @@ -205,6 +205,9 @@ void RGBMatrix_Test::loadSave() RGBMatrix* mtx = new RGBMatrix(m_doc); mtx->setColor(0, Qt::magenta); mtx->setColor(1, Qt::blue); + mtx->setColor(2, Qt::green); + mtx->setColor(3, Qt::red); + mtx->setColor(4, Qt::yellow); mtx->setControlMode(RGBMatrix::ControlModeRgb); mtx->setFixtureGroup(42); mtx->setAlgorithm(RGBAlgorithm::algorithm(m_doc, "Stripes")); @@ -237,7 +240,7 @@ void RGBMatrix_Test::loadSave() QCOMPARE(xmlReader.attributes().value("ID").toString(), QString::number(mtx->id())); QCOMPARE(xmlReader.attributes().value("Name").toString(), QString("Xyzzy")); - int speed = 0, dir = 0, run = 0, algo = 0, monocolor = 0, endcolor = 0, grp = 0, colormode = 0; + int speed = 0, dir = 0, run = 0, algo = 0, color1 = 0, color2 = 0, color3 = 0, color4 = 0, color5 = 0, grp = 0, colormode = 0; while (xmlReader.readNextStartElement()) { @@ -265,15 +268,30 @@ void RGBMatrix_Test::loadSave() algo++; xmlReader.skipCurrentElement(); } - else if (xmlReader.name().toString() == "MonoColor") + else if (xmlReader.name().toString() == "Color1") { QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::magenta).rgb()); - monocolor++; + color1++; } - else if (xmlReader.name().toString() == "EndColor") + else if (xmlReader.name().toString() == "Color2") { QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::blue).rgb()); - endcolor++; + color2++; + } + else if (xmlReader.name().toString() == "Color3") + { + QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::green).rgb()); + color3++; + } + else if (xmlReader.name().toString() == "Color4") + { + QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::red).rgb()); + color4++; + } + else if (xmlReader.name().toString() == "Color5") + { + QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::yellow).rgb()); + color5++; } else if (xmlReader.name().toString() == "FixtureGroup") { @@ -295,8 +313,11 @@ void RGBMatrix_Test::loadSave() QCOMPARE(dir, 1); QCOMPARE(run, 1); QCOMPARE(algo, 1); - QCOMPARE(monocolor, 1); - QCOMPARE(endcolor, 1); + QCOMPARE(color1, 1); + QCOMPARE(color2, 1); + QCOMPARE(color3, 1); + QCOMPARE(color4, 1); + QCOMPARE(color5, 1); QCOMPARE(grp, 1); QCOMPARE(colormode, 1); diff --git a/ui/src/rgbmatrixeditor.cpp b/ui/src/rgbmatrixeditor.cpp index 4227db849c..cca9e704e9 100644 --- a/ui/src/rgbmatrixeditor.cpp +++ b/ui/src/rgbmatrixeditor.cpp @@ -582,7 +582,7 @@ void RGBMatrixEditor::updateColors() pm.fill(Qt::transparent); else pm.fill(m_matrix->getColor(4)); - m_mtxColor4Button->setIcon(QIcon(pm)); + m_mtxColor5Button->setIcon(QIcon(pm)); } } } From 9cb0e689897951bdd1ef65f9257a2b7ea7a7496c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Sun, 17 Dec 2023 21:53:33 +0100 Subject: [PATCH 31/63] Do not overwrite configured colors Apply only the limited amount of colors when switching e.g. from ballscolors to balls and back. Previously, balls would toggle between color 1 and color 2 while it accepts only one color and the second color is not configurable (v4 / UI) --- engine/src/rgbalgorithm.cpp | 9 +- engine/src/rgbmatrix.cpp | 12 +-- engine/src/rgbmatrix.h | 4 +- qmlui/rgbmatrixeditor.cpp | 10 +-- ui/src/rgbmatrixeditor.cpp | 169 ++++++++++++++++++++++-------------- 5 files changed, 124 insertions(+), 80 deletions(-) diff --git a/engine/src/rgbalgorithm.cpp b/engine/src/rgbalgorithm.cpp index 9d84c71a17..a7151aa961 100644 --- a/engine/src/rgbalgorithm.cpp +++ b/engine/src/rgbalgorithm.cpp @@ -50,8 +50,13 @@ RGBAlgorithm::RGBAlgorithm(Doc * doc) void RGBAlgorithm::setColors(QColor colors[RGBAlgorithmRawColorCount]) { - for (unsigned int i = 0; i < RGBAlgorithmRawColorCount; i++) - m_colors[i] = colors[i]; + for (int i = 0; i < RGBAlgorithmRawColorCount; i++) + { + if (acceptColors() <= i) + m_colors[i] = colors[i]; + else + m_colors[i] = QColor(); + } } QColor RGBAlgorithm::getColor(unsigned int i) const diff --git a/engine/src/rgbmatrix.cpp b/engine/src/rgbmatrix.cpp index d89af50ef7..9a7f0d3bc0 100644 --- a/engine/src/rgbmatrix.cpp +++ b/engine/src/rgbmatrix.cpp @@ -325,7 +325,7 @@ QColor RGBMatrix::getColor(unsigned int i) const void RGBMatrix::updateColorDelta() { - m_stepHandler->calculateColorDelta(m_rgbColors[0], m_rgbColors[1]); + m_stepHandler->calculateColorDelta(m_rgbColors[0], m_rgbColors[1], m_algorithm); } /************************************************************************ @@ -557,7 +557,7 @@ void RGBMatrix::preRun(MasterTimer *timer) if (m_algorithm != NULL) { // Copy direction from parent class direction - m_stepHandler->initializeDirection(direction(), m_rgbColors[0], m_rgbColors[1], m_stepsCount); + m_stepHandler->initializeDirection(direction(), m_rgbColors[0], m_rgbColors[1], m_stepsCount, m_algorithm); if (m_algorithm->type() == RGBAlgorithm::Script) { @@ -1018,13 +1018,13 @@ int RGBMatrixStep::currentStepIndex() const return m_currentStepIndex; } -void RGBMatrixStep::calculateColorDelta(QColor startColor, QColor endColor) +void RGBMatrixStep::calculateColorDelta(QColor startColor, QColor endColor, RGBAlgorithm *algorithm) { m_crDelta = 0; m_cgDelta = 0; m_cbDelta = 0; - if (endColor.isValid()) + if (endColor.isValid() && algorithm != NULL && algorithm->acceptColors() > 1) { m_crDelta = endColor.red() - startColor.red(); m_cgDelta = endColor.green() - startColor.green(); @@ -1063,7 +1063,7 @@ void RGBMatrixStep::updateStepColor(int stepIndex, QColor startColor, int stepsC //qDebug() << "RGBMatrix step" << stepIndex << ", color:" << QString::number(m_stepColor.rgb(), 16); } -void RGBMatrixStep::initializeDirection(Function::Direction direction, QColor startColor, QColor endColor, int stepsCount) +void RGBMatrixStep::initializeDirection(Function::Direction direction, QColor startColor, QColor endColor, int stepsCount, RGBAlgorithm *algorithm) { m_direction = direction; @@ -1082,7 +1082,7 @@ void RGBMatrixStep::initializeDirection(Function::Direction direction, QColor st setStepColor(startColor); } - calculateColorDelta(startColor, endColor); + calculateColorDelta(startColor, endColor, algorithm); } bool RGBMatrixStep::checkNextStep(Function::RunOrder order, diff --git a/engine/src/rgbmatrix.h b/engine/src/rgbmatrix.h index f65c1f80b0..a3b1bd3bb6 100644 --- a/engine/src/rgbmatrix.h +++ b/engine/src/rgbmatrix.h @@ -59,7 +59,7 @@ class RGBMatrixStep int currentStepIndex() const; /** Calculate the RGB components delta between $startColor and $endColor */ - void calculateColorDelta(QColor startColor, QColor endColor); + void calculateColorDelta(QColor startColor, QColor endColor, RGBAlgorithm *algorithm); /** Set/Get the final color of the next step to be reproduced */ void setStepColor(QColor color); @@ -71,7 +71,7 @@ class RGBMatrixStep /** Initialize the playback direction and set the initial step index and * color based on $startColor and $endColor */ - void initializeDirection(Function::Direction direction, QColor startColor, QColor endColor, int stepsCount); + void initializeDirection(Function::Direction direction, QColor startColor, QColor endColor, int stepsCount, RGBAlgorithm *algorithm); /** Check the steps progression based on $order and the internal m_direction. * This method returns true if the RGBMatrix can continue to run, otherwise diff --git a/qmlui/rgbmatrixeditor.cpp b/qmlui/rgbmatrixeditor.cpp index bb542d248a..908223b95e 100644 --- a/qmlui/rgbmatrixeditor.cpp +++ b/qmlui/rgbmatrixeditor.cpp @@ -177,7 +177,7 @@ void RGBMatrixEditor::setColor1(QColor algoColor) Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor1, m_matrix->id(), m_matrix->getColor(0), algoColor); m_matrix->setColor(0, algoColor); - m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); + m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm()); emit color1Changed(algoColor); } @@ -197,7 +197,7 @@ void RGBMatrixEditor::setColor2(QColor algoColor) Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor2, m_matrix->id(), m_matrix->getColor(1), algoColor); m_matrix->setColor(1, algoColor); - m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); + m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm()); emit color2Changed(algoColor); if (algoColor.isValid()) @@ -280,7 +280,7 @@ void RGBMatrixEditor::setHasColor2(bool hasColor) if (m_matrix && hasColor == false) { m_matrix->setColor(1, QColor()); - m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); + m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm()); } emit hasColor2Changed(hasColor); } @@ -755,8 +755,8 @@ void RGBMatrixEditor::initPreviewData() return; m_previewStepHandler->initializeDirection(m_matrix->direction(), m_matrix->getColor(0), - m_matrix->getColor(1), m_matrix->stepsCount()); - m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); + m_matrix->getColor(1), m_matrix->stepsCount(), m_matrix->algorithm()); + m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm()); m_previewTimer->start(MasterTimer::tick()); } diff --git a/ui/src/rgbmatrixeditor.cpp b/ui/src/rgbmatrixeditor.cpp index cca9e704e9..1e0c6f3dff 100644 --- a/ui/src/rgbmatrixeditor.cpp +++ b/ui/src/rgbmatrixeditor.cpp @@ -487,13 +487,20 @@ void RGBMatrixEditor::updateColors() if (m_matrix->blendMode() == Universe::MaskBlend) { m_matrix->setColor(0, Qt::white); - m_matrix->setColor(1, QColor()); - m_matrix->setColor(2, QColor()); - m_matrix->setColor(3, QColor()); - m_matrix->setColor(4, QColor()); - - m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); - + // Overwrite more colors only if applied. + if (accColors <= 2) + m_matrix->setColor(1, QColor()); + if (accColors <= 3) + m_matrix->setColor(2, QColor()); + if (accColors <= 4) + m_matrix->setColor(3, QColor()); + if (accColors <= 5) + m_matrix->setColor(4, QColor()); + + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), + m_matrix->algorithm()); + + // Set all colors to white as being part of the mask QPixmap pm(50, 26); pm.fill(Qt::white); m_mtxColor1Button->setIcon(QIcon(pm)); @@ -506,49 +513,72 @@ void RGBMatrixEditor::updateColors() } else if (m_controlModeCombo->currentIndex() != RGBMatrix::ControlModeRgb) { - // Convert startColor to grayscale for single color modes + // Convert color 1 to grayscale for single color modes uchar gray = qGray(m_matrix->getColor(0).rgb()); + m_matrix->setColor(0, QColor(gray, gray, gray)); QPixmap pm(50, 26); pm.fill(QColor(gray, gray, gray)); m_mtxColor1Button->setIcon(QIcon(pm)); - m_matrix->setColor(0, QColor(gray, gray, gray)); - if (accColors > 1) + // Convert color 2 and following to grayscale for single color modes + if (accColors < 2) + m_matrix->setColor(1, QColor()); + if (m_matrix->getColor(1) == QColor()) + { + pm.fill(Qt::transparent); + } + else { - // Convert endColor to grayscale for single color modes gray = qGray(m_matrix->getColor(1).rgb()); m_matrix->setColor(1, QColor(gray, gray, gray)); - if (m_matrix->getColor(1) == QColor()) - pm.fill(Qt::transparent); - else - pm.fill(QColor(gray, gray, gray)); - m_mtxColor2Button->setIcon(QIcon(pm)); + pm.fill(QColor(gray, gray, gray)); + } + m_mtxColor2Button->setIcon(QIcon(pm)); + if (accColors < 3) + m_matrix->setColor(2, QColor()); + if (m_matrix->getColor(2) == QColor()) + { + pm.fill(Qt::transparent); + } + else + { gray = qGray(m_matrix->getColor(2).rgb()); m_matrix->setColor(2, QColor(gray, gray, gray)); - if (m_matrix->getColor(2) == QColor()) - pm.fill(Qt::transparent); - else - pm.fill(QColor(gray, gray, gray)); - m_mtxColor3Button->setIcon(QIcon(pm)); + pm.fill(QColor(gray, gray, gray)); + } + m_mtxColor3Button->setIcon(QIcon(pm)); + if (accColors < 4) + m_matrix->setColor(3, QColor()); + if (m_matrix->getColor(3) == QColor()) + { + pm.fill(Qt::transparent); + } + else + { gray = qGray(m_matrix->getColor(3).rgb()); m_matrix->setColor(3, QColor(gray, gray, gray)); - if (m_matrix->getColor(3) == QColor()) - pm.fill(Qt::transparent); - else - pm.fill(QColor(gray, gray, gray)); - m_mtxColor4Button->setIcon(QIcon(pm)); + pm.fill(QColor(gray, gray, gray)); + } + m_mtxColor4Button->setIcon(QIcon(pm)); + if (accColors < 5) + m_matrix->setColor(4, QColor()); + if (m_matrix->getColor(4) == QColor()) + { + pm.fill(Qt::transparent); + } + else + { gray = qGray(m_matrix->getColor(4).rgb()); m_matrix->setColor(4, QColor(gray, gray, gray)); - if (m_matrix->getColor(4) == QColor()) - pm.fill(Qt::transparent); - else - pm.fill(QColor(gray, gray, gray)); - m_mtxColor5Button->setIcon(QIcon(pm)); + pm.fill(QColor(gray, gray, gray)); } - m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); + m_mtxColor5Button->setIcon(QIcon(pm)); + + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), + m_matrix->algorithm()); } else { @@ -556,34 +586,34 @@ void RGBMatrixEditor::updateColors() pm.fill(m_matrix->getColor(0)); m_mtxColor1Button->setIcon(QIcon(pm)); - if (accColors > 1) - { - m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); + // Preserve the colors (do not set them to QColor(). + // RGBMatrixStep::calculateColorDelta will ensure correct color application + if (m_matrix->getColor(1) == QColor()) + pm.fill(Qt::transparent); + else + pm.fill(m_matrix->getColor(1)); + m_mtxColor2Button->setIcon(QIcon(pm)); - if (m_matrix->getColor(1) == QColor()) - pm.fill(Qt::transparent); - else - pm.fill(m_matrix->getColor(1)); - m_mtxColor2Button->setIcon(QIcon(pm)); + if (m_matrix->getColor(2) == QColor()) + pm.fill(Qt::transparent); + else + pm.fill(m_matrix->getColor(2)); + m_mtxColor3Button->setIcon(QIcon(pm)); - if (m_matrix->getColor(2) == QColor()) - pm.fill(Qt::transparent); - else - pm.fill(m_matrix->getColor(2)); - m_mtxColor3Button->setIcon(QIcon(pm)); + if (m_matrix->getColor(3) == QColor()) + pm.fill(Qt::transparent); + else + pm.fill(m_matrix->getColor(3)); + m_mtxColor4Button->setIcon(QIcon(pm)); - if (m_matrix->getColor(3) == QColor()) - pm.fill(Qt::transparent); - else - pm.fill(m_matrix->getColor(3)); - m_mtxColor4Button->setIcon(QIcon(pm)); + if (m_matrix->getColor(4) == QColor()) + pm.fill(Qt::transparent); + else + pm.fill(m_matrix->getColor(4)); + m_mtxColor5Button->setIcon(QIcon(pm)); - if (m_matrix->getColor(4) == QColor()) - pm.fill(Qt::transparent); - else - pm.fill(m_matrix->getColor(4)); - m_mtxColor5Button->setIcon(QIcon(pm)); - } + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), + m_matrix->algorithm()); } } } @@ -694,7 +724,8 @@ bool RGBMatrixEditor::createPreviewItems() } m_previewHandler->initializeDirection(m_matrix->direction(), m_matrix->getColor(0), - m_matrix->getColor(1), m_matrix->stepsCount()); + m_matrix->getColor(1), m_matrix->stepsCount(), + m_matrix->algorithm()); m_matrix->previewMap(m_previewHandler->currentStepIndex(), m_previewHandler); @@ -805,7 +836,9 @@ void RGBMatrixEditor::slotDialDestroyed(QObject *) void RGBMatrixEditor::slotPatternActivated(const QString& text) { RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, text); + m_matrix->setAlgorithm(algo); if (algo != NULL) { + updateColors(); QColor colors[RGBAlgorithmRawColorCount] = { m_matrix->getColor(0), m_matrix->getColor(1), @@ -814,9 +847,9 @@ void RGBMatrixEditor::slotPatternActivated(const QString& text) m_matrix->getColor(4) }; algo->setColors(colors); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), + m_matrix->algorithm()); } - m_matrix->setAlgorithm(algo); - m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); updateExtraOptions(); slotRestartTest(); @@ -1076,35 +1109,40 @@ void RGBMatrixEditor::slotOffsetSpinChanged() void RGBMatrixEditor::slotLoopClicked() { m_matrix->setRunOrder(Function::Loop); - m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), + m_matrix->algorithm()); slotRestartTest(); } void RGBMatrixEditor::slotPingPongClicked() { m_matrix->setRunOrder(Function::PingPong); - m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), + m_matrix->algorithm()); slotRestartTest(); } void RGBMatrixEditor::slotSingleShotClicked() { m_matrix->setRunOrder(Function::SingleShot); - m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), + m_matrix->algorithm()); slotRestartTest(); } void RGBMatrixEditor::slotForwardClicked() { m_matrix->setDirection(Function::Forward); - m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), + m_matrix->algorithm()); slotRestartTest(); } void RGBMatrixEditor::slotBackwardClicked() { m_matrix->setDirection(Function::Backward); - m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), + m_matrix->algorithm()); slotRestartTest(); } @@ -1298,7 +1336,8 @@ void RGBMatrixEditor::slotSaveToSequenceClicked() if (m_matrix->getColor(1).isValid()) m_previewHandler->setStepColor(m_matrix->getColor(1)); } - m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1)); + m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), + m_matrix->algorithm()); if (m_matrix->runOrder() == RGBMatrix::PingPong) totalSteps = (totalSteps * 2) - 1; From b3094b5826cd42072257c2f158719a5da5a5dcd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Tue, 2 Jan 2024 16:20:56 +0100 Subject: [PATCH 32/63] Integrate latest changes from webaccess where the signal infrastructure had been changed to enable the VC widget for color selection. --- engine/src/rgbmatrix.cpp | 13 ++- engine/src/rgbmatrix.h | 3 - engine/test/rgbtext/rgbtext_test.cpp | 21 +++-- ui/src/rgbmatrixeditor.cpp | 1 - ui/src/virtualconsole/vcmatrix.cpp | 100 +++++++++++++++++---- ui/src/virtualconsole/vcmatrix.h | 10 ++- webaccess/res/virtualconsole.js | 54 ++++++++--- webaccess/res/websocket.js | 10 ++- webaccess/src/webaccess.cpp | 129 ++++++++++++++++++++++----- webaccess/src/webaccess.h | 7 +- 10 files changed, 275 insertions(+), 73 deletions(-) diff --git a/engine/src/rgbmatrix.cpp b/engine/src/rgbmatrix.cpp index bc10d2a072..884b3155b3 100644 --- a/engine/src/rgbmatrix.cpp +++ b/engine/src/rgbmatrix.cpp @@ -71,8 +71,11 @@ RGBMatrix::RGBMatrix(Doc* doc) , m_algorithmMutex(QMutex::Recursive) #endif , m_rgbColors{ - Qt::red, // was m_startColor - QColor() // was m_endColor + Qt::red, + QColor(), + QColor(), + QColor(), + QColor() } , m_stepHandler(new RGBMatrixStep()) , m_roundTime(new QElapsedTimer()) @@ -291,7 +294,8 @@ void RGBMatrix::previewMap(int step, RGBMatrixStep *handler) ,m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0 ,m_rgbColors[2].isValid() ? m_rgbColors[2].rgb() : 0 ,m_rgbColors[3].isValid() ? m_rgbColors[3].rgb() : 0 - ,m_rgbColors[4].isValid() ? m_rgbColors[4].rgb() : 0}; + ,m_rgbColors[4].isValid() ? m_rgbColors[4].rgb() : 0 + }; m_algorithm->rgbMap(m_group->size(), handler->stepColor().rgb(), step, handler->m_map, rawColors); } } @@ -610,7 +614,8 @@ void RGBMatrix::write(MasterTimer *timer, QList universes) ,m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0 ,m_rgbColors[2].isValid() ? m_rgbColors[2].rgb() : 0 ,m_rgbColors[3].isValid() ? m_rgbColors[3].rgb() : 0 - ,m_rgbColors[4].isValid() ? m_rgbColors[4].rgb() : 0}; + ,m_rgbColors[4].isValid() ? m_rgbColors[4].rgb() : 0 + }; //qDebug() << "RGBMatrix step" << m_stepHandler->currentStepIndex() << ", color:" << QString::number(m_stepHandler->stepColor().rgb(), 16); m_algorithm->rgbMap(m_group->size(), m_stepHandler->stepColor().rgb(), m_stepHandler->currentStepIndex(), m_stepHandler->m_map, rawColors); diff --git a/engine/src/rgbmatrix.h b/engine/src/rgbmatrix.h index a3b1bd3bb6..aa259b00e9 100644 --- a/engine/src/rgbmatrix.h +++ b/engine/src/rgbmatrix.h @@ -191,9 +191,6 @@ class RGBMatrix : public Function void setColor(unsigned int i, QColor c); QColor getColor(unsigned int i) const; - void setRgbColor(const unsigned int i, const QColor& c); - QColor rgbColor(const unsigned int i) const; - void updateColorDelta(); private: diff --git a/engine/test/rgbtext/rgbtext_test.cpp b/engine/test/rgbtext/rgbtext_test.cpp index 41613c9394..8dd454ecdc 100644 --- a/engine/test/rgbtext/rgbtext_test.cpp +++ b/engine/test/rgbtext/rgbtext_test.cpp @@ -325,8 +325,11 @@ void RGBText_Test::staticLetters() QRgb color(0xFFFFFFFF); RGBMap map; uint rawRgbColors[RGBAlgorithmRawColorCount] = { - QColor(Qt::red).rgb(), - QColor(Qt::green).rgb() + QColor(Qt::red).rgb() + ,QColor(Qt::green).rgb() + ,0 + ,0 + ,0 }; // Since fonts and their rendering differs from installation to installation, @@ -367,8 +370,11 @@ void RGBText_Test::horizontalScroll() text.setText("QLC"); text.setAnimationStyle(RGBText::Horizontal); uint rawRgbColors[RGBAlgorithmRawColorCount] = { - QColor(Qt::red).rgb(), - QColor(Qt::green).rgb() + QColor(Qt::red).rgb() + ,QColor(Qt::green).rgb() + ,0 + ,0 + ,0 }; QFontMetrics fm(text.font()); @@ -419,8 +425,11 @@ void RGBText_Test::verticalScroll() text.setText("QLC"); text.setAnimationStyle(RGBText::Vertical); uint rawRgbColors[RGBAlgorithmRawColorCount] = { - QColor(Qt::red).rgb(), - QColor(Qt::green).rgb() + QColor(Qt::red).rgb() + ,QColor(Qt::green).rgb() + ,0 + ,0 + ,0 }; QFontMetrics fm(text.font()); diff --git a/ui/src/rgbmatrixeditor.cpp b/ui/src/rgbmatrixeditor.cpp index 96888240c1..bd3517a512 100644 --- a/ui/src/rgbmatrixeditor.cpp +++ b/ui/src/rgbmatrixeditor.cpp @@ -499,7 +499,6 @@ void RGBMatrixEditor::updateColors() m_previewHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm()); - // Set all colors to white as being part of the mask QPixmap pm(50, 26); pm.fill(Qt::white); m_mtxColor1Button->setIcon(QIcon(pm)); diff --git a/ui/src/virtualconsole/vcmatrix.cpp b/ui/src/virtualconsole/vcmatrix.cpp index 3e90bafd32..75e73af47c 100644 --- a/ui/src/virtualconsole/vcmatrix.cpp +++ b/ui/src/virtualconsole/vcmatrix.cpp @@ -79,7 +79,7 @@ VCMatrix::VCMatrix(QWidget *parent, Doc *doc) QVBoxLayout *vbox = new QVBoxLayout(); - /* Start Color Button */ + /* Color 1 Button */ m_mtxColor1Button = new QToolButton(this); m_mtxColor1Button->setFixedSize(48, 48); m_mtxColor1Button->setIconSize(QSize(42, 42)); @@ -96,7 +96,7 @@ VCMatrix::VCMatrix(QWidget *parent, Doc *doc) connect(m_mtxColor1CnGWidget, SIGNAL(colorChanged(QRgb)), this, SLOT(slotColor1Changed(QRgb))); - /* End Color Button */ + /* Color 2 Button */ m_mtxColor2Button = new QToolButton(this); m_mtxColor2Button->setFixedSize(48, 48); m_mtxColor2Button->setIconSize(QSize(42, 42)); @@ -340,32 +340,84 @@ int VCMatrix::sliderValue() return m_slider->value(); } -void VCMatrix::slotSetStartColor(QColor color) +void VCMatrix::slotSetColor1(QColor color) { RGBMatrix *matrix = qobject_cast(m_doc->function(m_matrixID)); if (matrix == NULL) return; - if (matrix->startColor() != color) + if (matrix->getColor(0) != color) { - matrix->setStartColor(color); - emit startColorChanged(); + matrix->setColor(0, color); + emit mtxColor1Changed(); } } -QColor VCMatrix::startColor() +void VCMatrix::slotSetColor2(QColor color) +{ + RGBMatrix *matrix = qobject_cast(m_doc->function(m_matrixID)); + if (matrix == NULL) + return; + + if (matrix->getColor(1) != color) + { + matrix->setColor(1, color); + emit mtxColor2Changed(); + } +} + +void VCMatrix::slotSetColor3(QColor color) +{ + RGBMatrix *matrix = qobject_cast(m_doc->function(m_matrixID)); + if (matrix == NULL) + return; + + if (matrix->getColor(2) != color) + { + matrix->setColor(2, color); + emit mtxColor3Changed(); + } +} + +void VCMatrix::slotSetColor4(QColor color) +{ + RGBMatrix *matrix = qobject_cast(m_doc->function(m_matrixID)); + if (matrix == NULL) + return; + + if (matrix->getColor(3) != color) + { + matrix->setColor(3, color); + emit mtxColor4Changed(); + } +} + +void VCMatrix::slotSetColor5(QColor color) +{ + RGBMatrix *matrix = qobject_cast(m_doc->function(m_matrixID)); + if (matrix == NULL) + return; + + if (matrix->getColor(4) != color) + { + matrix->setColor(4, color); + emit mtxColor5Changed(); + } +} + +QColor VCMatrix::mtxColor(int id) { RGBMatrix *matrix = qobject_cast(m_doc->function(m_matrixID)); if (matrix == NULL) return QColor(); - return matrix->startColor(); + return matrix->getColor(id); } void VCMatrix::slotColor1Changed(QRgb color) { QColor col(color); - slotSetStartColor(col); + slotSetColor1(col); QPixmap px(42, 42); px.fill(col); m_mtxColor1Button->setIcon(px); @@ -382,7 +434,7 @@ void VCMatrix::slotColor1Changed(QRgb color) void VCMatrix::slotColor2Changed(QRgb color) { QColor col(color); - slotSetEndColor(col); + slotSetColor2(col); QPixmap px(42, 42); px.fill(col); m_mtxColor2Button->setIcon(px); @@ -399,6 +451,7 @@ void VCMatrix::slotColor2Changed(QRgb color) void VCMatrix::slotColor3Changed(QRgb color) { QColor col(color); + slotSetColor3(col); QPixmap px(42, 42); px.fill(col); m_mtxColor3Button->setIcon(px); @@ -413,6 +466,7 @@ void VCMatrix::slotColor3Changed(QRgb color) void VCMatrix::slotColor4Changed(QRgb color) { QColor col(color); + slotSetColor4(col); QPixmap px(42, 42); px.fill(col); m_mtxColor4Button->setIcon(px); @@ -427,6 +481,7 @@ void VCMatrix::slotColor4Changed(QRgb color) void VCMatrix::slotColor5Changed(QRgb color) { QColor col(color); + slotSetColor5(col); QPixmap px(42, 42); px.fill(col); m_mtxColor5Button->setIcon(px); @@ -1111,7 +1166,7 @@ void VCMatrix::slotCustomControlClicked() if (instantChanges() == true) matrix->updateColorDelta(); btn->setDown(true); - emit startColorChanged(); + emit mtxColor1Changed(); } else if (control->m_type == VCMatrixControl::Color2) { @@ -1119,41 +1174,47 @@ void VCMatrix::slotCustomControlClicked() if (instantChanges() == true) matrix->updateColorDelta(); btn->setDown(true); - emit endColorChanged(); + emit mtxColor2Changed(); } else if (control->m_type == VCMatrixControl::Color3) { matrix->setColor(2, control->m_color); btn->setDown(true); + emit mtxColor3Changed(); } else if (control->m_type == VCMatrixControl::Color4) { matrix->setColor(3, control->m_color); btn->setDown(true); + emit mtxColor4Changed(); } else if (control->m_type == VCMatrixControl::Color5) { matrix->setColor(4, control->m_color); btn->setDown(true); + emit mtxColor5Changed(); } else if (control->m_type == VCMatrixControl::Color2Reset) { matrix->setColor(1, QColor()); if (instantChanges() == true) matrix->updateColorDelta(); - emit endColorChanged(); + emit mtxColor2Changed(); } else if (control->m_type == VCMatrixControl::Color3Reset) { matrix->setColor(2, QColor()); + emit mtxColor3Changed(); } else if (control->m_type == VCMatrixControl::Color4Reset) { matrix->setColor(3, QColor()); + emit mtxColor4Changed(); } else if (control->m_type == VCMatrixControl::Color5Reset) { matrix->setColor(4, QColor()); + emit mtxColor5Changed(); } else if (control->m_type == VCMatrixControl::Animation) { @@ -1206,7 +1267,7 @@ void VCMatrix::slotCustomControlValueChanged() matrix->setColor(0, color); if (instantChanges() == true) matrix->updateColorDelta(); - emit startColorChanged(); + emit mtxColor1Changed(); } else if (control->m_type == VCMatrixControl::Color2Knob) { @@ -1217,7 +1278,7 @@ void VCMatrix::slotCustomControlValueChanged() matrix->setColor(1, color); if (instantChanges() == true) matrix->updateColorDelta(); - emit endColorChanged(); + emit mtxColor2Changed(); } else if (control->m_type == VCMatrixControl::Color3Knob) { @@ -1226,6 +1287,7 @@ void VCMatrix::slotCustomControlValueChanged() color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb()); matrix->setColor(2, color); + emit mtxColor3Changed(); } else if (control->m_type == VCMatrixControl::Color4Knob) { @@ -1234,6 +1296,7 @@ void VCMatrix::slotCustomControlValueChanged() color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb()); matrix->setColor(3, color); + emit mtxColor4Changed(); } else if (control->m_type == VCMatrixControl::Color5Knob) { @@ -1242,6 +1305,7 @@ void VCMatrix::slotCustomControlValueChanged() color = (color & ~control->m_color.rgb()) | (knobValueColor & control->m_color.rgb()); matrix->setColor(4, color); + emit mtxColor5Changed(); } else { @@ -1259,7 +1323,11 @@ void VCMatrix::slotMatrixControlKnobValueChanged(int controlID, int value) { if (customControls[i]->m_id == controlID) { - if (customControls[i]->m_type == VCMatrixControl::StartColorKnob || customControls[i]->m_type == VCMatrixControl::EndColorKnob) + if (customControls[i]->m_type == VCMatrixControl::Color1Knob + || customControls[i]->m_type == VCMatrixControl::Color2Knob + || customControls[i]->m_type == VCMatrixControl::Color3Knob + || customControls[i]->m_type == VCMatrixControl::Color4Knob + || customControls[i]->m_type == VCMatrixControl::Color5Knob) { KnobWidget *knob = qobject_cast(this->getWidget(customControls[i])); knob->setValue(value); diff --git a/ui/src/virtualconsole/vcmatrix.h b/ui/src/virtualconsole/vcmatrix.h index 558044ae5e..901de7cb8a 100644 --- a/ui/src/virtualconsole/vcmatrix.h +++ b/ui/src/virtualconsole/vcmatrix.h @@ -127,13 +127,15 @@ class VCMatrix : public VCWidget /** @reimp */ int sliderValue(); QString animationValue(); - QColor startColor(); - QColor endColor(); + QColor mtxColor(int id); signals: void sliderValueChanged(int value); - void startColorChanged(); - void endColorChanged(); + void mtxColor1Changed(); + void mtxColor2Changed(); + void mtxColor3Changed(); + void mtxColor4Changed(); + void mtxColor5Changed(); void animationValueChanged(QString name); void matrixControlKnobValueChanged(int controlID, int value); diff --git a/webaccess/res/virtualconsole.js b/webaccess/res/virtualconsole.js index cecbc0d8a1..61cbe66450 100644 --- a/webaccess/res/virtualconsole.js +++ b/webaccess/res/virtualconsole.js @@ -376,7 +376,6 @@ function updateTime() { } function controlWatch(id, op) { - var obj = document.getElementById(id); var msg = id + "|" + op; websocket.send(msg); } @@ -427,26 +426,59 @@ function setMatrixComboValue(id, comboValue) { combo.value = comboValue; } -function matrixStartColorChange(id) { - var colorObj = document.querySelector("#msc" + id); - var colorMsg = id + "|MATRIX_COLOR_CHANGE|START|" + hexToUint(colorObj.value); +function matrixColor1Change(id) { + var colorObj = document.querySelector("#mc1i" + id); + var colorMsg = id + "|MATRIX_COLOR_CHANGE|COLOR_1|" + hexToUint(colorObj.value); console.log(colorMsg); websocket.send(colorMsg); } -function setMatrixStartColorValue(id, color) { - var combo = document.querySelector("#msc" + id); +function setMatrixColor1Value(id, color) { + var combo = document.querySelector("#mc1i" + id); + combo.value = color; +} + +function matrixColor2Change(id) { + var colorObj = document.querySelector("#mc2i" + id); + var colorMsg = id + "|MATRIX_COLOR_CHANGE|COLOR_2|" + hexToUint(colorObj.value); + websocket.send(colorMsg); +} + +function setMatrixColor2Value(id, color) { + var combo = document.querySelector("#mc2i" + id); + combo.value = color; +} + +function matrixColor3Change(id) { + var colorObj = document.querySelector("#mc3i" + id); + var colorMsg = id + "|MATRIX_COLOR_CHANGE|COLOR_3|" + hexToUint(colorObj.value); + websocket.send(colorMsg); +} + +function setMatrixColor3Value(id, color) { + var combo = document.querySelector("#mc3i" + id); + combo.value = color; +} + +function matrixColor4Change(id) { + var colorObj = document.querySelector("#mc4i" + id); + var colorMsg = id + "|MATRIX_COLOR_CHANGE|COLOR_4|" + hexToUint(colorObj.value); + websocket.send(colorMsg); +} + +function setMatrixColor2Value(id, color) { + var combo = document.querySelector("#mc4i" + id); combo.value = color; } -function matrixEndColorChange(id) { - var colorObj = document.querySelector("#mec" + id); - var colorMsg = id + "|MATRIX_COLOR_CHANGE|END|" + hexToUint(colorObj.value); +function matrixColor5Change(id) { + var colorObj = document.querySelector("#mc5i" + id); + var colorMsg = id + "|MATRIX_COLOR_CHANGE|COLOR_5|" + hexToUint(colorObj.value); websocket.send(colorMsg); } -function setMatrixEndColorValue(id, color) { - var combo = document.querySelector("#mec" + id); +function setMatrixColor5Value(id, color) { + var combo = document.querySelector("#mc5i" + id); combo.value = color; } diff --git a/webaccess/res/websocket.js b/webaccess/res/websocket.js index 6c1e0291ee..2c9ffe35ca 100644 --- a/webaccess/res/websocket.js +++ b/webaccess/res/websocket.js @@ -73,9 +73,15 @@ function connect() { setCueButtonStyle(msgParams[0], msgParams[2], msgParams[3], msgParams[4], msgParams[5]); } else if (msgParams[1] === "MATRIX_SLIDER") { setMatrixSliderValue(msgParams[0], msgParams[2]); - } else if (msgParams[1] === "MATRIX_START_COLOR") { + } else if (msgParams[1] === "MATRIX_COLOR_1") { setMatrixStartColorValue(msgParams[0], msgParams[2]); - } else if (msgParams[1] === "MATRIX_END_COLOR") { + } else if (msgParams[1] === "MATRIX_COLOR_2") { + setMatrixEndColorValue(msgParams[0], msgParams[2]); + } else if (msgParams[1] === "MATRIX_COLOR_3") { + setMatrixEndColorValue(msgParams[0], msgParams[2]); + } else if (msgParams[1] === "MATRIX_COLOR_4") { + setMatrixEndColorValue(msgParams[0], msgParams[2]); + } else if (msgParams[1] === "MATRIX_COLOR_5") { setMatrixEndColorValue(msgParams[0], msgParams[2]); } else if (msgParams[1] === "MATRIX_COMBO") { setMatrixComboValue(msgParams[0], msgParams[2]); diff --git a/webaccess/src/webaccess.cpp b/webaccess/src/webaccess.cpp index 0c6eff9a93..f6e1879a7e 100644 --- a/webaccess/src/webaccess.cpp +++ b/webaccess/src/webaccess.cpp @@ -805,10 +805,16 @@ void WebAccess::slotHandleWebSocketRequest(QHttpConnection *conn, QString data) matrix->slotSetSliderValue(cmdList[2].toInt()); if (cmdList[1] == "MATRIX_COMBO_CHANGE") matrix->slotSetAnimationValue(cmdList[2]); - if (cmdList[1] == "MATRIX_COLOR_CHANGE" && cmdList[2] == "START") - matrix->slotStartColorChanged(cmdList[3].toInt()); - if (cmdList[1] == "MATRIX_COLOR_CHANGE" && cmdList[2] == "END") - matrix->slotEndColorChanged(cmdList[3].toInt()); + if (cmdList[1] == "MATRIX_COLOR_CHANGE" && cmdList[2] == "COLOR_1") + matrix->slotColor1Changed(cmdList[3].toInt()); + if (cmdList[1] == "MATRIX_COLOR_CHANGE" && cmdList[2] == "COLOR_2") + matrix->slotColor2Changed(cmdList[3].toInt()); + if (cmdList[1] == "MATRIX_COLOR_CHANGE" && cmdList[2] == "COLOR_3") + matrix->slotColor3Changed(cmdList[3].toInt()); + if (cmdList[1] == "MATRIX_COLOR_CHANGE" && cmdList[2] == "COLOR_4") + matrix->slotColor4Changed(cmdList[3].toInt()); + if (cmdList[1] == "MATRIX_COLOR_CHANGE" && cmdList[2] == "COLOR_5") + matrix->slotColor5Changed(cmdList[3].toInt()); if (cmdList[1] == "MATRIX_KNOB") matrix->slotMatrixControlKnobValueChanged(cmdList[2].toInt(), cmdList[3].toInt()); if (cmdList[1] == "MATRIX_PUSHBUTTON") @@ -1646,23 +1652,53 @@ void WebAccess::slotMatrixSliderValueChanged(int value) sendWebSocketMessage(wsMessage.toUtf8()); } -void WebAccess::slotMatrixStartColorChanged() +void WebAccess::slotMatrixColor1Changed() { VCMatrix *matrix = qobject_cast(sender()); if (matrix == NULL) return; - QString wsMessage = QString("%1|MATRIX_START_COLOR|%2").arg(matrix->id()).arg(matrix->startColor().name()); + QString wsMessage = QString("%1|MATRIX_COLOR_1|%2").arg(matrix->id()).arg(matrix->mtxColor(0).name()); sendWebSocketMessage(wsMessage.toUtf8()); } -void WebAccess::slotMatrixEndColorChanged() +void WebAccess::slotMatrixColor2Changed() { VCMatrix *matrix = qobject_cast(sender()); if (matrix == NULL) return; - QString wsMessage = QString("%1|MATRIX_END_COLOR|%2").arg(matrix->id()).arg(matrix->endColor().name()); + QString wsMessage = QString("%1|MATRIX_COLOR_2|%2").arg(matrix->id()).arg(matrix->mtxColor(1).name()); + sendWebSocketMessage(wsMessage.toUtf8()); +} + +void WebAccess::slotMatrixColor3Changed() +{ + VCMatrix *matrix = qobject_cast(sender()); + if (matrix == NULL) + return; + + QString wsMessage = QString("%1|MATRIX_COLOR_3|%2").arg(matrix->id()).arg(matrix->mtxColor(2).name()); + sendWebSocketMessage(wsMessage.toUtf8()); +} + +void WebAccess::slotMatrixColor4Changed() +{ + VCMatrix *matrix = qobject_cast(sender()); + if (matrix == NULL) + return; + + QString wsMessage = QString("%1|MATRIX_COLOR_4|%2").arg(matrix->id()).arg(matrix->mtxColor(3).name()); + sendWebSocketMessage(wsMessage.toUtf8()); +} + +void WebAccess::slotMatrixColor5Changed() +{ + VCMatrix *matrix = qobject_cast(sender()); + if (matrix == NULL) + return; + + QString wsMessage = QString("%1|MATRIX_COLOR_5|%2").arg(matrix->id()).arg(matrix->mtxColor(4).name()); sendWebSocketMessage(wsMessage.toUtf8()); } @@ -1711,15 +1747,29 @@ QString WebAccess::getMatrixHTML(VCMatrix *matrix) str += "
"+matrix->caption()+"
"; } str += "
"; - if (matrix->visibilityMask() & VCMatrix::Visibility::ShowStartColorButton) { - - str += "id())+"\" class=\"vMatrix\" value=\""+(matrix->startColor().name())+"\" " - "oninput=\"matrixStartColorChange(" + QString::number(matrix->id()) + ");\" ontouchmove=\"matrixStartColorChange(" + QString::number(matrix->id()) + ");\" " + if (matrix->visibilityMask() & VCMatrix::Visibility::ShowColor1Button) { + str += "id())+"\" class=\"vMatrix\" value=\""+(matrix->mtxColor(0).name())+"\" " + "oninput=\"matrixColor1Change(" + QString::number(matrix->id()) + ");\" ontouchmove=\"matrixColor1Change(" + QString::number(matrix->id()) + ");\" " " />"; } - if (matrix->visibilityMask() & VCMatrix::Visibility::ShowEndColorButton) { - str += "id())+"\" class=\"vMatrix\" value=\""+(matrix->endColor().name())+"\" " - "oninput=\"matrixEndColorChange(" + QString::number(matrix->id()) + ");\" ontouchmove=\"matrixEndColorChange(" + QString::number(matrix->id()) + ");\" " + if (matrix->visibilityMask() & VCMatrix::Visibility::ShowColor2Button) { + str += "id())+"\" class=\"vMatrix\" value=\""+(matrix->mtxColor(1).name())+"\" " + "oninput=\"matrixColor2Change(" + QString::number(matrix->id()) + ");\" ontouchmove=\"matrixColor2Change(" + QString::number(matrix->id()) + ");\" " + " />"; + } + if (matrix->visibilityMask() & VCMatrix::Visibility::ShowColor3Button) { + str += "id())+"\" class=\"vMatrix\" value=\""+(matrix->mtxColor(2).name())+"\" " + "oninput=\"matrixColor3Change(" + QString::number(matrix->id()) + ");\" ontouchmove=\"matrixColor3Change(" + QString::number(matrix->id()) + ");\" " + " />"; + } + if (matrix->visibilityMask() & VCMatrix::Visibility::ShowColor4Button) { + str += "id())+"\" class=\"vMatrix\" value=\""+(matrix->mtxColor(3).name())+"\" " + "oninput=\"matrixColor4Change(" + QString::number(matrix->id()) + ");\" ontouchmove=\"matrixColor4Change(" + QString::number(matrix->id()) + ");\" " + " />"; + } + if (matrix->visibilityMask() & VCMatrix::Visibility::ShowColor5Button) { + str += "id())+"\" class=\"vMatrix\" value=\""+(matrix->mtxColor(4).name())+"\" " + "oninput=\"matrixColor5Change(" + QString::number(matrix->id()) + ");\" ontouchmove=\"matrixColor5Change(" + QString::number(matrix->id()) + ");\" " " />"; } str += "
"; @@ -1738,18 +1788,45 @@ QString WebAccess::getMatrixHTML(VCMatrix *matrix) str += "
"; for (int i = 0; i < customControls.length(); i++) { VCMatrixControl *control = customControls[i]; - if (control->m_type == VCMatrixControl::StartColor) { + if (control->m_type == VCMatrixControl::Color1) { str += "
m_color.name())+"; margin-right: 4px; margin-bottom: 4px; \" " - "onclick=\"wcMatrixPushButtonClicked("+(QString::number(control->m_id))+")\">S
"; - } else if (control->m_type == VCMatrixControl::EndColor) { + "onclick=\"wcMatrixPushButtonClicked("+(QString::number(control->m_id))+")\">1
"; + } else if (control->m_type == VCMatrixControl::Color2) { str += "
m_color.name())+"; margin-right: 4px; margin-bottom: 4px; \" " - "onclick=\"wcMatrixPushButtonClicked("+(QString::number(control->m_id))+")\">E
"; - } else if (control->m_type == VCMatrixControl::ResetEndColor) { - QString btnLabel = tr("End Color Reset"); + "onclick=\"wcMatrixPushButtonClicked("+(QString::number(control->m_id))+")\">2"; + } else if (control->m_type == VCMatrixControl::Color2Reset) { + QString btnLabel = tr("Color 2 Reset"); str += "
m_id))+")\">"+btnLabel+"
"; + } else if (control->m_type == VCMatrixControl::Color3) { + str += "
m_color.name())+"; margin-right: 4px; margin-bottom: 4px; \" " + "onclick=\"wcMatrixPushButtonClicked("+(QString::number(control->m_id))+")\">3
"; + } else if (control->m_type == VCMatrixControl::Color3Reset) { + QString btnLabel = tr("Color 3 Reset"); + str += "
m_id))+")\">"+btnLabel+"
"; + } else if (control->m_type == VCMatrixControl::Color4) { + str += "
m_color.name())+"; margin-right: 4px; margin-bottom: 4px; \" " + "onclick=\"wcMatrixPushButtonClicked("+(QString::number(control->m_id))+")\">4
"; + } else if (control->m_type == VCMatrixControl::Color4Reset) { + QString btnLabel = tr("Color 4 Reset"); + str += "
m_id))+")\">"+btnLabel+"
"; + } else if (control->m_type == VCMatrixControl::Color5) { + str += "
m_color.name())+"; margin-right: 4px; margin-bottom: 4px; \" " + "onclick=\"wcMatrixPushButtonClicked("+(QString::number(control->m_id))+")\">5
"; + } else if (control->m_type == VCMatrixControl::Color5Reset) { + QString btnLabel = tr("Color 5 Reset"); + str += "
m_id))+")\">"+btnLabel+"
"; } else if (control->m_type == VCMatrixControl::Animation || control->m_type == VCMatrixControl::Text) { QString btnLabel = control->m_resource; @@ -1769,10 +1846,14 @@ QString WebAccess::getMatrixHTML(VCMatrix *matrix) str += "
m_id))+")\">"+btnLabel+"
"; - } else if (control->m_type == VCMatrixControl::StartColorKnob || control->m_type == VCMatrixControl::EndColorKnob) { + } else if (control->m_type == VCMatrixControl::Color1Knob + || control->m_type == VCMatrixControl::Color2Knob + || control->m_type == VCMatrixControl::Color3Knob + || control->m_type == VCMatrixControl::Color4Knob + || control->m_type == VCMatrixControl::Color5Knob) { KnobWidget *knob = qobject_cast(matrix->getWidget(control)); QString slID = QString::number(control->m_id); - QColor color = control->m_type == VCMatrixControl::StartColorKnob ? control->m_color : control->m_color.darker(250); + QColor color = control->m_type == VCMatrixControl::Color1Knob ? control->m_color : control->m_color.darker(250); str += "
"; str += "
"; diff --git a/webaccess/src/webaccess.h b/webaccess/src/webaccess.h index 998ee56de3..179cbd8cc9 100644 --- a/webaccess/src/webaccess.h +++ b/webaccess/src/webaccess.h @@ -98,8 +98,11 @@ protected slots: void slotClockTimeChanged(quint32 time); void slotFramePageChanged(int pageNum); void slotMatrixSliderValueChanged(int value); - void slotMatrixStartColorChanged(); - void slotMatrixEndColorChanged(); + void slotMatrixColor1Changed(); + void slotMatrixColor2Changed(); + void slotMatrixColor3Changed(); + void slotMatrixColor4Changed(); + void slotMatrixColor5Changed(); void slotMatrixAnimationValueChanged(QString name); void slotMatrixControlKnobValueChanged(int controlID, int value); From e6e3ab2bf3b4d5f63275ce560f81fabe7140ec0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Tue, 2 Jan 2024 18:06:36 +0100 Subject: [PATCH 33/63] Fix C&P typo in the function name. --- webaccess/res/virtualconsole.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webaccess/res/virtualconsole.js b/webaccess/res/virtualconsole.js index 61cbe66450..e75b4de1ec 100644 --- a/webaccess/res/virtualconsole.js +++ b/webaccess/res/virtualconsole.js @@ -466,7 +466,7 @@ function matrixColor4Change(id) { websocket.send(colorMsg); } -function setMatrixColor2Value(id, color) { +function setMatrixColor4Value(id, color) { var combo = document.querySelector("#mc4i" + id); combo.value = color; } From 19bf6af203b292416a0e2bf51a9b804f3bc9ef45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Tue, 2 Jan 2024 18:06:58 +0100 Subject: [PATCH 34/63] Consistently use the intended base argument in parseInt. --- resources/rgbscripts/devtool/devtool.js | 31 +++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/resources/rgbscripts/devtool/devtool.js b/resources/rgbscripts/devtool/devtool.js index 182d2b3659..7c7ed78d90 100644 --- a/resources/rgbscripts/devtool/devtool.js +++ b/resources/rgbscripts/devtool/devtool.js @@ -353,7 +353,8 @@ devtool.getCurrentColorInt = function() devtool.writeCurrentStep = function() { - devtool.currentStep = parseInt(document.getElementById("currentStep").value); // currentStep may have been changed manually + // currentStep may have been changed manually + devtool.currentStep = parseInt(document.getElementById("currentStep").value, 10); var map = document.getElementById("map"); for (var i = map.rows.length - 1; i >= 0; i--) { @@ -416,13 +417,13 @@ devtool.updateStepCount = function() devtool.onGridSizeUpdated = function() { - devtool.gridwidth = parseInt(document.getElementById("gridwidth").value); + devtool.gridwidth = parseInt(document.getElementById("gridwidth").value, 10); localStorage.setItem("devtool.gridwidth", devtool.gridwidth); - devtool.gridheight = parseInt(document.getElementById("gridheight").value); + devtool.gridheight = parseInt(document.getElementById("gridheight").value, 10); localStorage.setItem("devtool.gridheight", devtool.gridheight); - devtool.gridsize = parseInt(document.getElementById("gridsize").value); + devtool.gridsize = parseInt(document.getElementById("gridsize").value, 10); localStorage.setItem("devtool.gridsize", devtool.gridsize); devtool.updateStepCount(); @@ -432,7 +433,7 @@ devtool.onGridSizeUpdated = function() devtool.onColorTextChange = function() { - var color = parseInt("0x" + document.getElementById("color1Text").value).toString(16); + var color = parseInt("0x" + document.getElementById("color1Text").value, 16).toString(16); if (color === "NaN"){ document.getElementById("color1Picker").value = "#000000"; } else { @@ -440,7 +441,7 @@ devtool.onColorTextChange = function() } localStorage.setItem("devtool.color1", color); - color = parseInt("0x" + document.getElementById("color2Text").value).toString(16); + color = parseInt("0x" + document.getElementById("color2Text").value, 16).toString(16); if (color === "NaN") { // Evaluation of the string. document.getElementById("color2Picker").value = "#000000"; localStorage.setItem("devtool.color2", ""); @@ -449,7 +450,7 @@ devtool.onColorTextChange = function() localStorage.setItem("devtool.color2", color); } - color = parseInt("0x" + document.getElementById("color3Text").value).toString(16); + color = parseInt("0x" + document.getElementById("color3Text").value, 16).toString(16); if (color === "NaN") { // Evaluation of the string. document.getElementById("color3Picker").value = "#000000"; localStorage.setItem("devtool.color3", ""); @@ -458,7 +459,7 @@ devtool.onColorTextChange = function() localStorage.setItem("devtool.color3", color); } - color = parseInt("0x" + document.getElementById("color4Text").value).toString(16); + color = parseInt("0x" + document.getElementById("color4Text").value, 16).toString(16); if (color === "NaN") { // Evaluation of the string. document.getElementById("color4Picker").value = "#000000"; localStorage.setItem("devtool.color4", ""); @@ -467,7 +468,7 @@ devtool.onColorTextChange = function() localStorage.setItem("devtool.color4", color); } - color = parseInt("0x" + document.getElementById("color5Text").value).toString(16); + color = parseInt("0x" + document.getElementById("color5Text").value, 16).toString(16); if (color === "NaN") { // Evaluation of the string. document.getElementById("color5Picker").value = "#000000"; localStorage.setItem("devtool.color5", ""); @@ -481,10 +482,10 @@ devtool.onColorTextChange = function() devtool.onColorPickerChange = function(i) { - textId = "color" + i + "Text"; - pickerId = "color" + i + "Picker"; - oldTextValue = document.getElementById(textId).value; - newTextValue = document.getElementById(pickerId).value.substring(1); + var textId = "color" + i + "Text"; + var pickerId = "color" + i + "Picker"; + var oldTextValue = document.getElementById(textId).value; + var newTextValue = document.getElementById(pickerId).value.substring(1); if (oldTextValue != newTextValue) { document.getElementById(textId).value = newTextValue; devtool.onColorTextChange(); @@ -512,8 +513,8 @@ devtool.stopTest = function() devtool.initTestStatus = function() { let timerStatus = localStorage.getItem("devtool.timerRunning"); - if (timerStatus === null || parseInt(timerStatus) !== 0) { - devtool.startTest(parseInt(timerStatus)); + if (timerStatus === null || parseInt(timerStatus, 10) !== 0) { + devtool.startTest(parseInt(timerStatus, 10)); } } From ca386adf0e0de5192963275a46a0212ab655b979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Tue, 2 Jan 2024 18:36:53 +0100 Subject: [PATCH 35/63] Uodate ballscolors to support more than 5 balls and catch up the different colors from the color inputs. --- resources/rgbscripts/ballscolors.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/resources/rgbscripts/ballscolors.js b/resources/rgbscripts/ballscolors.js index 2a3b7ed4ce..1479d8d1cc 100644 --- a/resources/rgbscripts/ballscolors.js +++ b/resources/rgbscripts/ballscolors.js @@ -31,7 +31,7 @@ var testAlgo; algo.presetSize = 1; algo.properties.push("name:presetSize|type:range|display:Size|values:1,20|write:setSize|read:getSize"); algo.presetNumber = 5; - algo.properties.push("name:presetNumber|type:range|display:Number|values:1,5|write:setNumber|read:getNumber"); + algo.properties.push("name:presetNumber|type:range|display:Number|values:1,15|write:setNumber|read:getNumber"); algo.presetCollision = 0; algo.properties.push("name:presetCollision|type:list|display:Self Collision|values:No,Yes|write:setCollision|read:getCollision"); algo.presetSize = 5; @@ -88,10 +88,6 @@ var testAlgo; var xDirection = (Math.random() * 2) - 1; algo.direction[i] = [yDirection, xDirection]; } - // Get the colors from the external preset. - for (var i = algo.acceptColors; i < algo.presetNumber; i++) { - algo.colour[i] = colorPalette.collection[algo.colorIndex[i - algo.acceptColors]][1]; - } algo.initialized = true; return; }; @@ -100,8 +96,8 @@ var testAlgo; if (algo.initialized === false) { util.initialize(width, height); } - for (var i = 0; i < algo.acceptColors; i++) { - algo.colour[i] = algo.getRawColor(rawColors, i); + for (var i = 0; i < algo.presetNumber; i++) { + algo.colour[i] = algo.getRawColor(rawColors, i % algo.acceptColors); } var map = new Array(height); // Clear map data From 54965164b17e2c450f2b50a1043e8ac1d081cc5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Tue, 2 Jan 2024 18:55:59 +0100 Subject: [PATCH 36/63] Update translations of new knobs. --- ui/src/virtualconsole/vcmatrix.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ui/src/virtualconsole/vcmatrix.cpp b/ui/src/virtualconsole/vcmatrix.cpp index 75e73af47c..30d0998371 100644 --- a/ui/src/virtualconsole/vcmatrix.cpp +++ b/ui/src/virtualconsole/vcmatrix.cpp @@ -1017,11 +1017,11 @@ void VCMatrix::addCustomControl(VCMatrixControl const& control) controlKnob->setFixedHeight(36); QString knobLabel; if (control.m_color == Qt::red) - knobLabel = tr("Start color Red component"); + knobLabel = tr("Color 1 Red component"); else if (control.m_color == Qt::green) - knobLabel = tr("Start color Green component"); + knobLabel = tr("Color 1 Green component"); else if (control.m_color == Qt::blue) - knobLabel = tr("Start color Blue component"); + knobLabel = tr("Color 1 Blue component"); controlKnob->setToolTip(knobLabel); } else if (control.m_type == VCMatrixControl::Color2Knob) @@ -1033,11 +1033,11 @@ void VCMatrix::addCustomControl(VCMatrixControl const& control) controlKnob->setFixedHeight(36); QString knobLabel; if (control.m_color == Qt::red) - knobLabel = tr("End color Red component"); + knobLabel = tr("Color 2 Red component"); else if (control.m_color == Qt::green) - knobLabel = tr("End color Green component"); + knobLabel = tr("Color 2 Green component"); else if (control.m_color == Qt::blue) - knobLabel = tr("End color Blue component"); + knobLabel = tr("Color 2 Blue component"); controlKnob->setToolTip(knobLabel); } else if (control.m_type == VCMatrixControl::Color3Knob) @@ -1049,11 +1049,11 @@ void VCMatrix::addCustomControl(VCMatrixControl const& control) controlKnob->setFixedHeight(36); QString knobLabel; if (control.m_color == Qt::red) - knobLabel = tr("End color Red component"); + knobLabel = tr("Color 3 Red component"); else if (control.m_color == Qt::green) - knobLabel = tr("End color Green component"); + knobLabel = tr("Color 3 Green component"); else if (control.m_color == Qt::blue) - knobLabel = tr("End color Blue component"); + knobLabel = tr("Color 3 Blue component"); controlKnob->setToolTip(knobLabel); } else if (control.m_type == VCMatrixControl::Color4Knob) @@ -1065,11 +1065,11 @@ void VCMatrix::addCustomControl(VCMatrixControl const& control) controlKnob->setFixedHeight(36); QString knobLabel; if (control.m_color == Qt::red) - knobLabel = tr("End color Red component"); + knobLabel = tr("Color 4 Red component"); else if (control.m_color == Qt::green) - knobLabel = tr("End color Green component"); + knobLabel = tr("Color 4 Green component"); else if (control.m_color == Qt::blue) - knobLabel = tr("End color Blue component"); + knobLabel = tr("Color 4 Blue component"); controlKnob->setToolTip(knobLabel); } else if (control.m_type == VCMatrixControl::Color5Knob) @@ -1081,11 +1081,11 @@ void VCMatrix::addCustomControl(VCMatrixControl const& control) controlKnob->setFixedHeight(36); QString knobLabel; if (control.m_color == Qt::red) - knobLabel = tr("End color Red component"); + knobLabel = tr("Color 5 Red component"); else if (control.m_color == Qt::green) - knobLabel = tr("End color Green component"); + knobLabel = tr("Color 5 Green component"); else if (control.m_color == Qt::blue) - knobLabel = tr("End color Blue component"); + knobLabel = tr("Color 5 Blue component"); controlKnob->setToolTip(knobLabel); } From bdd74ee88a4ac1cf77ca9fcd53fb9c54301d9634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Mon, 25 Mar 2024 19:19:29 +0100 Subject: [PATCH 37/63] Resurrect original scripts for backward compatibility. --- resources/rgbscripts/CMakeLists.txt | 4 + resources/rgbscripts/alternate-2colors.js | 258 +++++++++++ resources/rgbscripts/alternate.js | 117 ++++- resources/rgbscripts/balls5colors.js | 200 ++++++++ resources/rgbscripts/ballscolors.js | 149 +++++- resources/rgbscripts/marquee-2colors.js | 248 ++++++++++ resources/rgbscripts/marquee.js | 95 +++- resources/rgbscripts/plasma5colors.js | 286 ++++++++++++ resources/rgbscripts/plasmacolors.js | 529 +++++++++++++--------- resources/rgbscripts/rgbscripts.pro | 4 + 10 files changed, 1618 insertions(+), 272 deletions(-) create mode 100644 resources/rgbscripts/alternate-2colors.js create mode 100644 resources/rgbscripts/balls5colors.js create mode 100644 resources/rgbscripts/marquee-2colors.js create mode 100644 resources/rgbscripts/plasma5colors.js diff --git a/resources/rgbscripts/CMakeLists.txt b/resources/rgbscripts/CMakeLists.txt index acd4510d1b..276d247554 100644 --- a/resources/rgbscripts/CMakeLists.txt +++ b/resources/rgbscripts/CMakeLists.txt @@ -2,8 +2,10 @@ project(scripts) set(SCRIPT_FILES alternate.js + alternate-2colors.js balls.js ballscolors.js + balls5colors.js blinder.js circles.js circular.js @@ -18,11 +20,13 @@ set(SCRIPT_FILES gradient.js lines.js marquee.js + marquee-2colors.js noise.js onebyone.js opposite.js plasma.js plasmacolors.js + plasma5colors.js randomcolumn.js randomfillcolumn.js randomfillrow.js diff --git a/resources/rgbscripts/alternate-2colors.js b/resources/rgbscripts/alternate-2colors.js new file mode 100644 index 0000000000..fa359e5864 --- /dev/null +++ b/resources/rgbscripts/alternate-2colors.js @@ -0,0 +1,258 @@ +/* + Q Light Controller Plus + alternate-2colors.js + + Copyright (c) Hans-Jürgen Tappe + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0.txt + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +// Development tool access +var testAlgo; + +(function() { + + var algo = new Object; + algo.apiVersion = 3; + algo.name = "Alternate (2 Colors)"; + algo.author = "Hans-Jürgen Tappe"; + + var x = 0; + var y = 0; + + algo.acceptColors = 2; + algo.properties = new Array(); + + algo.align = 0; + algo.properties.push("name:align|type:list|" + + "display:Align (for even width)|values:Left,Centered,Split|" + + "write:setAlign|read:getAlign"); + // Left aligned is default. + algo.setAlign = function(_align) { + if (_align === "Centered") { + algo.align = 1; + } else if (_align === "Split") { + algo.align = 2; + } else { + algo.align = 0; + } + }; + algo.getAlign = function() { + if (algo.align === 1) { + return "Centered"; + } else if (algo.align === 2) { + return "Split"; + } else { + return "Left"; + } + }; + + algo.orientation = 0; + algo.properties.push("name:orientation|type:list|" + + "display:Orientation|values:Horizontal,Vertical,Interleaved|" + + "write:setOrientation|read:getOrientation"); + algo.setOrientation = function(_orientation) { + if (_orientation === "Vertical") { + algo.orientation = 1; + } else if (_orientation === "Interleaved") { + algo.orientation = 2; + } else { + algo.orientation = 0; + } + }; + algo.getOrientation = function() { + if (parseInt(algo.orientation, 10) === 1) { + return "Vertical"; + } else if (algo.orientation === 2) { + return "Interleaved"; + } else { + return "Horizontal"; + } + }; + + algo.blockSize = 1; + algo.properties.push("name:blockSize|type:range|" + + "display:Block Size / Split (>= 1)|" + + "values:1,32000|" + + "write:setBlockSize|read:getBlockSize"); + algo.setBlockSize = function(_size) { + algo.blockSize = parseInt(_size, 10); + }; + algo.getBlockSize = function() { + return algo.blockSize; + }; + + algo.offset = 0; + algo.properties.push("name:offset|type:range|" + + "display:Offset (>= 0)|" + + "values:0,32000|" + + "write:setOffset|read:getOffset"); + algo.setOffset = function(_size) { + algo.offset = parseInt(_size, 10); + }; + algo.getOffset = function() { + return algo.offset; + }; + + algo.getRawColor = function (rawColors, idx) { + if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { + return rawColors[idx]; + } else { + return 0; + } + } + + algo.rgbMap = function(width, height, rgb, step, rawColors) { + var map = new Array(height); + var colorSelectOne = (step === 1) ? false : true; + var rowColorOne = colorSelectOne; + var realBlockSize = algo.blockSize; + + for (y = 0; y < height; y++) { + map[parseInt(y, 10)] = new Array(width); + for (x = 0; x < width; x++) { + map[parseInt(y, 10)][parseInt(x, 10)] = 0; + } + } + + var xMax = width; + var yMax = height; + if (algo.align === 1) { + if (algo.orientation === 0 || algo.orientation === 2) { + // Centered mode + xMax = Math.ceil(width / 2); + } + if (algo.orientation === 1 || algo.orientation === 2) { + // Centered mode + yMax = Math.ceil(height / 2); + } + } + + if (algo.align === 2) { + // Split mode + if (algo.orientation === 0) { + // Horizontal + realBlockSize = width / algo.blockSize; + } else if (algo.orientation === 1) { + // Vertical + realBlockSize = height / algo.blockSize; + } else if (algo.orientation === 2) { + // Interleaved + realBlockSize = Math.min(width, height) / algo.blockSize; + } + } + + var effectiveStep; + var realBlockCount; + var lowRest; + var highRest; + var rest; + for (y = 0; y < yMax; y++) { + if (algo.orientation === 0) { + // Horizontal split; vertical lines + // Initialize vertical bars, each column the same + colorSelectOne = (step === 1) ? false : true; + } else if (algo.orientation === 1) { + // Horizontal Bars, count steps by row + effectiveStep = y + Math.round(step * realBlockSize) + algo.offset; + + // Initialize start color for each row. + realBlockCount = Math.floor(effectiveStep / realBlockSize); + lowRest = effectiveStep - realBlockCount * realBlockSize; + highRest = (realBlockCount + 1) * realBlockSize - effectiveStep; + rest = Math.min(lowRest, highRest); + if (rest < 0.5 || lowRest === 0.5) { + colorSelectOne = !colorSelectOne; + } + } else if (algo.orientation === 2) { + // Interleaved + var effectiveY = y + Math.floor(step * realBlockSize) + algo.offset; + + realBlockCount = Math.floor(effectiveY / realBlockSize); + lowRest = effectiveY - realBlockCount * realBlockSize; + highRest = (realBlockCount + 1) * realBlockSize - effectiveY; + rest = Math.min(lowRest, highRest); + if (rest < 0.5 || lowRest === 0.5) { + rowColorOne = !rowColorOne; + } + colorSelectOne = rowColorOne; + } + + for (x = 0; x < xMax; x++) { + if (algo.orientation === 0) { + // Horizontal split, vertical bars, count steps by column + effectiveStep = x + algo.offset; + realBlockCount = Math.floor(effectiveStep / realBlockSize); + lowRest = effectiveStep - realBlockCount * realBlockSize; + highRest = (realBlockCount + 1) * realBlockSize - effectiveStep; + rest = Math.min(lowRest, highRest); + if (rest < 0.5 || lowRest == 0.5) { + colorSelectOne = !colorSelectOne; + } + } else if (algo.orientation === 2) { + // vertical split, horizontal Bars, count steps by row and column + var effectiveX = x + Math.floor(step * realBlockSize) + algo.offset; + // Change color each step. + realBlockCount = Math.floor(effectiveX / realBlockSize); + lowRest = effectiveX - realBlockCount * realBlockSize; + highRest = (realBlockCount + 1) * realBlockSize - effectiveX; + rest = Math.min(lowRest, highRest); + if (rest < 0.5 || lowRest == 0.5) { + colorSelectOne = !colorSelectOne; + } + } + if (colorSelectOne) { + map[parseInt(y, 10)][parseInt(x, 10)] = algo.getRawColor(rawColors, 0); + } else { + map[parseInt(y, 10)][parseInt(x, 10)] = algo.getRawColor(rawColors, 1); + } + } + } + // Align centered + if (algo.align === 1) { + if (algo.orientation === 0) { + for (y = 0; y < yMax; y++) { + for (x = 0; x < xMax; x++) { + map[parseInt(y, 10)][parseInt(width - x - 1, 10)] = map[parseInt(y, 10)][parseInt(x, 10)]; + } + } + } else if (algo.orientation === 1) { + for (y = 0; y < yMax; y++) { + for (x = 0; x < xMax; x++) { + map[parseInt(height - y - 1, 10)][parseInt(x, 10)] = map[parseInt(y, 10)][parseInt(x, 10)]; + } + } + } else if (algo.orientation === 2) { + for (y = 0; y < yMax; y++) { + for (x = 0; x < xMax; x++) { + map[parseInt(height - y - 1, 10)][parseInt(x, 10)] = map[parseInt(y, 10)][parseInt(x, 10)]; + map[parseInt(y, 10)][parseInt(width - x - 1, 10)] = map[parseInt(y, 10)][parseInt(x, 10)]; + map[parseInt(height - y - 1, 10)][parseInt(width - x - 1, 10)] = map[parseInt(y, 10)][parseInt(x, 10)]; + } + } + } + } + + return map; + }; + + algo.rgbMapStepCount = function(width, height) { + // Only two steps; one for even pixels and another for odd pixels + return 2; + }; + + // Development tool access + testAlgo = algo; + + return algo; +})(); diff --git a/resources/rgbscripts/alternate.js b/resources/rgbscripts/alternate.js index 52c42ec41b..7381e06852 100644 --- a/resources/rgbscripts/alternate.js +++ b/resources/rgbscripts/alternate.js @@ -21,18 +21,117 @@ var testAlgo; (function() { + var colorPalette = new Object; + colorPalette.collection = new Array( + ["White", 0xFFFFFF], // 0 + ["Cream", 0xFFFF7F], // 1 + ["Pink", 0xFF7F7F], // 2 + ["Rose", 0x7F3F3F], // 3 + ["Coral", 0x7F3F1F], // 4 + ["Dim Red", 0x7F0000], // 5 + ["Red", 0xFF0000], // 6 + ["Orange", 0xFF3F00], // 7 + ["Dim Orange", 0x7F1F00], // 8 + ["Goldenrod", 0x7F3F00], // 9 + ["Gold", 0xFF7F00], // 10 + ["Yellow", 0xFFFF00], // 11 + ["Dim Yellow", 0x7F7F00], // 12 + ["Lime", 0x7FFF00], // 13 + ["Pale Green", 0x3F7F00], // 14 + ["Dim Green", 0x007F00], // 15 + ["Green", 0x00FF00], // 16 + ["Seafoam", 0x00FF3F], // 17 + ["Turquoise", 0x007F3F], // 18 + ["Teal", 0x007F7F], // 19 + ["Cyan", 0x00FFFF], // 20 + ["Electric Blue", 0x007FFF], // 21 + ["Blue", 0x0000FF], // 22 + ["Dim Blue", 0x00007F], // 23 + ["Pale Blue", 0x1F1F7F], // 24 + ["Indigo", 0x1F00BF], // 25 + ["Purple", 0x3F00BF], // 26 + ["Violet", 0x7F007F], // 27 + ["Magenta", 0xFF00FF], // 28 + ["Hot Pink", 0xFF003F], // 29 + ["Deep Pink", 0x7F001F], // 30 + ["OFF", 0x000000]); // 31 + + colorPalette.makeSubArray = function(_index) { + var _array = new Array(); + for (var i = 0; i < colorPalette.collection.length; i++) { + _array.push(colorPalette.collection[parseInt(i, 10)][parseInt(_index, 10)]); + } + return _array; + }; + colorPalette.names = colorPalette.makeSubArray(0); var algo = new Object; - algo.apiVersion = 3; + algo.apiVersion = 2; algo.name = "Alternate"; algo.author = "Hans-Jürgen Tappe"; var x = 0; var y = 0; - algo.acceptColors = 2; + algo.acceptColors = 0; algo.properties = new Array(); + algo.getColorIndex = function(_name) { + var idx = colorPalette.names.indexOf(_name); + if (idx === -1) { + idx = (colorPalette.collection.length - 1); + } + return idx; + }; + + algo.color1Index = algo.getColorIndex("Red"); + algo.properties.push("name:color1Index|type:list|display:Color 1|" + + "values:" + colorPalette.names.toString() + "|" + + "write:setColor1Index|read:getColor1Name"); + algo.color2Index = algo.getColorIndex("Green"); + algo.properties.push("name:color2Index|type:list|display:Color 2|" + + "values:" + colorPalette.names.toString() + "|" + + "write:setColor2Index|read:getColor2Name"); + + algo.getColorName = function(_index) { + if (_index < 0) { + _index = 0; + } + if (_index >= colorPalette.collection.length) { + _index = (colorPalette.collection.length - 1); + } + return colorPalette.collection[parseInt(_index, 10)][0]; + }; + algo.getColorValue = function(_index) { + if (_index < 0) { + _index = 0; + } + else if (_index >= colorPalette.collection.length) { + _index = (colorPalette.collection.length - 1); + } + return colorPalette.collection[parseInt(_index, 10)][1]; + }; + + algo.setColor1Index = function(_name) { + algo.color1Index = algo.getColorIndex(_name); + }; + algo.getColor1Name = function() { + return algo.getColorName(algo.color1Index); + }; + algo.getColor1Value = function() { + return algo.getColorValue(algo.color1Index); + }; + + algo.setColor2Index = function(_name) { + algo.color2Index = algo.getColorIndex(_name); + }; + algo.getColor2Name = function() { + return algo.getColorName(algo.color2Index); + }; + algo.getColor2Value = function() { + return algo.getColorValue(algo.color2Index); + }; + algo.align = 0; algo.properties.push("name:align|type:list|" + "display:Align (for even width)|values:Left,Centered,Split|" + @@ -104,15 +203,7 @@ var testAlgo; return algo.offset; }; - algo.getRawColor = function (rawColors, idx) { - if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { - return rawColors[idx]; - } else { - return 0; - } - } - - algo.rgbMap = function(width, height, rgb, step, rawColors) { + algo.rgbMap = function(width, height, rgb, step) { var map = new Array(height); var colorSelectOne = (step === 1) ? false : true; var rowColorOne = colorSelectOne; @@ -212,9 +303,9 @@ var testAlgo; } } if (colorSelectOne) { - map[parseInt(y, 10)][parseInt(x, 10)] = algo.getRawColor(rawColors, 0); + map[parseInt(y, 10)][parseInt(x, 10)] = algo.getColor1Value(); } else { - map[parseInt(y, 10)][parseInt(x, 10)] = algo.getRawColor(rawColors, 1); + map[parseInt(y, 10)][parseInt(x, 10)] = algo.getColor2Value(); } } } diff --git a/resources/rgbscripts/balls5colors.js b/resources/rgbscripts/balls5colors.js new file mode 100644 index 0000000000..42a2e63132 --- /dev/null +++ b/resources/rgbscripts/balls5colors.js @@ -0,0 +1,200 @@ +/* + Q Light Controller Plus + balls5colors.js + + Copyright (c) Rob Nieuwenhuizen + + Licensed under the Apache License, Version 2.0 (the 'License'); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0.txt + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an 'AS IS' BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +// Development tool access +var testAlgo; + +( + function () { + var algo = new Object; + algo.apiVersion = 3; + algo.name = "Balls (5 Colors)"; + algo.author = "Rob Nieuwenhuizen"; + algo.acceptColors = 5; + algo.properties = new Array(); + algo.presetSize = 1; + algo.properties.push("name:presetSize|type:range|display:Size|values:1,20|write:setSize|read:getSize"); + algo.presetNumber = 5; + algo.properties.push("name:presetNumber|type:range|display:Number|values:1,15|write:setNumber|read:getNumber"); + algo.presetCollision = 0; + algo.properties.push("name:presetCollision|type:list|display:Self Collision|values:No,Yes|write:setCollision|read:getCollision"); + algo.presetSize = 5; + + algo.colorIndex = new Array( + algo.color3Index, + algo.color4Index, + algo.color5Index); + + var util = new Object; + algo.initialized = false; + + algo.setSize = function (_size) { + algo.presetSize = _size; + }; + algo.getSize = function () { + return algo.presetSize; + }; + + algo.setNumber = function (_step) { + algo.presetNumber = _step; + algo.initialized = false; + }; + algo.getNumber = function () { + return algo.presetNumber; + }; + algo.setCollision = function (_colision) { + if (_colision === "Yes") { algo.presetCollision = 0; } + else if (_colision === "No") { algo.presetCollision = 1; } + }; + algo.getCollision = function () { + if (algo.presetCollision === 0) { return "Yes"; } + else if (algo.presetCollision === 1) { return "No"; } + }; + + algo.getRawColor = function (rawColors, idx) { + if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { + return rawColors[idx]; + } else { + return 0; + } + } + + util.initialize = function (width, height) { + algo.ball = new Array(algo.presetNumber); + algo.direction = new Array(algo.presetNumber); + algo.colour = new Array(algo.presetNumber); + + for (var i = 0; i < algo.presetNumber; i++) { + var x = Math.random() * (width - 1); // set random start + var y = Math.random() * (height - 1); // locations for balls + algo.ball[i] = [y, x]; + var yDirection = (Math.random() * 2) - 1; // and random directions + var xDirection = (Math.random() * 2) - 1; + algo.direction[i] = [yDirection, xDirection]; + } + algo.initialized = true; + return; + }; + + algo.rgbMap = function (width, height, rgb, progstep, rawColors) { + if (algo.initialized === false) { + util.initialize(width, height); + } + for (var i = 0; i < algo.presetNumber; i++) { + algo.colour[i] = algo.getRawColor(rawColors, i % algo.acceptColors); + } + + var map = new Array(height); // Clear map data + for (var y = 0; y < height; y++) { + map[y] = new Array(); + + for (var x = 0; x < width; x++) { + map[y][x] = 0; + } + } + + for (var i = 0; i < algo.presetNumber; i++) { // for each ball displayed + rgb = algo.colour[i]; // use RGB for ball random colour + var r = (rgb >> 16) & 0x00FF; // split colour in to + var g = (rgb >> 8) & 0x00FF; // separate parts + var b = rgb & 0x00FF; + var yx = algo.ball[i]; // ball's location, as float + var step = algo.direction[i]; // ball's direction / speed, as float + var my = Math.floor(yx[0]); // workout closest map location for ball + var mx = Math.floor(yx[1]); + var boxSize = Math.round(algo.presetSize / 2); // area size to draw ball + + for (var ry = my - boxSize; ry < my + boxSize + 2; ry++) { // area for faded edges + + for (var rx = mx - boxSize; rx < mx + boxSize + 2; rx++) { // to display ball + + if (rx < width && rx > -1 && ry < height && ry > -1) { // if edges are off the map dont draw + var pointRGB = map[ry][rx]; // get curent colour on the map + var pointr = (pointRGB >> 16) & 0x00FF;// so that colours mix and don't over + var pointg = (pointRGB >> 8) & 0x00FF; // write. + var pointb = pointRGB & 0x00FF; // splt rgb in to components + var ballr = r; + var ballg = g; + var ballb = b; + var offx = rx - yx[1]; // calculate the off set differance of map location + var offy = ry - yx[0]; // to the float location of the ball, using the hypotenuse + var hyp = 1 - (Math.sqrt((offx * offx) + (offy * offy)) / ((algo.presetSize / 2) + 1)); + + if (hyp < 0) { hyp = 0; } // if the distance multiplyed by ball size is negative = 0 + pointr += Math.round(ballr * hyp); // dim mapped ball colours by the distance from + pointg += Math.round(ballg * hyp); // the ball center ( hyp = 1, full colour / 0, off) + pointb += Math.round(ballb * hyp); // add the ball colour to the mapped location + if (pointr > 255) { pointr = 255; } // if addind the colours over saturates + if (pointg > 255) { pointg = 255; } // reduce it to the maximum + if (pointb > 255) { pointb = 255; } + + pointRGB = (pointr << 16) + (pointg << 8) + pointb; // combine colours + + map[ry][rx] = pointRGB; // set mapped point + } + } + } + + if (algo.presetCollision === 0) { // if colision detection is on + // Ball collision detection + for (var ti = 0; ti < algo.presetNumber; ti++) { // check all balls + + if (ti !== i) { // but not the current one + var disy = (yx[0] + step[0]) - algo.ball[ti][0]; // calculate distance + var disx = (yx[1] + step[1]) - algo.ball[ti][1]; // to current ball + var dish = Math.sqrt((disx * disx) + (disy * disy)); + if (dish < (1.414) * (algo.presetSize / 2)) { // if to close + var stepy = step[0]; // swap speed / direction of current ball + var stepx = step[1]; // with ball that is to close + algo.direction[i][0] = algo.direction[ti][0]; + algo.direction[i][1] = algo.direction[ti][1]; + algo.direction[ti][0] = stepy; + algo.direction[ti][1] = stepx; + } + } + } + } + + // edge collision detection + if (yx[0] <= 0 && step[0] < 0) { step[0] *= -1; } // top edge and moving up + else if (yx[0] >= height - 1 && step[0] > 0) { step[0] *= -1; } // bottom edge and moving down + + if (yx[1] <= 0 && step[1] < 0) { step[1] *= -1; } // left edge and moving left + else if (yx[1] >= width - 1 && step[1] > 0) { step[1] *= -1; } // right edge and moving right + + yx[0] += step[0]; // set ball's next location + yx[1] += step[1]; + + algo.ball[i] = yx; // update location + algo.direction[i] = step; // and direction / speed + } + return map; + }; + + algo.rgbMapStepCount = function (width, height) { + // This make no difference to the script ;-) + return 2; + }; + + // Development tool access + testAlgo = algo; + + return algo; + } +)(); diff --git a/resources/rgbscripts/ballscolors.js b/resources/rgbscripts/ballscolors.js index 1479d8d1cc..994cacfde4 100644 --- a/resources/rgbscripts/ballscolors.js +++ b/resources/rgbscripts/ballscolors.js @@ -22,21 +22,92 @@ var testAlgo; ( function () { + var colorPalette = new Object; + colorPalette.collection = new Array( + ["White" , 0xFFFFFF], // 0 + ["Cream" , 0xFFFF7F], // 1 + ["Pink" , 0xFF7F7F], // 2 + ["Rose" , 0x7F3F3F], // 3 + ["Coral" , 0x7F3F1F], // 4 + ["Dim Red" , 0x7F0000], // 5 + ["Red" , 0xFF0000], // 6 + ["Orange" , 0xFF3F00], // 7 + ["Dim Orange" , 0x7F1F00], // 8 + ["Goldenrod" , 0x7F3F00], // 9 + ["Gold" , 0xFF7F00], // 10 + ["Yellow" , 0xFFFF00], // 11 + ["Dim Yellow" , 0x7F7F00], // 12 + ["Lime" , 0x7FFF00], // 13 + ["Pale Green" , 0x3F7F00], // 14 + ["Dim Green" , 0x007F00], // 15 + ["Green" , 0x00FF00], // 16 + ["Seafoam" , 0x00FF3F], // 17 + ["Turquoise" , 0x007F3F], // 18 + ["Teal" , 0x007F7F], // 19 + ["Cyan" , 0x00FFFF], // 20 + ["Electric Blue", 0x007FFF], // 21 + ["Blue" , 0x0000FF], // 22 + ["Dim Blue" , 0x00007F], // 23 + ["Pale Blue" , 0x1F1F7F], // 24 + ["Indigo" , 0x1F00BF], // 25 + ["Purple" , 0x3F00BF], // 26 + ["Violet" , 0x7F007F], // 27 + ["Magenta" , 0xFF00FF], // 28 + ["Hot Pink" , 0xFF003F], // 29 + ["Deep Pink" , 0x7F001F], // 30 + ["Black" , 0x000000]); // 31 + + colorPalette.makeSubArray = function (_index) { + var _array = new Array(); + for (var i = 0; i < colorPalette.collection.length; i++) { + _array.push(colorPalette.collection[i][_index]); + } + return _array; + }; + colorPalette.names = colorPalette.makeSubArray(0); + var algo = new Object; - algo.apiVersion = 3; + algo.apiVersion = 2; algo.name = "Balls (Colors)"; algo.author = "Rob Nieuwenhuizen"; - algo.acceptColors = 5; + algo.acceptColors = 0; algo.properties = new Array(); algo.presetSize = 1; algo.properties.push("name:presetSize|type:range|display:Size|values:1,20|write:setSize|read:getSize"); algo.presetNumber = 5; - algo.properties.push("name:presetNumber|type:range|display:Number|values:1,15|write:setNumber|read:getNumber"); + algo.properties.push("name:presetNumber|type:range|display:Number|values:1,5|write:setNumber|read:getNumber"); algo.presetCollision = 0; algo.properties.push("name:presetCollision|type:list|display:Self Collision|values:No,Yes|write:setCollision|read:getCollision"); + algo.color1Index = 0; + algo.properties.push( + "name:color1Index|type:list|display:Color 1|" + + "values:" + colorPalette.names.toString() + "|" + + "write:setColor1|read:getColor1"); + algo.color2Index = 6; + algo.properties.push( + "name:color2Index|type:list|display:Color 2|" + + "values:" + colorPalette.names.toString() + "|" + + "write:setColor2|read:getColor2"); + algo.color3Index = 16; + algo.properties.push( + "name:color3Index|type:list|display:Color 3|" + + "values:" + colorPalette.names.toString() + "|" + + "write:setColor3|read:getColor3"); + algo.color4Index = 22; + algo.properties.push( + "name:color4Index|type:list|display:Color 4|" + + "values:" + colorPalette.names.toString() + "|" + + "write:setColor4|read:getColor4"); + algo.color5Index = 7; + algo.properties.push( + "name:color5Index|type:list|display:Color 5|" + + "values:" + colorPalette.names.toString() + "|" + + "write:setColor5|read:getColor5"); algo.presetSize = 5; algo.colorIndex = new Array( + algo.color1Index, + algo.color2Index, algo.color3Index, algo.color4Index, algo.color5Index); @@ -67,13 +138,62 @@ var testAlgo; else if (algo.presetCollision === 1) { return "No"; } }; - algo.getRawColor = function (rawColors, idx) { - if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { - return rawColors[idx]; - } else { - return 0; + algo.setColor = function (_index, _preset) { + var i = colorPalette.names.indexOf(_preset); + if (i === -1) { + i = (colorPalette.collection.length - 1); + } + algo.colorIndex[_index] = i; + return algo.colorIndex[_index]; + }; + algo.getColor = function (_index) { + var i = algo.colorIndex[_index]; + if (i < 0) { i = 0; } + if (i >= colorPalette.collection.length) { + i = (colorPalette.collection.length - 1); } - } + return colorPalette.collection[i][0]; + }; + + algo.setColor1 = function (_preset) { + algo.color1Index = algo.setColor(0, _preset); + algo.initialized = false; + }; + algo.getColor1 = function () { + return algo.getColor(0); + }; + + algo.setColor2 = function (_preset) { + algo.color2Index = algo.setColor(1, _preset); + algo.initialized = false; + }; + algo.getColor2 = function () { + return algo.getColor(1); + }; + + algo.setColor3 = function (_preset) { + algo.color3Index = algo.setColor(2, _preset); + algo.initialized = false; + }; + algo.getColor3 = function () { + return algo.getColor(2); + }; + + algo.setColor4 = function (_preset) { + algo.color4Index = algo.setColor(3, _preset); + algo.initialized = false; + }; + algo.getColor4 = function () { + return algo.getColor(3); + }; + + algo.setColor5 = function (_preset) { + algo.color5Index = algo.setColor(4, _preset); + algo.initialized = false; + }; + algo.getColor5 = function () { + return algo.getColor(4); + }; util.initialize = function (width, height) { algo.ball = new Array(algo.presetNumber); @@ -87,20 +207,17 @@ var testAlgo; var yDirection = (Math.random() * 2) - 1; // and random directions var xDirection = (Math.random() * 2) - 1; algo.direction[i] = [yDirection, xDirection]; + algo.colour[i] = colorPalette.collection[algo.colorIndex[i]][1]; } algo.initialized = true; return; }; - algo.rgbMap = function (width, height, rgb, progstep, rawColors) { + algo.rgbMap = function (width, height, rgb, progstep) { if (algo.initialized === false) { util.initialize(width, height); } - for (var i = 0; i < algo.presetNumber; i++) { - algo.colour[i] = algo.getRawColor(rawColors, i % algo.acceptColors); - } - - var map = new Array(height); // Clear map data + var map = new Array(height); // Clear map data for (var y = 0; y < height; y++) { map[y] = new Array(); @@ -125,7 +242,7 @@ var testAlgo; for (var rx = mx - boxSize; rx < mx + boxSize + 2; rx++) { // to display ball if (rx < width && rx > -1 && ry < height && ry > -1) { // if edges are off the map dont draw - var pointRGB = map[ry][rx]; // get curent colour on the map + var pointRGB = map[ry][rx]; // get curent colour on the map var pointr = (pointRGB >> 16) & 0x00FF;// so that colours mix and don't over var pointg = (pointRGB >> 8) & 0x00FF; // write. var pointb = pointRGB & 0x00FF; // splt rgb in to components diff --git a/resources/rgbscripts/marquee-2colors.js b/resources/rgbscripts/marquee-2colors.js new file mode 100644 index 0000000000..c59b6762fe --- /dev/null +++ b/resources/rgbscripts/marquee-2colors.js @@ -0,0 +1,248 @@ +/* + Q Light Controller Plus + marquee-2colors.js + + Copyright (c) Branson Matheson + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0.txt + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +// Development tool access +var testAlgo; + +(function () { + var algo = new Object(); + algo.apiVersion = 3; + algo.name = "Marquee (2 Colors)"; + algo.author = "Branson Matheson"; + algo.acceptColors = 2; + algo.properties = new Array(); + algo.edgeDepth = 2; + algo.properties.push( + "name:depth|type:range|display:Depth|values:1,10000|write:setDepth|read:getDepth" + ); + algo.marquee = 0; + algo.properties.push( + "name:marquee|type:list|display:Marquee|values:None,Forward,Backward|write:setMarquee|read:getMarquee" + ); + algo.marqueeCount = 3; + algo.properties.push( + "name:marqueeCount|type:range|display:Marquee Spaces|values:1,100|write:setMarqueeCount|read:getMarqueeCount" + ); + + var util = new Object(); + util.initialized = false; + util.width = 0; + util.height = 0; + util.featureColor = 0; + util.step = algo.marqueeCount; + + util.lights = new Array(); + util.feature = new Array(); + + algo.setDepth = function (_amount) { + algo.edgeDepth = parseInt(_amount, 10); + util.initialized = false; + }; + + algo.getDepth = function () { + return algo.edgeDepth; + }; + + algo.setMarquee = function (_marquee) { + if (_marquee === "None") { + algo.marquee = 0; + } + if (_marquee === "Forward") { + algo.marquee = 1; + } + if (_marquee === "Backward") { + algo.marquee = 2; + } + util.initialized = false; + }; + + algo.getMarquee = function () { + if (algo.marquee === 0) { + return "None"; + } + if (algo.marquee === 1) { + return "Forward"; + } + if (algo.marquee === 2) { + return "Backward"; + } + }; + + algo.setMarqueeCount = function (_amount) { + algo.marqueeCount = parseInt(_amount, 10); + util.initialized = false; + }; + + algo.getMarqueeCount = function () { + return algo.marqueeCount; + }; + + util.initialize = function (width, height, rawColors) { + // initialize feature + util.featureColor = algo.getRawColor(rawColors, 0); + util.feature = new Array(); + var maxDistance = Math.min(width, height) / 2; + for (var y = 0; y < height; y++) { + util.feature[y] = new Array(); + var y_distance = y; + if (y >= height / 2) { + y_distance = height - y - 1; + } + + for (var x = 0; x < width; x++) { + // write color + var distance = algo.edgeDepth + 1; + util.feature[y][x] = 0; + + var x_distance = x; + if (x >= width / 2) { + x_distance = width - x - 1; + } + + distance = Math.min(x_distance, y_distance); + if (distance <= algo.edgeDepth && distance <= maxDistance) { + var percent = ((algo.edgeDepth - distance) / algo.edgeDepth) * 100; + util.feature[y][x] = util.fadeColor(util.featureColor, percent); + } else { + util.feature[y][x] = 0; + } + } + } + + // initialize lights array: 2 heights, 2 widths, 4 duplicate corner pixels + // only if the dimensions have changes (not on color change) + if (util.width != width || util.height != height || util.initialized !== true) { + var length = height * 2 + width * 2 - 4; + util.lights = new Array(length); + var pointAmount = Math.floor(util.lights.length / (algo.marqueeCount + 1)); + var mediumDistance = length / pointAmount; + for (var i = 0; i < util.lights.length; i++) { + if (i % mediumDistance < 1) { + util.lights[i] = 1; + } else { + util.lights[i] = 0; + } + } + } + // for testing for change + util.width = width; + util.height = height; + util.initialized = true; + }; + + util.fadeColor = function (rgb, percent) { + var r = (rgb >> 16) & 0x00ff; + var g = (rgb >> 8) & 0x00ff; + var b = rgb & 0x00ff; + var newR = Math.round(r * (percent / 100)); + var newG = Math.round(g * (percent / 100)); + var newB = Math.round(b * (percent / 100)); + var newRGB = (newR << 16) + (newG << 8) + newB; + return newRGB; + }; + + util.getNextStep = function (width, height, rawColors) { + var map = new Array(height); + for (var y = 0; y <= height - 1; y++) { + map[y] = new Array(width); + for (var x = 0; x <= width - 1; x++) { + map[y][x] = util.feature[y][x]; + } + } + + if (algo.marquee === 0) { return map } + + if (algo.marquee === 1) { + var first = util.lights.shift(); + util.lights.push(first); + } else if (algo.marquee === 2) { + var last = util.lights.pop(); + util.lights.unshift(last); + } + + // create light map add lights, go around the outside + var marqueeColor = algo.getRawColor(rawColors, 1); + var p = 0; + // left + for (var y = 0; y < height; y++) { + var x = 0; + if (util.lights[p] === 1) { + map[y][x] = marqueeColor; + } + p += 1; + } + // bottom + for (var x = 1; x < width; x++) { + var y = height - 1; + if (util.lights[p] === 1) { + map[y][x] = marqueeColor; + } + p += 1; + } + // right + for (var y = height - 2; y >= 0; y--) { + var x = width - 1; + if (util.lights[p] === 1) { + map[y][x] = marqueeColor; + } + p += 1; + } + // top + for (var x = width - 2; x >= 0; x--) { + var y = 0; + if (util.lights[p] === 1) { + map[y][x] = marqueeColor; + } + p += 1; + } + return map; + }; + + algo.getRawColor = function (rawColors, idx) { + if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { + return rawColors[idx]; + } else { + return 0; + } + } + + algo.rgbMap = function(width, height, rgb, step, rawColors) { + if ( + util.initialized === false || + util.featureColor != algo.getRawColor(rawColors, 0) || + util.width !== width || + util.height !== height + ) { + util.initialize(width, height, rawColors); + } + + var map = util.getNextStep(width, height, rawColors); + return map; + }; + + algo.rgbMapStepCount = function (width, height) { + var size = Number(algo.marqueeCount); + return size + }; + + // Development tool access + testAlgo = algo; + + return algo; +})(); diff --git a/resources/rgbscripts/marquee.js b/resources/rgbscripts/marquee.js index 703ecbfc1a..3cab6d038a 100644 --- a/resources/rgbscripts/marquee.js +++ b/resources/rgbscripts/marquee.js @@ -21,11 +21,59 @@ var testAlgo; (function () { + var colorPalette = new Object(); + colorPalette.collection = new Array( + ["White" , 0xFFFFFF], + ["LightGrey" , 0xAAAAAA], + ["MediumGrey" , 0x999999], + ["DarkGrey" , 0x666666], + ["Cream" , 0xFFFF7F], + ["Pink" , 0xFF7F7F], + ["Rose" , 0x7F3F3F], + ["Coral" , 0x7F3F1F], + ["Dim Red" , 0x7F0000], + ["Red" , 0xFF0000], + ["Orange" , 0xFF3F00], + ["Dim Orange" , 0x7F1F00], + ["Goldenrod" , 0x7F3F00], + ["Gold" , 0xFF7F00], + ["Yellow" , 0xFFFF00], + ["Dim Yellow" , 0x7F7F00], + ["Lime" , 0x7FFF00], + ["Pale Green" , 0x3F7F00], + ["Dim Green" , 0x007F00], + ["Green" , 0x00FF00], + ["Seafoam" , 0x00FF3F], + ["Turquoise" , 0x007F3F], + ["Teal" , 0x007F7F], + ["Cyan" , 0x00FFFF], + ["Electric Blue", 0x007FFF], + ["Blue" , 0x0000FF], + ["Dim Blue" , 0x00007F], + ["Pale Blue" , 0x1F1F7F], + ["Indigo" , 0x1F00BF], + ["Purple" , 0x3F00BF], + ["Violet" , 0x7F007F], + ["Magenta" , 0xFF00FF], + ["Hot Pink" , 0xFF003F], + ["Deep Pink" , 0x7F001F], + ["Black" , 0x000000] + ); + + colorPalette.makeSubArray = function (_index) { + var _array = new Array(); + for (var i = 0; i < colorPalette.collection.length; i++) { + _array.push(colorPalette.collection[i][_index]); + } + return _array; + }; + colorPalette.names = colorPalette.makeSubArray(0); + var algo = new Object(); - algo.apiVersion = 3; + algo.apiVersion = 2; algo.name = "Marquee"; algo.author = "Branson Matheson"; - algo.acceptColors = 2; + algo.acceptColors = 1; algo.properties = new Array(); algo.edgeDepth = 2; algo.properties.push( @@ -39,6 +87,14 @@ var testAlgo; algo.properties.push( "name:marqueeCount|type:range|display:Marquee Spaces|values:1,100|write:setMarqueeCount|read:getMarqueeCount" ); + algo.marqueeColorIndex = 0; + algo.properties.push( + "name:marqueColor|type:list|display:Marquee Light Color|" + + "values:" + + colorPalette.names.toString() + + "|" + + "write:setMarqueeColorIndex|read:getMarqueeColorIndex" + ); var util = new Object(); util.initialized = false; @@ -93,9 +149,18 @@ var testAlgo; return algo.marqueeCount; }; - util.initialize = function (width, height, rawColors) { + algo.setMarqueeColorIndex = function (_preset) { + algo.marqueeColorIndex = colorPalette.names.indexOf(_preset); + util.initialized = false; + }; + + algo.getMarqueeColorIndex = function () { + return colorPalette.collection[algo.marqueeColorIndex][0]; + }; + + util.initialize = function (width, height, rgb) { // initialize feature - util.featureColor = algo.getRawColor(rawColors, 0); + util.featureColor = rgb; util.feature = new Array(); var maxDistance = Math.min(width, height) / 2; for (var y = 0; y < height; y++) { @@ -119,8 +184,6 @@ var testAlgo; if (distance <= algo.edgeDepth && distance <= maxDistance) { var percent = ((algo.edgeDepth - distance) / algo.edgeDepth) * 100; util.feature[y][x] = util.fadeColor(util.featureColor, percent); - } else { - util.feature[y][x] = 0; } } } @@ -157,7 +220,7 @@ var testAlgo; return newRGB; }; - util.getNextStep = function (width, height, rawColors) { + util.getNextStep = function (width, height) { var map = new Array(height); for (var y = 0; y <= height - 1; y++) { map[y] = new Array(width); @@ -177,7 +240,7 @@ var testAlgo; } // create light map add lights, go around the outside - var marqueeColor = algo.getRawColor(rawColors, 1); + var marqueeColor = colorPalette.collection[algo.marqueeColorIndex][1]; var p = 0; // left for (var y = 0; y < height; y++) { @@ -214,25 +277,17 @@ var testAlgo; return map; }; - algo.getRawColor = function (rawColors, idx) { - if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { - return rawColors[idx]; - } else { - return 0; - } - } - - algo.rgbMap = function(width, height, rgb, step, rawColors) { + algo.rgbMap = function (width, height, rgb, step) { if ( util.initialized === false || - util.featureColor != algo.getRawColor(rawColors, 0) || + util.featureColor != rgb || util.width !== width || util.height !== height ) { - util.initialize(width, height, rawColors); + util.initialize(width, height, rgb); } - var map = util.getNextStep(width, height, rawColors); + var map = util.getNextStep(width, height); return map; }; diff --git a/resources/rgbscripts/plasma5colors.js b/resources/rgbscripts/plasma5colors.js new file mode 100644 index 0000000000..38d2510532 --- /dev/null +++ b/resources/rgbscripts/plasma5colors.js @@ -0,0 +1,286 @@ +/* + Q Light Controller Plus + plasma5colors.js + + Copyright (c) Nathan Durnan + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0.txt + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +// Development tool access +var testAlgo; + +( + function() + { + var algo = new Object; + algo.apiVersion = 3; + algo.name = "Plasma (5 Colors)"; + algo.author = "Nathan Durnan"; + algo.acceptColors = 5; + algo.properties = new Array(); + algo.rstepcount = 0; + algo.gstepcount = 50; + algo.bstepcount = 100; + algo.presetSize = 5; + algo.properties.push( + "name:presetSize|type:range|display:Size|" + + "values:1,20|write:setSize|read:getSize"); + algo.ramp = 15; + algo.properties.push( + "name:ramp|type:range|display:Ramp|" + + "values:10,30|write:setRamp|read:getRamp"); + algo.stepsize = 25; + algo.properties.push( + "name:stepsize|type:range|display:Speed|" + + "values:1,50|write:setStep|read:getStep"); + + var util = new Object; + util.initialized = false; + util.gradientData = new Array(); + util.colorArray = new Array(); + + algo.getRawColor = function (rawColors, idx) { + if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { + return rawColors[idx]; + } else { + return 0; + } + } + + algo.setSize = function(_size) + { + algo.presetSize = _size; + util.initialized = false; + }; + + algo.getSize = function() + { + return algo.presetSize; + }; + + algo.setRamp = function(_ramp) + { + algo.ramp = _ramp; + util.initialized = false; + }; + + algo.getRamp = function() + { + return algo.ramp; + }; + + algo.setStep = function(_step) + { + algo.stepsize = _step; + util.initialized = false; + }; + + algo.getStep = function() + { + return algo.stepsize; + }; + + util.initialize = function(rawColors) + { + // Get the colors from the external preset. + for (var i = 0; i < algo.acceptColors; i++) { + util.colorArray[i] = algo.getRawColor(rawColors, i); + } + + // calculate the gradient for the selected preset + // with the given width + var gradIdx = 0; + util.gradientData = new Array(); + for (var i = 0; i < util.colorArray.length; i++) + { + var sColor = util.colorArray[i]; + var eColor = util.colorArray[0]; + if (i < util.colorArray.length - 1) { + eColor = util.colorArray[i + 1]; + } + util.gradientData[gradIdx++] = sColor; + var sr = (sColor >> 16) & 0x00FF; + var sg = (sColor >> 8) & 0x00FF; + var sb = sColor & 0x00FF; + var er = (eColor >> 16) & 0x00FF; + var eg = (eColor >> 8) & 0x00FF; + var eb = eColor & 0x00FF; + + var stepR = ((er - sr) / 300); + var stepG = ((eg - sg) / 300); + var stepB = ((eb - sb) / 300); + + for (var s = 1; s < 300; s++) + { + var gradR = Math.floor(sr + (stepR * s)) & 0x00FF; + var gradG = Math.floor(sg + (stepG * s)) & 0x00FF; + var gradB = Math.floor(sb + (stepB * s)) & 0x00FF; + var gradRGB = (gradR << 16) + (gradG << 8) + gradB; + util.gradientData[gradIdx++] = gradRGB; + } + } + util.initialized = true; + }; + + // This is a port of Ken Perlin's Java code. The + // original Java code is at http://cs.nyu.edu/%7Eperlin/noise/. + // Note that in this version, a number from 0 to 1 is returned. + util.noise = function(x, y, z) + { + var p = new Array(512); + var permutation = [ // 256 members + 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, + 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, + 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, + 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, + 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, + 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, + 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, + 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, + 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, + 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, + 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, + 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, + 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, + 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, + 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, + 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, + 78, 66, 215, 61, 156, 180 + ]; + + // initialize symmetrical permutation array(512) + for (var i = 0; i < 256; i++) { + p[i] = permutation[i]; + p[256 + i] = permutation[i]; + } + // Find unit cube that contains point. + var X = Math.floor(x) & 255; + var Y = Math.floor(y) & 255; + var Z = Math.floor(z) & 255; + // Find relative x,y,z of point in cube. + x -= Math.floor(x); + y -= Math.floor(y); + z -= Math.floor(z); + // Compute fade curves for each of y, y, z + var u = fade(x); + var v = fade(y); + var w = fade(z); + // Hash coordinates of the 8 cube corners, + var A = p[X] + Y; + var AA = p[A] + Z; + var AB = p[A + 1] + Z; + var B = p[X + 1] + Y; + var BA = p[B] + Z; + var BB = p[B + 1] + Z; + + // And add blended results from8 corners of cube + var rawNoise = lerp(w, + lerp(v, lerp(u, grad(p[AA ], x , y , z ), + grad(p[BA ], x-1, y , z )), + lerp(u, grad(p[AB ], x , y - 1, z ), + grad(p[BB ], x-1, y - 1, z ))), + lerp(v, lerp(u, grad(p[AA + 1], x , y , z - 1), + grad(p[BA + 1], x-1, y , z - 1)), + lerp(u, grad(p[AB + 1], x , y - 1, z - 1), + grad(p[BB + 1], x-1, y - 1, z - 1))) + ); + // Scale to range between 0 and 1 + var noise = scale(rawNoise); + return noise; + }; + // Fade function for values between 0 and 1 + function fade(t) + { + // https://www.geogebra.org/calculator + // f(t)=t^(3) (t (t*6-15)+10) + var fade = t * t * t * (t * (t * 6 - 15) + 10); + return fade; + } + // https://en.wikipedia.org/wiki/Linear_interpolation + function lerp(t, a, b) + { + return a + t * (b - a); + } + // https://en.wikipedia.org/wiki/Gradient + function grad(hash, x, y, z) + { + // CONVERT TO 4 BITS OF HASH CODE + var h = hash & 0x0000000f; + // INTO 12 GRADIENT DIRECTIONS. + var u = (h < 8) ? x : y; + var v = (h < 4) ? y : (h === 12 || h === 14) ? x : z; + return (((h & 1) === 0) ? u : -1 * u) + (((h & 2) === 0) ? v : -1 * v); + } + function scale(n) + { + var scaled = (1 + n) / 2; + return scaled; + } + + algo.rgbMap = function(width, height, rgb, step, rawColors) + { + if (util.colorArray.length === 0) { + util.initialized = false; + } else if (util.colorArray.length >= algo.acceptColors - 1 && Array.isArray(rawColors)) { + // Check if the externally provided color has changed. + for (var i = 0; i < Math.min(algo.acceptColors, rawColors.length); i++) { + if (util.colorArray[i] !== rawColors[i]) { + util.initialized = false; + } + } + } + if (util.initialized === false) + { + util.initialize(rawColors); + } + + // set a scaling value + var size = algo.presetSize / 2; + // create a more uniform speed control + var speed = Math.pow(100, (algo.stepsize / 50)); + algo.bstepcount += (speed / 500); + // A rolling step count for the noise function + algo.bstepcount = (algo.bstepcount % 256); + // keep the patten square + var square = (width > height) ? width : height; + + var map = new Array(height); + for (var y = 0; y < height; y++) + { + map[y] = new Array(); + + for (var x = 0; x < width; x++) + { + var nx = x / square; // Normalize nx & ny to 0 - 1 + var ny = y / square; + var n = util.noise(size * nx, size * ny, algo.bstepcount); + var gradStep = Math.round(Math.pow(n, (algo.ramp / 10)) * util.gradientData.length); + map[y][x] = util.gradientData[gradStep]; + } + } + + return map; + }; + + algo.rgbMapStepCount = function(width, height) + { + return 2; // This make no difference to the script ;-) + }; + + // Development tool access + testAlgo = algo; + + return algo; + } +)(); diff --git a/resources/rgbscripts/plasmacolors.js b/resources/rgbscripts/plasmacolors.js index 6cbce6d2e3..168d7d4c5e 100644 --- a/resources/rgbscripts/plasmacolors.js +++ b/resources/rgbscripts/plasmacolors.js @@ -21,254 +21,337 @@ var testAlgo; ( - function() +function() +{ + var colorPalette = new Object; + colorPalette.collection = new Array( + ["White" , 0xFFFFFF], // 0 + ["Cream" , 0xFFFF7F], // 1 + ["Pink" , 0xFF7F7F], // 2 + ["Rose" , 0x7F3F3F], // 3 + ["Coral" , 0x7F3F1F], // 4 + ["Dim Red" , 0x7F0000], // 5 + ["Red" , 0xFF0000], // 6 + ["Orange" , 0xFF3F00], // 7 + ["Dim Orange" , 0x7F1F00], // 8 + ["Goldenrod" , 0x7F3F00], // 9 + ["Gold" , 0xFF7F00], // 10 + ["Yellow" , 0xFFFF00], // 11 + ["Dim Yellow" , 0x7F7F00], // 12 + ["Lime" , 0x7FFF00], // 13 + ["Pale Green" , 0x3F7F00], // 14 + ["Dim Green" , 0x007F00], // 15 + ["Green" , 0x00FF00], // 16 + ["Seafoam" , 0x00FF3F], // 17 + ["Turquoise" , 0x007F3F], // 18 + ["Teal" , 0x007F7F], // 19 + ["Cyan" , 0x00FFFF], // 20 + ["Electric Blue", 0x007FFF], // 21 + ["Blue" , 0x0000FF], // 22 + ["Dim Blue" , 0x00007F], // 23 + ["Pale Blue" , 0x1F1F7F], // 24 + ["Indigo" , 0x1F00BF], // 25 + ["Purple" , 0x3F00BF], // 26 + ["Violet" , 0x7F007F], // 27 + ["Magenta" , 0xFF00FF], // 28 + ["Hot Pink" , 0xFF003F], // 29 + ["Deep Pink" , 0x7F001F], // 30 + ["OFF" , 0x000000]); // 31 + + colorPalette.makeSubArray = function(_index) { - var algo = new Object; - algo.apiVersion = 3; - algo.name = "Plasma (Colors)"; - algo.author = "Nathan Durnan"; - algo.acceptColors = 5; - algo.properties = new Array(); - algo.rstepcount = 0; - algo.gstepcount = 50; - algo.bstepcount = 100; - - var util = new Object; - util.initialized = false; - util.gradientData = new Array(); - util.colorArray = new Array(); + var _array = new Array(); + for (var i = 0; i < colorPalette.collection.length; i++) + { + _array.push(colorPalette.collection[i][_index]); + } + return _array; + }; + colorPalette.names = colorPalette.makeSubArray(0); - algo.getRawColor = function (rawColors, idx) { - if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { - return rawColors[idx]; - } else { - return 0; - } + var algo = new Object; + algo.apiVersion = 2; + algo.name = "Plasma (Colors)"; + algo.author = "Nathan Durnan"; + algo.acceptColors = 0; + algo.properties = new Array(); + algo.rstepcount = 0; + algo.gstepcount = 50; + algo.bstepcount = 100; + algo.color1Index = 0; + algo.properties.push( + "name:color1Index|type:list|display:Color 1|" + + "values:" + colorPalette.names.toString() + "|" + + "write:setColor1|read:getColor1"); + algo.color2Index = 6; + algo.properties.push( + "name:color2Index|type:list|display:Color 2|" + + "values:" + colorPalette.names.toString() + "|" + + "write:setColor2|read:getColor2"); + algo.color3Index = 16; + algo.properties.push( + "name:color3Index|type:list|display:Color 3|" + + "values:" + colorPalette.names.toString() + "|" + + "write:setColor3|read:getColor3"); + algo.color4Index = 22; + algo.properties.push( + "name:color4Index|type:list|display:Color 4|" + + "values:" + colorPalette.names.toString() + "|" + + "write:setColor4|read:getColor4"); + algo.color5Index = 31; + algo.properties.push( + "name:color5Index|type:list|display:Color 5|" + + "values:" + colorPalette.names.toString() + "|" + + "write:setColor5|read:getColor5"); + algo.presetSize = 5; + algo.properties.push( + "name:presetSize|type:range|display:Size|" + + "values:1,20|write:setSize|read:getSize"); + algo.ramp = 15; + algo.properties.push( + "name:ramp|type:range|display:Ramp|" + + "values:10,30|write:setRamp|read:getRamp"); + algo.stepsize = 25; + algo.properties.push( + "name:stepsize|type:range|display:Speed|" + + "values:1,50|write:setStep|read:getStep"); + algo.colorIndex = new Array( + algo.color1Index, + algo.color2Index, + algo.color3Index, + algo.color4Index, + algo.color5Index); + + var util = new Object; + util.initialized = false; + util.gradientData = new Array(); + util.colorArray = new Array(); + + algo.setColor = function(_index, _preset) + { + var i = colorPalette.names.indexOf(_preset); + if (i === -1) { + i = (colorPalette.collection.length - 1); } + algo.colorIndex[_index] = i; + return algo.colorIndex[_index]; + }; - algo.setSize = function(_size) - { - algo.presetSize = _size; - util.initialized = false; - }; + algo.getColor = function(_index) + { + var i = algo.colorIndex[_index]; + if (i < 0) { i = 0; } + if (i >= colorPalette.collection.length) { + i = (colorPalette.collection.length - 1); + } + return colorPalette.collection[i][0]; + }; - algo.getSize = function() - { - return algo.presetSize; - }; + algo.setColor1 = function(_preset) + { + algo.color1Index = algo.setColor(0, _preset); + util.initialize(); + }; + algo.getColor1 = function() + { + return algo.getColor(0); + }; - algo.setRamp = function(_ramp) - { - algo.ramp = _ramp; - util.initialized = false; - }; + algo.setColor2 = function(_preset) + { + algo.color2Index = algo.setColor(1, _preset); + util.initialize(); + }; + algo.getColor2 = function() + { + return algo.getColor(1); + }; - algo.getRamp = function() - { - return algo.ramp; - }; + algo.setColor3 = function(_preset) + { + algo.color3Index = algo.setColor(2, _preset); + util.initialize(); + }; + algo.getColor3 = function() + { + return algo.getColor(2); + }; - algo.setStep = function(_step) - { - algo.stepsize = _step; - util.initialized = false; - }; + algo.setColor4 = function(_preset) + { + algo.color4Index = algo.setColor(3, _preset); + util.initialize(); + }; + algo.getColor4 = function() + { + return algo.getColor(3); + }; - algo.getStep = function() - { - return algo.stepsize; - }; + algo.setColor5 = function(_preset) + { + algo.color5Index = algo.setColor(4, _preset); + util.initialize(); + }; + algo.getColor5 = function() + { + return algo.getColor(4); + }; - util.initialize = function(rawColors) - { - // Get the colors from the external preset. - for (var i = 0; i < algo.acceptColors; i++) { - util.colorArray[i] = algo.getRawColor(rawColors, i); - } + algo.setSize = function(_size) + { + algo.presetSize = _size; + util.initialize(); + }; + algo.getSize = function() + { + return algo.presetSize; + }; - // calculate the gradient for the selected preset - // with the given width - var gradIdx = 0; - util.gradientData = new Array(); - for (var i = 0; i < util.colorArray.length; i++) - { - var sColor = util.colorArray[i]; - var eColor = util.colorArray[0]; - if (i < util.colorArray.length - 1) { - eColor = util.colorArray[i + 1]; - } - util.gradientData[gradIdx++] = sColor; - var sr = (sColor >> 16) & 0x00FF; - var sg = (sColor >> 8) & 0x00FF; - var sb = sColor & 0x00FF; - var er = (eColor >> 16) & 0x00FF; - var eg = (eColor >> 8) & 0x00FF; - var eb = eColor & 0x00FF; - - var stepR = ((er - sr) / 300); - var stepG = ((eg - sg) / 300); - var stepB = ((eb - sb) / 300); - - for (var s = 1; s < 300; s++) - { - var gradR = Math.floor(sr + (stepR * s)) & 0x00FF; - var gradG = Math.floor(sg + (stepG * s)) & 0x00FF; - var gradB = Math.floor(sb + (stepB * s)) & 0x00FF; - var gradRGB = (gradR << 16) + (gradG << 8) + gradB; - util.gradientData[gradIdx++] = gradRGB; - } - } - util.initialized = true; - }; + algo.setRamp = function(_ramp) + { + algo.ramp = _ramp; + util.initialize(); + }; + algo.getRamp = function() + { + return algo.ramp; + }; - // This is a port of Ken Perlin's Java code. The - // original Java code is at http://cs.nyu.edu/%7Eperlin/noise/. - // Note that in this version, a number from 0 to 1 is returned. - util.noise = function(x, y, z) - { - var p = new Array(512); - var permutation = [ // 256 members - 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, - 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, - 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, - 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, - 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, - 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, - 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, - 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, - 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, - 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, - 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, - 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, - 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, - 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, - 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, - 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, - 78, 66, 215, 61, 156, 180 - ]; - - // initialize symmetrical permutation array(512) - for (var i = 0; i < 256; i++) { - p[i] = permutation[i]; - p[256 + i] = permutation[i]; - } - // Find unit cube that contains point. - var X = Math.floor(x) & 255; - var Y = Math.floor(y) & 255; - var Z = Math.floor(z) & 255; - // Find relative x,y,z of point in cube. - x -= Math.floor(x); - y -= Math.floor(y); - z -= Math.floor(z); - // Compute fade curves for each of y, y, z - var u = fade(x); - var v = fade(y); - var w = fade(z); - // Hash coordinates of the 8 cube corners, - var A = p[X] + Y; - var AA = p[A] + Z; - var AB = p[A + 1] + Z; - var B = p[X + 1] + Y; - var BA = p[B] + Z; - var BB = p[B + 1] + Z; - - // And add blended results from8 corners of cube - var rawNoise = lerp(w, - lerp(v, lerp(u, grad(p[AA ], x , y , z ), - grad(p[BA ], x-1, y , z )), - lerp(u, grad(p[AB ], x , y - 1, z ), - grad(p[BB ], x-1, y - 1, z ))), - lerp(v, lerp(u, grad(p[AA + 1], x , y , z - 1), - grad(p[BA + 1], x-1, y , z - 1)), - lerp(u, grad(p[AB + 1], x , y - 1, z - 1), - grad(p[BB + 1], x-1, y - 1, z - 1))) - ); - // Scale to range between 0 and 1 - var noise = scale(rawNoise); - return noise; - }; - // Fade function for values between 0 and 1 - function fade(t) + algo.setStep = function(_step) + { + algo.stepsize = _step; + util.initialize(); + }; + algo.getStep = function() + { + return algo.stepsize; + }; + + util.initialize = function() + { + // calculate the gradient for the selected preset + // with the given width + var gradIdx = 0; + util.gradientData = new Array(); + util.colorArray = new Array(); + for (var j = 0; j < algo.colorIndex.length; j++) { - // https://www.geogebra.org/calculator - // f(t)=t^(3) (t (t*6-15)+10) - var fade = t * t * t * (t * (t * 6 - 15) + 10); - return fade; + util.colorArray[j] = colorPalette.collection[algo.colorIndex[j]][1]; } - // https://en.wikipedia.org/wiki/Linear_interpolation - function lerp(t, a, b) + for (var i = 0; i < util.colorArray.length; i++) { - return a + t * (b - a); + var sColor = util.colorArray[i]; + var eColor = util.colorArray[i + 1]; + if (eColor == undefined) { + eColor = util.colorArray[0]; + } + util.gradientData[gradIdx++] = sColor; + var sr = (sColor >> 16) & 0x00FF; + var sg = (sColor >> 8) & 0x00FF; + var sb = sColor & 0x00FF; + var er = (eColor >> 16) & 0x00FF; + var eg = (eColor >> 8) & 0x00FF; + var eb = eColor & 0x00FF; + + var stepR = ((er - sr) / 300); + var stepG = ((eg - sg) / 300); + var stepB = ((eb - sb) / 300); + + for (var s = 1; s < 300; s++) + { + var gradR = Math.floor(sr + (stepR * s)) & 0x00FF; + var gradG = Math.floor(sg + (stepG * s)) & 0x00FF; + var gradB = Math.floor(sb + (stepB * s)) & 0x00FF; + var gradRGB = (gradR << 16) + (gradG << 8) + gradB; + util.gradientData[gradIdx++] = gradRGB; + } } - // https://en.wikipedia.org/wiki/Gradient - function grad(hash, x, y, z) - { - // CONVERT TO 4 BITS OF HASH CODE - var h = hash & 0x0000000f; - // INTO 12 GRADIENT DIRECTIONS. - var u = (h < 8) ? x : y; - var v = (h < 4) ? y : (h === 12 || h === 14) ? x : z; - return (((h & 1) === 0) ? u : -1 * u) + (((h & 2) === 0) ? v : -1 * v); + util.initialized = true; + }; + + function fade(t) { return t * t * t * (t * (t * 6 - 15) + 10); } + function lerp( t, a, b) { return a + t * (b - a); } + function grad(hash, x, y, z) { + var h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE + var u = h<8 ? x : y, // INTO 12 GRADIENT DIRECTIONS. + v = h<4 ? y : h===12||h===14 ? x : z; + return ((h&1) === 0 ? u : -u) + ((h&2) === 0 ? v : -v); + } + function scale(n) { return (1 + n)/2; } + + // This is a port of Ken Perlin's Java code. The + // original Java code is at http://cs.nyu.edu/%7Eperlin/noise/. + // Note that in this version, a number from 0 to 1 is returned. + util.noise = function(x, y, z) + { + var p = new Array(512); + var permutation = [ 151,160,137,91,90,15,131,13,201,95,96,53,194,233, 7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190, 6,148,247,120,234,75, 0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20, 125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229, 122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54, 65,25,63,161,1, 216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100, 109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212, 207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152, 2,44,154, 163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232, 178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,49,192,214, 31,181,199,106,157,184, 84,204,176,115, 121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180]; + + for (var i=0; i < 256 ; i++) { + p[256+i] = p[i] = permutation[i]; } - function scale(n) - { - var scaled = (1 + n) / 2; - return scaled; + var X = Math.floor(x) & 255, // FIND UNIT CUBE THAT + Y = Math.floor(y) & 255, // CONTAINS POINT. + Z = Math.floor(z) & 255; + x -= Math.floor(x); // FIND RELATIVE X,Y,Z + y -= Math.floor(y); // OF POINT IN CUBE. + z -= Math.floor(z); + var u = fade(x), // COMPUTE FADE CURVES + v = fade(y), // FOR EACH OF X,Y,Z. + w = fade(z); + var A = p[X ]+Y, AA = p[A]+Z, AB = p[A+1]+Z, // HASH COORDINATES OF + B = p[X+1]+Y, BA = p[B]+Z, BB = p[B+1]+Z; // THE 8 CUBE CORNERS, + + return scale(lerp(w, lerp(v, lerp(u, grad(p[AA ], x , y , z ), // AND ADD + grad(p[BA ], x-1, y , z )), // BLENDED + lerp(u, grad(p[AB ], x , y-1, z ), // RESULTS + grad(p[BB ], x-1, y-1, z ))), // FROM 8 + lerp(v, lerp(u, grad(p[AA+1], x , y , z-1 ), // CORNERS + grad(p[BA+1], x-1, y , z-1 )), // OF CUBE + lerp(u, grad(p[AB+1], x , y-1, z-1 ), + grad(p[BB+1], x-1, y-1, z-1 ))))); + }; + + algo.rgbMap = function(width, height, rgb, step) + { + if (util.initialized === false) { + util.initialize(); } + var size = algo.presetSize/2; // set a scaling value + var speed = Math.pow(100 , (algo.stepsize / 50)); // create a more uniform speed control + algo.bstepcount += (speed / 500); + algo.bstepcount = (algo.bstepcount % 256); // A rolling step count for the noise function + var square = width>height ? width : height; // keep the patten square - algo.rgbMap = function(width, height, rgb, step, rawColors) + var map = new Array(height); + for (var y = 0; y < height; y++) { - if (util.colorArray.length === 0) { - util.initialized = false; - } else if (util.colorArray.length >= algo.acceptColors - 1 && Array.isArray(rawColors)) { - // Check if the externally provided color has changed. - for (var i = 0; i < Math.min(algo.acceptColors, rawColors.length); i++) { - if (util.colorArray[i] !== rawColors[i]) { - util.initialized = false; - } - } - } - if (util.initialized === false) - { - util.initialize(rawColors); - } + map[y] = new Array(); - // set a scaling value - var size = algo.presetSize / 2; - // create a more uniform speed control - var speed = Math.pow(100, (algo.stepsize / 50)); - algo.bstepcount += (speed / 500); - // A rolling step count for the noise function - algo.bstepcount = (algo.bstepcount % 256); - // keep the patten square - var square = (width > height) ? width : height; - - var map = new Array(height); - for (var y = 0; y < height; y++) + for (var x = 0; x < width; x++) { - map[y] = new Array(); - - for (var x = 0; x < width; x++) - { - var nx = x / square; // Normalize nx & ny to 0 - 1 - var ny = y / square; - var n = util.noise(size * nx, size * ny, algo.bstepcount); - var gradStep = Math.round(Math.pow(n, (algo.ramp / 10)) * util.gradientData.length); - map[y][x] = util.gradientData[gradStep]; - } + var nx = x / square; // Normalize nx & ny to 0 - 1 + var ny = y / square; + var n = util.noise( size*nx, size*ny, algo.bstepcount); + var gradStep = Math.round( Math.pow(n , (algo.ramp/10)) * util.gradientData.length); + map[y][x] = util.gradientData[gradStep]; } + } - return map; - }; + return map; + }; - algo.rgbMapStepCount = function(width, height) - { - return 2; // This make no difference to the script ;-) - }; + algo.rgbMapStepCount = function(width, height) + { + if (util.initialized === false) { + util.initialize(); + } + return width * height; // This make no difference to the script ;-) + }; - // Development tool access - testAlgo = algo; + // Development tool access + testAlgo = algo; - return algo; - } + return algo; +} )(); diff --git a/resources/rgbscripts/rgbscripts.pro b/resources/rgbscripts/rgbscripts.pro index 39f921f400..aecf34d47d 100644 --- a/resources/rgbscripts/rgbscripts.pro +++ b/resources/rgbscripts/rgbscripts.pro @@ -4,8 +4,10 @@ TEMPLATE = subdirs TARGET = scripts scripts.files += alternate.js +scripts.files += alternate-2colors.js scripts.files += balls.js scripts.files += ballscolors.js +scripts.files += balls5colors.js scripts.files += blinder.js scripts.files += circles.js scripts.files += circular.js @@ -20,11 +22,13 @@ scripts.files += flyingobjects.js scripts.files += gradient.js scripts.files += lines.js scripts.files += marquee.js +scripts.files += marquee-2colors.js scripts.files += noise.js scripts.files += onebyone.js scripts.files += opposite.js scripts.files += plasma.js scripts.files += plasmacolors.js +scripts.files += plasma5colors.js scripts.files += randomcolumn.js scripts.files += randomfillcolumn.js scripts.files += randomfillrow.js From dbdb3633e2c4d832e62c4371d8f349a9056c0892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Tue, 26 Mar 2024 12:48:01 +0100 Subject: [PATCH 38/63] Fix the VC UI matrix properties layout to 5-color scheme. --- ui/src/virtualconsole/vcmatrixproperties.ui | 170 ++++++++++---------- 1 file changed, 85 insertions(+), 85 deletions(-) diff --git a/ui/src/virtualconsole/vcmatrixproperties.ui b/ui/src/virtualconsole/vcmatrixproperties.ui index 1d99dbc075..3b9591c3b7 100644 --- a/ui/src/virtualconsole/vcmatrixproperties.ui +++ b/ui/src/virtualconsole/vcmatrixproperties.ui @@ -296,32 +296,41 @@ - - - - Add color 2 knobs + + + + false - - - :/knob.png:/knob.png + + false + + + Type + + + + + Value + + - - + + - Add color 3 knobs + Add color 1 - :/knob.png:/knob.png + :/color.png:/color.png - - + + - Add color 4 knobs + Add color 1 knobs @@ -329,77 +338,65 @@ - - + + - Add color 5 knobs + Add color 1 - :/knob.png:/knob.png + :/color.png:/color.png - - - - false + + + + Add color 2 knobs - - false + + + :/knob.png:/knob.png - - - Type - - - - - Value - - - - + + - Add preset + Add color 2 reset - :/script.png:/script.png + :/fileclose.png:/fileclose.png - - + + - Add text + Add color 3 - :/fonts.png:/fonts.png + :/color.png:/color.png - - - - - + + - Add end color reset + Add color 3 knobs - :/fileclose.png:/fileclose.png + :/knob.png:/knob.png - + - Add end color reset + Add color 3 reset @@ -407,43 +404,43 @@ - - + + - Add end color reset + Add color 4 - :/fileclose.png:/fileclose.png + :/color.png:/color.png - - + + - Add end color reset + Add color 4 knobs - :/fileclose.png:/fileclose.png + :/knob.png:/knob.png - - + + - Remove + Add color 4 reset - :/edit_remove.png:/edit_remove.png + :/fileclose.png:/fileclose.png - - + + - Add start color + Add color 5 @@ -451,10 +448,10 @@ - - + + - Add start color knobs + Add color 5 knobs @@ -462,50 +459,53 @@ - - + + - Add end color + Add color 5 reset - :/color.png:/color.png + :/fileclose.png:/fileclose.png - - + + - Add end color + Add preset - :/color.png:/color.png + :/script.png:/script.png - - + + - Add end color + Add text - :/color.png:/color.png + :/fonts.png:/fonts.png - - + + - Add end color + Remove - :/color.png:/color.png + :/edit_remove.png:/edit_remove.png + + + From 34f746340e6b6996b96dc46d1e4e589a055d7ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Tue, 26 Mar 2024 19:07:33 +0100 Subject: [PATCH 39/63] Modify file names to exclude numbers. --- resources/rgbscripts/CMakeLists.txt | 8 ++++---- .../{alternate-2colors.js => alternatecolorsdirect.js} | 2 +- .../rgbscripts/{balls5colors.js => ballscolorsdirect.js} | 0 .../{marquee-2colors.js => marqueecolorsdirect.js} | 2 +- .../{plasma5colors.js => plasmacolorsdirect.js} | 0 resources/rgbscripts/rgbscripts.pro | 8 ++++---- 6 files changed, 10 insertions(+), 10 deletions(-) rename resources/rgbscripts/{alternate-2colors.js => alternatecolorsdirect.js} (99%) rename resources/rgbscripts/{balls5colors.js => ballscolorsdirect.js} (100%) rename resources/rgbscripts/{marquee-2colors.js => marqueecolorsdirect.js} (99%) rename resources/rgbscripts/{plasma5colors.js => plasmacolorsdirect.js} (100%) diff --git a/resources/rgbscripts/CMakeLists.txt b/resources/rgbscripts/CMakeLists.txt index 276d247554..b30ac1a806 100644 --- a/resources/rgbscripts/CMakeLists.txt +++ b/resources/rgbscripts/CMakeLists.txt @@ -2,10 +2,10 @@ project(scripts) set(SCRIPT_FILES alternate.js - alternate-2colors.js + alternatecolorsdirect.js balls.js ballscolors.js - balls5colors.js + ballscolorsdirect.js blinder.js circles.js circular.js @@ -20,13 +20,13 @@ set(SCRIPT_FILES gradient.js lines.js marquee.js - marquee-2colors.js + marqueecolorsdirect.js noise.js onebyone.js opposite.js plasma.js plasmacolors.js - plasma5colors.js + plasmacolorsdirect.js randomcolumn.js randomfillcolumn.js randomfillrow.js diff --git a/resources/rgbscripts/alternate-2colors.js b/resources/rgbscripts/alternatecolorsdirect.js similarity index 99% rename from resources/rgbscripts/alternate-2colors.js rename to resources/rgbscripts/alternatecolorsdirect.js index fa359e5864..02f4ff6683 100644 --- a/resources/rgbscripts/alternate-2colors.js +++ b/resources/rgbscripts/alternatecolorsdirect.js @@ -1,6 +1,6 @@ /* Q Light Controller Plus - alternate-2colors.js + alternate2colors.js Copyright (c) Hans-Jürgen Tappe diff --git a/resources/rgbscripts/balls5colors.js b/resources/rgbscripts/ballscolorsdirect.js similarity index 100% rename from resources/rgbscripts/balls5colors.js rename to resources/rgbscripts/ballscolorsdirect.js diff --git a/resources/rgbscripts/marquee-2colors.js b/resources/rgbscripts/marqueecolorsdirect.js similarity index 99% rename from resources/rgbscripts/marquee-2colors.js rename to resources/rgbscripts/marqueecolorsdirect.js index c59b6762fe..55f9d21000 100644 --- a/resources/rgbscripts/marquee-2colors.js +++ b/resources/rgbscripts/marqueecolorsdirect.js @@ -1,6 +1,6 @@ /* Q Light Controller Plus - marquee-2colors.js + marquee2colors.js Copyright (c) Branson Matheson diff --git a/resources/rgbscripts/plasma5colors.js b/resources/rgbscripts/plasmacolorsdirect.js similarity index 100% rename from resources/rgbscripts/plasma5colors.js rename to resources/rgbscripts/plasmacolorsdirect.js diff --git a/resources/rgbscripts/rgbscripts.pro b/resources/rgbscripts/rgbscripts.pro index aecf34d47d..454c49cf9d 100644 --- a/resources/rgbscripts/rgbscripts.pro +++ b/resources/rgbscripts/rgbscripts.pro @@ -4,10 +4,10 @@ TEMPLATE = subdirs TARGET = scripts scripts.files += alternate.js -scripts.files += alternate-2colors.js +scripts.files += alternatecolorsdirect.js scripts.files += balls.js scripts.files += ballscolors.js -scripts.files += balls5colors.js +scripts.files += ballscolorsdirect.js scripts.files += blinder.js scripts.files += circles.js scripts.files += circular.js @@ -22,13 +22,13 @@ scripts.files += flyingobjects.js scripts.files += gradient.js scripts.files += lines.js scripts.files += marquee.js -scripts.files += marquee-2colors.js +scripts.files += marqueecolorsdirect.js scripts.files += noise.js scripts.files += onebyone.js scripts.files += opposite.js scripts.files += plasma.js scripts.files += plasmacolors.js -scripts.files += plasma5colors.js +scripts.files += plasmacolorsdirect.js scripts.files += randomcolumn.js scripts.files += randomfillcolumn.js scripts.files += randomfillrow.js From 9870df2c8fac14a232f4ca69098f9d139c234378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Fri, 24 May 2024 17:34:16 +0200 Subject: [PATCH 40/63] Fix typo. --- ui/src/virtualconsole/vcmatrixproperties.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/virtualconsole/vcmatrixproperties.ui b/ui/src/virtualconsole/vcmatrixproperties.ui index 3b9591c3b7..627a2e2692 100644 --- a/ui/src/virtualconsole/vcmatrixproperties.ui +++ b/ui/src/virtualconsole/vcmatrixproperties.ui @@ -341,7 +341,7 @@ - Add color 1 + Add color 2 From 8b0046d03d655c64aaf82b0ca084fdd7a690310b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Sun, 26 May 2024 12:07:28 +0200 Subject: [PATCH 41/63] Align color pickers in matrix editor --- ui/src/rgbmatrixeditor.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/rgbmatrixeditor.ui b/ui/src/rgbmatrixeditor.ui index 45037d0097..d966295e3d 100644 --- a/ui/src/rgbmatrixeditor.ui +++ b/ui/src/rgbmatrixeditor.ui @@ -370,7 +370,7 @@ - + Matrix color 1 From 8bda20e9f2679890d17aeb52a7d3df866d8d943c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Wed, 5 Jun 2024 21:03:41 +0200 Subject: [PATCH 42/63] Remplace static array with dynamic QVector. --- engine/src/rgbalgorithm.cpp | 24 ++--- engine/src/rgbalgorithm.h | 10 +- engine/src/rgbaudio.cpp | 4 +- engine/src/rgbaudio.h | 4 +- engine/src/rgbimage.cpp | 2 +- engine/src/rgbimage.h | 2 +- engine/src/rgbmatrix.cpp | 122 +++++++++++------------ engine/src/rgbmatrix.h | 7 +- engine/src/rgbplain.cpp | 4 +- engine/src/rgbplain.h | 4 +- engine/src/rgbscript.cpp | 11 +- engine/src/rgbscript.h | 2 +- engine/src/rgbscriptv4.cpp | 10 +- engine/src/rgbscriptv4.h | 2 +- engine/src/rgbtext.cpp | 2 +- engine/src/rgbtext.h | 2 +- engine/test/rgbscript/rgbscript_test.cpp | 8 +- engine/test/rgbtext/rgbtext_test.cpp | 6 +- qmlui/rgbmatrixeditor.cpp | 4 +- ui/src/rgbmatrixeditor.cpp | 5 +- 20 files changed, 117 insertions(+), 118 deletions(-) diff --git a/engine/src/rgbalgorithm.cpp b/engine/src/rgbalgorithm.cpp index a7151aa961..3b87ef052d 100644 --- a/engine/src/rgbalgorithm.cpp +++ b/engine/src/rgbalgorithm.cpp @@ -40,26 +40,22 @@ RGBAlgorithm::RGBAlgorithm(Doc * doc) : m_doc(doc) { - Q_ASSERT(5 == RGBAlgorithmRawColorCount); - m_colors[0] = QColor(); - m_colors[1] = QColor(); - m_colors[2] = QColor(); - m_colors[3] = QColor(); - m_colors[4] = QColor(); } -void RGBAlgorithm::setColors(QColor colors[RGBAlgorithmRawColorCount]) +void RGBAlgorithm::setColors(QVector colors) { - for (int i = 0; i < RGBAlgorithmRawColorCount; i++) - { - if (acceptColors() <= i) - m_colors[i] = colors[i]; - else - m_colors[i] = QColor(); + m_colors.clear(); + QVectorIterator it(colors); + int count = 0; + while (it.hasNext()) { + QColor color = it.next(); + if (acceptColors() < count) + m_colors.append(color); + count ++; } } -QColor RGBAlgorithm::getColor(unsigned int i) const +QColor RGBAlgorithm::getColor(uint i) const { return m_colors[i]; } diff --git a/engine/src/rgbalgorithm.h b/engine/src/rgbalgorithm.h index 566458e886..ac8f3adf5c 100644 --- a/engine/src/rgbalgorithm.h +++ b/engine/src/rgbalgorithm.h @@ -40,7 +40,7 @@ typedef QVector > RGBMap; #define KXMLQLCRGBAlgorithm QString("Algorithm") #define KXMLQLCRGBAlgorithmType QString("Type") -#define RGBAlgorithmRawColorCount 5 +#define RGBAlgorithmColorDisplayCount 5 class RGBAlgorithm { @@ -76,7 +76,7 @@ class RGBAlgorithm /** Load a RGBMap for the given step. */ virtual void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, - uint (&rawColors)[RGBAlgorithmRawColorCount]) = 0; + QVector &rawColors) = 0; /** Release resources that may have been acquired in rgbMap() */ virtual void postRun() {} @@ -105,13 +105,13 @@ class RGBAlgorithm ************************************************************************/ public: /** Set the colors the algorithm can use */ - virtual void setColors(QColor[RGBAlgorithmRawColorCount]); + virtual void setColors(QVector); /** Get the color which is set for the algorithm */ - virtual QColor getColor(unsigned int i) const; + virtual QColor getColor(uint i) const; private: - QColor m_colors[RGBAlgorithmRawColorCount]; + QVector m_colors; /************************************************************************ * Available algorithms diff --git a/engine/src/rgbaudio.cpp b/engine/src/rgbaudio.cpp index d531a168c8..5c43457626 100644 --- a/engine/src/rgbaudio.cpp +++ b/engine/src/rgbaudio.cpp @@ -123,7 +123,7 @@ int RGBAudio::rgbMapStepCount(const QSize& size) return 1; } -void RGBAudio::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]) +void RGBAudio::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors) { Q_UNUSED(step); Q_UNUSED(rawColors); @@ -206,7 +206,7 @@ int RGBAudio::apiVersion() const return 1; } -void RGBAudio::setColors(QColor colors[RGBAlgorithmRawColorCount]) +void RGBAudio::setColors(QVector colors) { RGBAlgorithm::setColors(colors); diff --git a/engine/src/rgbaudio.h b/engine/src/rgbaudio.h index 39f0adb1a3..cb783cbd70 100644 --- a/engine/src/rgbaudio.h +++ b/engine/src/rgbaudio.h @@ -71,7 +71,7 @@ protected slots: int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors); /** @reimp */ virtual void postRun(); @@ -86,7 +86,7 @@ protected slots: int apiVersion() const; /** @reimp */ - void setColors(QColor colors[RGBAlgorithmRawColorCount]); + void setColors(QVector colors); /** @reimp */ RGBAlgorithm::Type type() const; diff --git a/engine/src/rgbimage.cpp b/engine/src/rgbimage.cpp index 97077a7cc8..a42e3fc8e4 100644 --- a/engine/src/rgbimage.cpp +++ b/engine/src/rgbimage.cpp @@ -235,7 +235,7 @@ int RGBImage::rgbMapStepCount(const QSize& size) } } -void RGBImage::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]) +void RGBImage::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors) { Q_UNUSED(rgb); Q_UNUSED(rawColors); diff --git a/engine/src/rgbimage.h b/engine/src/rgbimage.h index 226967a61a..fce605507e 100644 --- a/engine/src/rgbimage.h +++ b/engine/src/rgbimage.h @@ -103,7 +103,7 @@ class RGBImage : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors); /** @reimp */ QString name() const; diff --git a/engine/src/rgbmatrix.cpp b/engine/src/rgbmatrix.cpp index 4f60026d2c..c929a14777 100644 --- a/engine/src/rgbmatrix.cpp +++ b/engine/src/rgbmatrix.cpp @@ -36,11 +36,7 @@ #define KXMLQLCRGBMatrixStartColor QString("MonoColor") #define KXMLQLCRGBMatrixEndColor QString("EndColor") -#define KXMLQLCRGBMatrixColor1 QString("Color1") -#define KXMLQLCRGBMatrixColor2 QString("Color2") -#define KXMLQLCRGBMatrixColor3 QString("Color3") -#define KXMLQLCRGBMatrixColor4 QString("Color4") -#define KXMLQLCRGBMatrixColor5 QString("Color5") +#define KXMLQLCRGBMatrixColorBase QString("Color") #define KXMLQLCRGBMatrixFixtureGroup QString("FixtureGroup") #define KXMLQLCRGBMatrixDimmerControl QString("DimmerControl") @@ -178,8 +174,14 @@ bool RGBMatrix::copyFrom(const Function* function) else setAlgorithm(NULL); - for(unsigned int i = 0; i < RGBAlgorithmRawColorCount; i++) - setColor(i, mtx->getColor(i)); + QVectorIterator it(mtx->getColors()); + uint count = 0; + while (it.hasNext()) { + QColor color = it.next(); + setColor(count, color); + count ++; + } + setControlMode(mtx->controlMode()); return Function::copyFrom(function); @@ -289,13 +291,15 @@ void RGBMatrix::previewMap(int step, RGBMatrixStep *handler) m_group = doc()->fixtureGroup(fixtureGroup()); if (m_group != NULL) { - Q_ASSERT(5 == RGBAlgorithmRawColorCount); - uint rawColors[] = { - m_rgbColors[0].rgb() - ,m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0 - ,m_rgbColors[2].isValid() ? m_rgbColors[2].rgb() : 0 - ,m_rgbColors[3].isValid() ? m_rgbColors[3].rgb() : 0 - ,m_rgbColors[4].isValid() ? m_rgbColors[4].rgb() : 0 + int accColors = m_algorithm->acceptColors(); + QVector rawColors; + rawColors.resize(accColors); + QVectorIterator it(m_rgbColors); + int count = 0; + while (it.hasNext() && count < accColors) { + QColor color = it.next(); + rawColors.replace(count, color.isValid() ? color.rgb() : 0); + count ++; }; m_algorithm->rgbMap(m_group->size(), handler->stepColor().rgb(), step, handler->m_map, rawColors); } @@ -305,25 +309,32 @@ void RGBMatrix::previewMap(int step, RGBMatrixStep *handler) * Color ****************************************************************************/ -void RGBMatrix::setColor(unsigned int i, QColor c) +void RGBMatrix::setColor(int i, QColor c) { - if (i >= RGBAlgorithmRawColorCount) - return; - m_rgbColors[i] = c; + if (i >= m_rgbColors.count()) + m_rgbColors.resize(i + 1); + m_rgbColors.replace(i, c); { QMutexLocker algorithmLocker(&m_algorithmMutex); if (m_algorithm != NULL) { - m_algorithm->setColors(&m_rgbColors[0]); + m_algorithm->setColors(m_rgbColors); updateColorDelta(); } } emit changed(id()); } -QColor RGBMatrix::getColor(unsigned int i) const +QColor RGBMatrix::getColor(int i) const +{ + if (i >= m_rgbColors.count()) + return QColor(); + return m_rgbColors.at(i); +} + +QVector RGBMatrix::getColors() const { - return m_rgbColors[i]; + return m_rgbColors; } void RGBMatrix::updateColorDelta() @@ -406,30 +417,21 @@ bool RGBMatrix::loadXML(QXmlStreamReader &root) { loadXMLRunOrder(root); } -#if (5 != RGBAlgorithmRawColorCount) -#error "Further colors need to be read." -#endif - else if (root.name() == KXMLQLCRGBMatrixStartColor - || root.name() == KXMLQLCRGBMatrixColor1) + // Legacy support + else if (root.name() == KXMLQLCRGBMatrixStartColor) { setColor(0, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); } - else if (root.name() == KXMLQLCRGBMatrixEndColor - || root.name() == KXMLQLCRGBMatrixColor2) + else if (root.name() == KXMLQLCRGBMatrixEndColor) { setColor(1, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); } - else if (root.name() == KXMLQLCRGBMatrixColor3) - { - setColor(2, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); - } - else if (root.name() == KXMLQLCRGBMatrixColor4) - { - setColor(3, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); - } - else if (root.name() == KXMLQLCRGBMatrixColor5) + else if (root.name().startsWith(KXMLQLCRGBMatrixColorBase, Qt::CaseSensitive)) { - setColor(4, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); + QString colorNumText = root.name().string()->right( + root.name().length() - KXMLQLCRGBMatrixColorBase.length()); + uint colorNum = colorNumText.toUInt(); + setColor(colorNum, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); } else if (root.name() == KXMLQLCRGBMatrixControlMode) { @@ -483,25 +485,15 @@ bool RGBMatrix::saveXML(QXmlStreamWriter *doc) if (dimmerControl()) doc->writeTextElement(KXMLQLCRGBMatrixDimmerControl, QString::number(dimmerControl())); - /* Color 1 */ - doc->writeTextElement(KXMLQLCRGBMatrixColor1, QString::number(getColor(0).rgb())); - - /* Color 2 */ - if (getColor(1).isValid()) - doc->writeTextElement(KXMLQLCRGBMatrixColor2, QString::number(getColor(1).rgb())); - - /* Color 2 */ - if (getColor(2).isValid()) - doc->writeTextElement(KXMLQLCRGBMatrixColor3, QString::number(getColor(2).rgb())); - - /* Color 2 */ - if (getColor(3).isValid()) - doc->writeTextElement(KXMLQLCRGBMatrixColor4, QString::number(getColor(3).rgb())); - - /* Color 5 */ - if (getColor(4).isValid()) - doc->writeTextElement(KXMLQLCRGBMatrixColor5, QString::number(getColor(4).rgb())); - Q_ASSERT(5 == RGBAlgorithmRawColorCount); + /* Colors */ + QVectorIterator colorIt(m_rgbColors); + uint count = 0; + while (colorIt.hasNext()) { + QColor color = colorIt.next(); + QString elementName = KXMLQLCRGBMatrixColorBase.append(QString::number(count)); + doc->writeTextElement(elementName, QString::number(color.rgb())); + count ++; + } /* Control Mode */ doc->writeTextElement(KXMLQLCRGBMatrixControlMode, RGBMatrix::controlModeToString(m_controlMode)); @@ -609,13 +601,15 @@ void RGBMatrix::write(MasterTimer *timer, QList universes) if (tempoType() == Beats) m_stepBeatDuration = beatsToTime(duration(), timer->beatTimeDuration()); - Q_ASSERT(5 == RGBAlgorithmRawColorCount); - uint rawColors[] = { - m_rgbColors[0].rgb() - ,m_rgbColors[1].isValid() ? m_rgbColors[1].rgb() : 0 - ,m_rgbColors[2].isValid() ? m_rgbColors[2].rgb() : 0 - ,m_rgbColors[3].isValid() ? m_rgbColors[3].rgb() : 0 - ,m_rgbColors[4].isValid() ? m_rgbColors[4].rgb() : 0 + int accColors = m_algorithm->acceptColors(); + QVector rawColors; + rawColors.resize(accColors); + QVectorIterator it(m_rgbColors); + int count = 0; + while (it.hasNext() && count < accColors) { + QColor color = it.next(); + rawColors.replace(count, color.isValid() ? color.rgb() : 0); + count ++; }; //qDebug() << "RGBMatrix step" << m_stepHandler->currentStepIndex() << ", color:" << QString::number(m_stepHandler->stepColor().rgb(), 16); m_algorithm->rgbMap(m_group->size(), m_stepHandler->stepColor().rgb(), diff --git a/engine/src/rgbmatrix.h b/engine/src/rgbmatrix.h index aa259b00e9..ebfa989f25 100644 --- a/engine/src/rgbmatrix.h +++ b/engine/src/rgbmatrix.h @@ -188,13 +188,14 @@ class RGBMatrix : public Function * Color ************************************************************************/ public: - void setColor(unsigned int i, QColor c); - QColor getColor(unsigned int i) const; + void setColor(int i, QColor c); + QColor getColor(int i) const; + QVector getColors() const; void updateColorDelta(); private: - QColor m_rgbColors[RGBAlgorithmRawColorCount]; + QVector m_rgbColors; RGBMatrixStep *m_stepHandler; /************************************************************************ diff --git a/engine/src/rgbplain.cpp b/engine/src/rgbplain.cpp index f23c114785..3a1dd1b842 100644 --- a/engine/src/rgbplain.cpp +++ b/engine/src/rgbplain.cpp @@ -55,7 +55,7 @@ int RGBPlain::rgbMapStepCount(const QSize& size) return 1; } -void RGBPlain::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]) +void RGBPlain::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors) { Q_UNUSED(step); Q_UNUSED(rawColors); @@ -82,7 +82,7 @@ int RGBPlain::apiVersion() const return 1; } -void RGBPlain::setColors(QColor colors[RGBAlgorithmRawColorCount]) +void RGBPlain::setColors(QVector colors) { RGBAlgorithm::setColors(colors); } diff --git a/engine/src/rgbplain.h b/engine/src/rgbplain.h index 0aea97180d..a2d88116c9 100644 --- a/engine/src/rgbplain.h +++ b/engine/src/rgbplain.h @@ -50,7 +50,7 @@ class RGBPlain : public QObject, public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors); /** @reimp */ QString name() const; @@ -62,7 +62,7 @@ class RGBPlain : public QObject, public RGBAlgorithm int apiVersion() const; /** @reimp */ - void setColors(QColor colors[RGBAlgorithmRawColorCount]); + void setColors(QVector colors); /** @reimp */ RGBAlgorithm::Type type() const; diff --git a/engine/src/rgbscript.cpp b/engine/src/rgbscript.cpp index a9f4b91278..9edad258fc 100644 --- a/engine/src/rgbscript.cpp +++ b/engine/src/rgbscript.cpp @@ -249,7 +249,7 @@ int RGBScript::rgbMapStepCount(const QSize& size) } } -void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]) +void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors) { QMutexLocker engineLocker(s_engineMutex); @@ -260,10 +260,13 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint if (m_apiVersion <= 2) { args << size.width() << size.height() << rgb << step; } else { - QScriptValue jsRawColors = s_engine->newArray(RGBAlgorithmRawColorCount); - for (int i = 0; i < RGBAlgorithmRawColorCount; i++) { - jsRawColors.setProperty(i, QScriptValue(rawColors[i])); + int accColors = acceptColors(); + int rawColorCount = rawColors.count(); + QScriptValue jsRawColors = s_engine->newArray(accColors); + for (int i = 0; i < rawColorCount && i < accColors; i++) { + jsRawColors.setProperty(i, QScriptValue(rawColors.at(i))); } + args << size.width() << size.height() << rgb << step << jsRawColors; } QScriptValue yarray = m_rgbMap.call(QScriptValue(), args); diff --git a/engine/src/rgbscript.h b/engine/src/rgbscript.h index 7f30660354..ca462244bd 100644 --- a/engine/src/rgbscript.h +++ b/engine/src/rgbscript.h @@ -91,7 +91,7 @@ class RGBScript : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors); /** @reimp */ QString name() const; diff --git a/engine/src/rgbscriptv4.cpp b/engine/src/rgbscriptv4.cpp index 672dffb417..67e9845a58 100644 --- a/engine/src/rgbscriptv4.cpp +++ b/engine/src/rgbscriptv4.cpp @@ -233,7 +233,7 @@ int RGBScript::rgbMapStepCount(const QSize& size) } } -void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]) +void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors) { QMutexLocker engineLocker(s_engineMutex); @@ -244,9 +244,11 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint if (m_apiVersion <= 2) { args << size.width() << size.height() << rgb << step; } else { - QJSValue jsRawColors = s_engine->newArray(RGBAlgorithmRawColorCount); - for (int i = 0; i < RGBAlgorithmRawColorCount; i++) { - jsRawColors.setProperty(i, QJSValue(rawColors[i])); + int accColors = acceptColors(); + int rawColorCount = rawColors.count(); + QJSValue jsRawColors = s_engine->newArray(); + for (int i = 0; i < rawColorCount && i < accColors; i++) { + jsRawColors.setProperty(i, QJSValue(rawColors.at(i)));; } args << size.width() << size.height() << rgb << step << jsRawColors; diff --git a/engine/src/rgbscriptv4.h b/engine/src/rgbscriptv4.h index d9f40ecfe2..13e14598ac 100644 --- a/engine/src/rgbscriptv4.h +++ b/engine/src/rgbscriptv4.h @@ -92,7 +92,7 @@ class RGBScript : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors); /** @reimp */ QString name() const; diff --git a/engine/src/rgbtext.cpp b/engine/src/rgbtext.cpp index 542a9dec20..42b76cd7de 100644 --- a/engine/src/rgbtext.cpp +++ b/engine/src/rgbtext.cpp @@ -266,7 +266,7 @@ int RGBText::rgbMapStepCount(const QSize& size) return scrollingTextStepCount(); } -void RGBText::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]) +void RGBText::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors) { Q_UNUSED(rawColors); if (animationStyle() == StaticLetters) diff --git a/engine/src/rgbtext.h b/engine/src/rgbtext.h index d5a1ad7561..5c58c23bfb 100644 --- a/engine/src/rgbtext.h +++ b/engine/src/rgbtext.h @@ -99,7 +99,7 @@ class RGBText : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, uint (&rawColors)[RGBAlgorithmRawColorCount]); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors); /** @reimp */ QString name() const; diff --git a/engine/test/rgbscript/rgbscript_test.cpp b/engine/test/rgbscript/rgbscript_test.cpp index deeb11172d..ac96cb4e15 100644 --- a/engine/test/rgbscript/rgbscript_test.cpp +++ b/engine/test/rgbscript/rgbscript_test.cpp @@ -175,7 +175,7 @@ void RGBScript_Test::evaluateNoRgbMapFunction() RGBMap map; s.m_contents = code; QCOMPARE(s.evaluate(), false); - uint rawRgbColors[RGBAlgorithmRawColorCount] = { + QVector rawRgbColors = { QColor(Qt::red).rgb(), QColor(Qt::green).rgb() }; @@ -213,7 +213,7 @@ void RGBScript_Test::rgbMapColorArray() RGBMap map; RGBScript s = m_doc->rgbScriptsCache()->script("Alternate"); QCOMPARE(s.evaluate(), true); - uint rawRgbColors[RGBAlgorithmRawColorCount] = { + QVector rawRgbColors = { QColor(Qt::red).rgb() & 0x00ffffff, QColor(Qt::green).rgb() & 0x00ffffff }; @@ -240,7 +240,7 @@ void RGBScript_Test::rgbMap() { RGBMap map; RGBScript s = m_doc->rgbScriptsCache()->script("Stripes"); - uint rawRgbColors[RGBAlgorithmRawColorCount] = { + QVector rawRgbColors = { QColor(Qt::red).rgb(), uint(0) }; @@ -272,7 +272,7 @@ void RGBScript_Test::runScripts() { QSize mapSize = QSize(7, 11); // Use different numbers for x and y for the test QSize mapSizePlus = QSize(12, 22); // Prepare a larger matrix to check behaviour on matrix change - uint rawRgbColors[RGBAlgorithmRawColorCount] = { + QVector rawRgbColors = { // QColor(Qt::red).rgb() is 0xffff0000 due to the alpha channel // This test also wants to test that there is no color space overrun. QColor(Qt::red).rgb() & 0xffffff, diff --git a/engine/test/rgbtext/rgbtext_test.cpp b/engine/test/rgbtext/rgbtext_test.cpp index 8dd454ecdc..bccf54e2c5 100644 --- a/engine/test/rgbtext/rgbtext_test.cpp +++ b/engine/test/rgbtext/rgbtext_test.cpp @@ -324,7 +324,7 @@ void RGBText_Test::staticLetters() QRgb color(0xFFFFFFFF); RGBMap map; - uint rawRgbColors[RGBAlgorithmRawColorCount] = { + QVector rawRgbColors = { QColor(Qt::red).rgb() ,QColor(Qt::green).rgb() ,0 @@ -369,7 +369,7 @@ void RGBText_Test::horizontalScroll() RGBText text(m_doc); text.setText("QLC"); text.setAnimationStyle(RGBText::Horizontal); - uint rawRgbColors[RGBAlgorithmRawColorCount] = { + QVector rawRgbColors = { QColor(Qt::red).rgb() ,QColor(Qt::green).rgb() ,0 @@ -424,7 +424,7 @@ void RGBText_Test::verticalScroll() RGBText text(m_doc); text.setText("QLC"); text.setAnimationStyle(RGBText::Vertical); - uint rawRgbColors[RGBAlgorithmRawColorCount] = { + QVector rawRgbColors = { QColor(Qt::red).rgb() ,QColor(Qt::green).rgb() ,0 diff --git a/qmlui/rgbmatrixeditor.cpp b/qmlui/rgbmatrixeditor.cpp index c85a2cf36d..81f555ed6f 100644 --- a/qmlui/rgbmatrixeditor.cpp +++ b/qmlui/rgbmatrixeditor.cpp @@ -134,8 +134,8 @@ void RGBMatrixEditor::setAlgorithmIndex(int algoIndex) /** if we're setting the same algorithm, then there's nothing to do */ if (m_matrix->algorithm() != nullptr && m_matrix->algorithm()->name() == algo->name()) return; - Q_ASSERT(5 == RGBAlgorithmRawColorCount); - QColor colors[RGBAlgorithmRawColorCount] = { + Q_ASSERT(5 == RGBAlgorithmColorDisplayCount); + QVector colors = { m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->getColor(2), diff --git a/ui/src/rgbmatrixeditor.cpp b/ui/src/rgbmatrixeditor.cpp index 945c0234b0..037f011a0f 100644 --- a/ui/src/rgbmatrixeditor.cpp +++ b/ui/src/rgbmatrixeditor.cpp @@ -887,7 +887,10 @@ void RGBMatrixEditor::slotPatternActivated(int patternIndex) m_matrix->setAlgorithm(algo); if (algo != NULL) { updateColors(); - QColor colors[RGBAlgorithmRawColorCount] = { +#if (5 != RGBAlgorithmColorDisplayCount) +#error "Further colors need to be displayed." +#endif + QVector colors = { m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->getColor(2), From 05fd4b369ac0babce7c7e60f9cfefb275404a9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Thu, 6 Jun 2024 09:52:20 +0200 Subject: [PATCH 43/63] Fix for unit test in the new structure. --- engine/src/rgbmatrix.cpp | 6 +-- engine/test/rgbmatrix/rgbmatrix_test.cpp | 59 ++++++++++++++---------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/engine/src/rgbmatrix.cpp b/engine/src/rgbmatrix.cpp index c929a14777..7089aa87cc 100644 --- a/engine/src/rgbmatrix.cpp +++ b/engine/src/rgbmatrix.cpp @@ -430,8 +430,8 @@ bool RGBMatrix::loadXML(QXmlStreamReader &root) { QString colorNumText = root.name().string()->right( root.name().length() - KXMLQLCRGBMatrixColorBase.length()); - uint colorNum = colorNumText.toUInt(); - setColor(colorNum, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); + uint colorIdx = colorNumText.toUInt() - 1; + setColor(colorIdx, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); } else if (root.name() == KXMLQLCRGBMatrixControlMode) { @@ -490,7 +490,7 @@ bool RGBMatrix::saveXML(QXmlStreamWriter *doc) uint count = 0; while (colorIt.hasNext()) { QColor color = colorIt.next(); - QString elementName = KXMLQLCRGBMatrixColorBase.append(QString::number(count)); + QString elementName = KXMLQLCRGBMatrixColorBase.append(QString::number(count + 1)); doc->writeTextElement(elementName, QString::number(color.rgb())); count ++; } diff --git a/engine/test/rgbmatrix/rgbmatrix_test.cpp b/engine/test/rgbmatrix/rgbmatrix_test.cpp index f34b53e017..1dfb801ea2 100644 --- a/engine/test/rgbmatrix/rgbmatrix_test.cpp +++ b/engine/test/rgbmatrix/rgbmatrix_test.cpp @@ -240,7 +240,8 @@ void RGBMatrix_Test::loadSave() QCOMPARE(xmlReader.attributes().value("ID").toString(), QString::number(mtx->id())); QCOMPARE(xmlReader.attributes().value("Name").toString(), QString("Xyzzy")); - int speed = 0, dir = 0, run = 0, algo = 0, color1 = 0, color2 = 0, color3 = 0, color4 = 0, color5 = 0, grp = 0, colormode = 0; + int speed = 0, dir = 0, run = 0, algo = 0, grp = 0, color1 = 0, color2 = 0, color3 = 0, color4 = 0, color5 = 0, colormode = 0; + QVector colors; while (xmlReader.readNextStartElement()) { @@ -268,30 +269,40 @@ void RGBMatrix_Test::loadSave() algo++; xmlReader.skipCurrentElement(); } - else if (xmlReader.name().toString() == "Color1") + else if (xmlReader.name().toString().startsWith("Color", Qt::CaseSensitive)) { - QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::magenta).rgb()); - color1++; - } - else if (xmlReader.name().toString() == "Color2") - { - QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::blue).rgb()); - color2++; - } - else if (xmlReader.name().toString() == "Color3") - { - QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::green).rgb()); - color3++; - } - else if (xmlReader.name().toString() == "Color4") - { - QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::red).rgb()); - color4++; - } - else if (xmlReader.name().toString() == "Color5") - { - QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::yellow).rgb()); - color5++; + bool ok = false; + QString colorNumText = xmlReader.name().toString().right( + xmlReader.name().toString().length() - QString("Color").length()); + int colorNum = colorNumText.toInt(&ok, 10); + QVERIFY(ok); + + switch (colorNum) { + case 1: + QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::magenta).rgb()); + color1 ++; + break; + case 2: + QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::blue).rgb()); + color2++; + break; + case 3: + QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::green).rgb()); + color3++; + break; + case 4: + QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::red).rgb()); + color4++; + break; + case 5: + QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::yellow).rgb()); + color5++; + break; + default: + // The color number can be between 1 and MAXINT, but here we expect only 5. + QVERIFY(colorNum > 0 && colorNum <= 5); + break; + } } else if (xmlReader.name().toString() == "FixtureGroup") { From d02415f3d106148911f039eb99647b4af459bbb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Tue, 15 Oct 2024 20:43:24 +0200 Subject: [PATCH 44/63] Implement v3 color hook API in scripts. --- resources/rgbscripts/alternate.js | 20 +- resources/rgbscripts/alternatecolorsdirect.js | 51 ++-- resources/rgbscripts/ballscolorsdirect.js | 43 +-- resources/rgbscripts/devtool.html | 29 +- resources/rgbscripts/devtool/devtool.js | 251 +++++++----------- resources/rgbscripts/empty.js | 38 ++- resources/rgbscripts/marqueecolorsdirect.js | 50 ++-- resources/rgbscripts/plasmacolorsdirect.js | 51 ++-- 8 files changed, 258 insertions(+), 275 deletions(-) diff --git a/resources/rgbscripts/alternate.js b/resources/rgbscripts/alternate.js index 7381e06852..32c1727ba9 100644 --- a/resources/rgbscripts/alternate.js +++ b/resources/rgbscripts/alternate.js @@ -59,7 +59,7 @@ var testAlgo; colorPalette.makeSubArray = function(_index) { var _array = new Array(); for (var i = 0; i < colorPalette.collection.length; i++) { - _array.push(colorPalette.collection[parseInt(i, 10)][parseInt(_index, 10)]); + _array.push(colorPalette.collection[i][_index]); } return _array; }; @@ -210,9 +210,9 @@ var testAlgo; var realBlockSize = algo.blockSize; for (y = 0; y < height; y++) { - map[parseInt(y, 10)] = new Array(width); + map[y] = new Array(width); for (x = 0; x < width; x++) { - map[parseInt(y, 10)][parseInt(x, 10)] = 0; + map[y][x] = 0; } } @@ -303,9 +303,9 @@ var testAlgo; } } if (colorSelectOne) { - map[parseInt(y, 10)][parseInt(x, 10)] = algo.getColor1Value(); + map[y][x] = algo.getColor1Value(); } else { - map[parseInt(y, 10)][parseInt(x, 10)] = algo.getColor2Value(); + map[y][x] = algo.getColor2Value(); } } } @@ -314,21 +314,21 @@ var testAlgo; if (algo.orientation === 0) { for (y = 0; y < yMax; y++) { for (x = 0; x < xMax; x++) { - map[parseInt(y, 10)][parseInt(width - x - 1, 10)] = map[parseInt(y, 10)][parseInt(x, 10)]; + map[y][width - x - 1] = map[y][x]; } } } else if (algo.orientation === 1) { for (y = 0; y < yMax; y++) { for (x = 0; x < xMax; x++) { - map[parseInt(height - y - 1, 10)][parseInt(x, 10)] = map[parseInt(y, 10)][parseInt(x, 10)]; + map[height - y - 1][x] = map[y][x]; } } } else if (algo.orientation === 2) { for (y = 0; y < yMax; y++) { for (x = 0; x < xMax; x++) { - map[parseInt(height - y - 1, 10)][parseInt(x, 10)] = map[parseInt(y, 10)][parseInt(x, 10)]; - map[parseInt(y, 10)][parseInt(width - x - 1, 10)] = map[parseInt(y, 10)][parseInt(x, 10)]; - map[parseInt(height - y - 1, 10)][parseInt(width - x - 1, 10)] = map[parseInt(y, 10)][parseInt(x, 10)]; + map[height - y - 1][x] = map[y][x]; + map[y][width - x - 1] = map[y][x]; + map[height - y - 1][width - x - 1] = map[y][x]; } } } diff --git a/resources/rgbscripts/alternatecolorsdirect.js b/resources/rgbscripts/alternatecolorsdirect.js index 02f4ff6683..1f3f190033 100644 --- a/resources/rgbscripts/alternatecolorsdirect.js +++ b/resources/rgbscripts/alternatecolorsdirect.js @@ -1,6 +1,6 @@ /* Q Light Controller Plus - alternate2colors.js + alternatecolorsdirect.js Copyright (c) Hans-Jürgen Tappe @@ -104,25 +104,40 @@ var testAlgo; return algo.offset; }; - algo.getRawColor = function (rawColors, idx) { - if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { - return rawColors[idx]; - } else { - return 0; + var util = new Object; + util.colorArray = new Array(algo.acceptColors); + + util.getRawColor = function (idx) { + var color = 0; + if (Array.isArray(util.colorArray) && util.colorArray.length > idx && ! isNaN(util.colorArray[idx])) { + color = util.colorArray[idx]; } + return color; } - algo.rgbMap = function(width, height, rgb, step, rawColors) { + algo.rgbMapSetColors = function(rawColors) + { + if (! Array.isArray(rawColors)) + return; + for (var i = 0; i < algo.acceptColors; i++) { + if (i < rawColors.length) + { + util.colorArray[i] = rawColors[i]; + } else { + util.colorArray[i] = 0; + } + } + } + + algo.rgbMap = function(width, height, rgb, step) { var map = new Array(height); var colorSelectOne = (step === 1) ? false : true; var rowColorOne = colorSelectOne; var realBlockSize = algo.blockSize; + // Setup the rgb map for (y = 0; y < height; y++) { - map[parseInt(y, 10)] = new Array(width); - for (x = 0; x < width; x++) { - map[parseInt(y, 10)][parseInt(x, 10)] = 0; - } + map[y] = new Array(width); } var xMax = width; @@ -212,9 +227,9 @@ var testAlgo; } } if (colorSelectOne) { - map[parseInt(y, 10)][parseInt(x, 10)] = algo.getRawColor(rawColors, 0); + map[y][x] = util.getRawColor(0); } else { - map[parseInt(y, 10)][parseInt(x, 10)] = algo.getRawColor(rawColors, 1); + map[y][x] = util.getRawColor(1); } } } @@ -223,21 +238,21 @@ var testAlgo; if (algo.orientation === 0) { for (y = 0; y < yMax; y++) { for (x = 0; x < xMax; x++) { - map[parseInt(y, 10)][parseInt(width - x - 1, 10)] = map[parseInt(y, 10)][parseInt(x, 10)]; + map[y][width - x - 1] = map[y][x]; } } } else if (algo.orientation === 1) { for (y = 0; y < yMax; y++) { for (x = 0; x < xMax; x++) { - map[parseInt(height - y - 1, 10)][parseInt(x, 10)] = map[parseInt(y, 10)][parseInt(x, 10)]; + map[height - y - 1][x] = map[y][x]; } } } else if (algo.orientation === 2) { for (y = 0; y < yMax; y++) { for (x = 0; x < xMax; x++) { - map[parseInt(height - y - 1, 10)][parseInt(x, 10)] = map[parseInt(y, 10)][parseInt(x, 10)]; - map[parseInt(y, 10)][parseInt(width - x - 1, 10)] = map[parseInt(y, 10)][parseInt(x, 10)]; - map[parseInt(height - y - 1, 10)][parseInt(width - x - 1, 10)] = map[parseInt(y, 10)][parseInt(x, 10)]; + map[height - y - 1][x] = map[y][x]; + map[y][width - x - 1] = map[y][x]; + map[height - y - 1][width - x - 1] = map[y][x]; } } } diff --git a/resources/rgbscripts/ballscolorsdirect.js b/resources/rgbscripts/ballscolorsdirect.js index 42a2e63132..c4ba230570 100644 --- a/resources/rgbscripts/ballscolorsdirect.js +++ b/resources/rgbscripts/ballscolorsdirect.js @@ -1,6 +1,6 @@ /* Q Light Controller Plus - balls5colors.js + ballscolorsdirect.js Copyright (c) Rob Nieuwenhuizen @@ -36,13 +36,10 @@ var testAlgo; algo.properties.push("name:presetCollision|type:list|display:Self Collision|values:No,Yes|write:setCollision|read:getCollision"); algo.presetSize = 5; - algo.colorIndex = new Array( - algo.color3Index, - algo.color4Index, - algo.color5Index); - - var util = new Object; algo.initialized = false; + + var util = new Object; + util.colorArray = new Array(algo.acceptColors); algo.setSize = function (_size) { algo.presetSize = _size; @@ -67,18 +64,31 @@ var testAlgo; else if (algo.presetCollision === 1) { return "No"; } }; - algo.getRawColor = function (rawColors, idx) { - if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { - return rawColors[idx]; - } else { - return 0; + util.getRawColor = function (idx) { + var color = 0; + if (Array.isArray(util.colorArray) && util.colorArray.length > idx && ! isNaN(util.colorArray[idx])) { + color = util.colorArray[idx]; + } + return color; + } + + algo.rgbMapSetColors = function(rawColors) + { + if (! Array.isArray(rawColors)) + return; + for (var i = 0; i < algo.acceptColors; i++) { + if (i < rawColors.length) + { + util.colorArray[i] = rawColors[i]; + } else { + util.colorArray[i] = 0; + } } } util.initialize = function (width, height) { algo.ball = new Array(algo.presetNumber); algo.direction = new Array(algo.presetNumber); - algo.colour = new Array(algo.presetNumber); for (var i = 0; i < algo.presetNumber; i++) { var x = Math.random() * (width - 1); // set random start @@ -92,13 +102,10 @@ var testAlgo; return; }; - algo.rgbMap = function (width, height, rgb, progstep, rawColors) { + algo.rgbMap = function (width, height, rgb, progstep) { if (algo.initialized === false) { util.initialize(width, height); } - for (var i = 0; i < algo.presetNumber; i++) { - algo.colour[i] = algo.getRawColor(rawColors, i % algo.acceptColors); - } var map = new Array(height); // Clear map data for (var y = 0; y < height; y++) { @@ -110,7 +117,7 @@ var testAlgo; } for (var i = 0; i < algo.presetNumber; i++) { // for each ball displayed - rgb = algo.colour[i]; // use RGB for ball random colour + rgb = util.getRawColor(i % algo.acceptColors); // use RGB for ball random colour var r = (rgb >> 16) & 0x00FF; // split colour in to var g = (rgb >> 8) & 0x00FF; // separate parts var b = rgb & 0x00FF; diff --git a/resources/rgbscripts/devtool.html b/resources/rgbscripts/devtool.html index d5457c9a99..3fac197f39 100644 --- a/resources/rgbscripts/devtool.html +++ b/resources/rgbscripts/devtool.html @@ -127,32 +127,7 @@

Grid Size

Pixel colors

- - - - - - - - - - - - - - - - - - - - - - - - - - +
Color 1 (rrggbb)
Color 2 (rrggbb, leave empty to disable)
Color 3 (rrggbb, leave empty to disable)
Color 4 (rrggbb, leave empty to disable)
Color 5 (rrggbb, leave empty to disable)
@@ -214,7 +189,7 @@

Preview


-This file is licensed under the Apache 2.0 license. Copyright © Heikki Junnila, Massimo Callegari, APIv2 integration: Hans-Jürgen Tappe. +This file is licensed under the Apache 2.0 license. Copyright © Heikki Junnila, Massimo Callegari, APIv2 & APIv3 integration: Hans-Jürgen Tappe. diff --git a/resources/rgbscripts/devtool/devtool.js b/resources/rgbscripts/devtool/devtool.js index 7c7ed78d90..32e3d9441c 100644 --- a/resources/rgbscripts/devtool/devtool.js +++ b/resources/rgbscripts/devtool/devtool.js @@ -179,26 +179,59 @@ devtool.initProperties = function() properties.forEach(devtool.addPropertyTableEntry); } -devtool.initPixelColors = function() +devtool.getAcceptColors = function() { - var acceptColors = parseInt(testAlgo.acceptColors, 10); - if (isNaN(acceptColors)) { - acceptColors = 0; - } - var pixelColorChooser = document.getElementById("pixelColorChooser"); - pixelColorChooser.hidden = (acceptColors === 0); - - var color2Chooser = document.getElementById("color2Chooser"); - color2Chooser.hidden = (acceptColors < 2); + var acceptColors = 2 // Default + if (typeof testAlgo.acceptColors !== "undefined") { + acceptColors = parseInt(testAlgo.acceptColors, 10); + } - var color3Chooser = document.getElementById("color3Chooser"); - color3Chooser.hidden = (acceptColors < 3); + return acceptColors; +} - var color4Chooser = document.getElementById("color4Chooser"); - color4Chooser.hidden = (acceptColors < 4); +devtool.initPixelColors = function() +{ + var acceptColors = devtool.getAcceptColors(); - var color5Chooser = document.getElementById("color5Chooser"); - color5Chooser.hidden = (acceptColors < 5); + var colorTable = document.getElementById("colorChooserTable"); + if (colorTable === null) + return; + while (colorTable.rows.length > acceptColors) + colorTable.deleteRow(-1); + while (colorTable.rows.length < acceptColors) { + var colorId = colorTable.rows.length + 1; + var row = colorTable.insertRow(); + row.id = "color" + colorId + "Chooser"; + var titleCell = row.insertCell(); + if (colorId == 1) + titleCell.textContent = "Color " + colorId + " (rrggbb)"; + else + titleCell.textContent = "Color " + colorId + " (rrggbb, leave empty to disable)"; + var colorInput = document.createElement("input"); + colorInput.setAttribute("type", "text"); + colorInput.setAttribute("id", "color" + colorId + "Text"); + if (colorId == 1) + colorInput.value = "FF0000"; + else + colorInput.value = ""; + colorInput.setAttribute("pattern", "[0-9A-Fa-f]{6}"); + colorInput.setAttribute("size", "6"); + colorInput.setAttribute("onInput", "devtool.onColorTextChange()"); + colorInput.required = true; + var colorCell = row.insertCell(); + colorCell.appendChild(colorInput); + var colorPicker = document.createElement("input"); + colorPicker.setAttribute("type", "color"); + colorPicker.setAttribute("id", "color" + colorId + "Picker"); + if (colorId == 1) + colorPicker.value = "#FF0000"; + else + colorPicker.value = "#000000"; + colorPicker.setAttribute("onInput", "devtool.onColorPickerChange(" + colorId + ")"); + colorPicker.required = true; + var pickerCell = row.insertCell(); + pickerCell.appendChild(colorPicker); + } } devtool.initSpeedValue = function() @@ -223,48 +256,24 @@ devtool.initAlternateValue = function() devtool.initColorValues = function() { - var color1 = localStorage.getItem("devtool.color1"); - if (color1 === null || Number.isNaN(parseInt("0x" + color1, 16))) { - color1 = "ff0000"; - } - color1 = color1.padStart(6,"0"); - document.getElementById("color1Text").value = color1; - document.getElementById("color1Picker").value = "#" + color1; - var color2 = localStorage.getItem("devtool.color2"); - if (color2 === null || color2 === "" || Number.isNaN(parseInt("0x" + color2, 16))) { - document.getElementById("color2Text").value = ""; - document.getElementById("color2Picker").value = "#000000"; - } else { - color2 = color2.padStart(6,"0"); - document.getElementById("color2Text").value = color2; - document.getElementById("color2Picker").value = "#" + color2; - } - var color3 = localStorage.getItem("devtool.color3"); - if (color3 === null || color2 === "" || Number.isNaN(parseInt("0x" + color3, 16))) { - document.getElementById("color3Text").value = ""; - document.getElementById("color3Picker").value = "#000000"; - } else { - color3 = color3.padStart(6,"0"); - document.getElementById("color3Text").value = color3; - document.getElementById("color3Picker").value = "#" + color3; - } - var color4 = localStorage.getItem("devtool.color4"); - if (color4 === null || color4 === "" || Number.isNaN(parseInt("0x" + color4, 16))) { - document.getElementById("color4Text").value = ""; - document.getElementById("color4Picker").value = "#000000"; - } else { - color4 = color4.padStart(6,"0"); - document.getElementById("color4Text").value = color4; - document.getElementById("color4Picker").value = "#" + color4; - } - var color5 = localStorage.getItem("devtool.color5"); - if (color5 === null || color5 === "" || Number.isNaN(parseInt("0x" + color5, 16))) { - document.getElementById("color5Text").value = ""; - document.getElementById("color5Picker").value = "#000000"; - } else { - color5 = color5.padStart(6,"0"); - document.getElementById("color5Text").value = color5; - document.getElementById("color5Picker").value = "#" + color5; + var rawColors = []; + var acceptColors = devtool.getAcceptColors(); + for (var i = 0; i < acceptColors; i++) { + var idx = i + 1; + var color = localStorage.getItem("devtool.color" + idx); + if (color === null || Number.isNaN(parseInt("0x" + color, 16))) { + if (idx == 1) + color = "ff0000"; + else + color = "000000"; + } + color = color.padStart(6,"0"); + rawColors.push(parseInt("0x" + color, 16)); + document.getElementById("color" + idx + "Text").value = color; + document.getElementById("color" + idx + "Picker").value = "#" + color; + } + if (testAlgo.apiVersion >= 3) { + testAlgo.rgbMapSetColors(rawColors); } } @@ -295,46 +304,25 @@ devtool.getRgbFromColorInt = function(color) return [red, green, blue]; } -devtool.getColor1Int = function() -{ - var colorInput = document.getElementById("color1Text"); - return parseInt(colorInput.value, 16); -} - -devtool.getColor2Int = function() -{ - var colorInput = document.getElementById("color2Text"); - return parseInt(colorInput.value, 16); -} - -devtool.getColor3Int = function() -{ - var colorInput = document.getElementById("color3Text"); - return parseInt(colorInput.value, 16); -} - -devtool.getColor4Int = function() -{ - var colorInput = document.getElementById("color4Text"); - return parseInt(colorInput.value, 16); -} - -devtool.getColor5Int = function() +devtool.getColorInt = function(index) { - var colorInput = document.getElementById("color5Text"); - return parseInt(colorInput.value, 16); + var colorInput = document.getElementById("color" + index + "Text"); + if (colorInput === null) + return 0; + return parseInt("0x" + colorInput.value, 16); } devtool.getCurrentColorInt = function() { - var primaryColor = devtool.getColor1Int(); - var secondaryColor = devtool.getColor2Int(); + var primaryColor = devtool.getColorInt(1); + var secondaryColor = devtool.getColorInt(2); + var acceptColors = devtool.getAcceptColors(); - if (testAlgo.acceptColors === 0 || Number.isNaN(primaryColor)) { + if (acceptColors === 0 || Number.isNaN(primaryColor)) { return null; } - if (testAlgo.acceptColors === 1 || Number.isNaN(secondaryColor) || devtool.stepCount() <= 1) { + if (acceptColors === 1 || Number.isNaN(secondaryColor) || devtool.stepCount() <= 1) { return primaryColor; } @@ -361,19 +349,7 @@ devtool.writeCurrentStep = function() map.deleteRow(i); } - var rgb; - if (testAlgo.apiVersion <= 2) { - rgb = testAlgo.rgbMap(devtool.gridwidth, devtool.gridheight, devtool.getCurrentColorInt(), devtool.currentStep); - } else { - var color1Rgb = devtool.getColor1Int(); - var color2Rgb = devtool.getColor2Int(); - var color3Rgb = devtool.getColor3Int(); - var color4Rgb = devtool.getColor4Int(); - var color5Rgb = devtool.getColor5Int(); - var rawColors = [color1Rgb, color2Rgb, color3Rgb, color4Rgb, color5Rgb]; - - rgb = testAlgo.rgbMap(devtool.gridwidth, devtool.gridheight, devtool.getCurrentColorInt(), devtool.currentStep, rawColors); - } + var rgb = testAlgo.rgbMap(devtool.gridwidth, devtool.gridheight, devtool.getCurrentColorInt(), devtool.currentStep); for (var y = 0; y < devtool.gridheight; y++) { @@ -382,11 +358,7 @@ devtool.writeCurrentStep = function() for (var x = 0; x < devtool.gridwidth; x++) { var cell = row.insertCell(x); - var rgbStr = rgb[y][x].toString(16); - while (rgbStr.length !== 6) { - rgbStr = "0" + rgbStr; - } - rgbStr = "#" + rgbStr; + var rgbStr = "#" + rgb[y][x].toString(16).padStart(6,"0"); cell.style.backgroundColor = rgbStr; cell.style.height = devtool.gridsize + "px"; cell.style.width = devtool.gridsize + "px"; @@ -433,50 +405,27 @@ devtool.onGridSizeUpdated = function() devtool.onColorTextChange = function() { - var color = parseInt("0x" + document.getElementById("color1Text").value, 16).toString(16); - if (color === "NaN"){ - document.getElementById("color1Picker").value = "#000000"; - } else { - document.getElementById("color1Picker").value = "#" + color.padStart(6,"0");; - } - localStorage.setItem("devtool.color1", color); - - color = parseInt("0x" + document.getElementById("color2Text").value, 16).toString(16); - if (color === "NaN") { // Evaluation of the string. - document.getElementById("color2Picker").value = "#000000"; - localStorage.setItem("devtool.color2", ""); - } else { - document.getElementById("color2Picker").value = "#" + color.padStart(6,"0");; - localStorage.setItem("devtool.color2", color); - } - - color = parseInt("0x" + document.getElementById("color3Text").value, 16).toString(16); - if (color === "NaN") { // Evaluation of the string. - document.getElementById("color3Picker").value = "#000000"; - localStorage.setItem("devtool.color3", ""); - } else { - document.getElementById("color3Picker").value = "#" + color.padStart(6,"0");; - localStorage.setItem("devtool.color3", color); + var rawColors = []; + var acceptColors = devtool.getAcceptColors(); + for (var i = 0; i < acceptColors; i++) { + var idx = i + 1; + var color = parseInt("0x" + document.getElementById("color" + idx + "Text").value, 16).toString(16); + if (color === "NaN" && + document.getElementById("color" + idx + "Picker").value != "#000000"){ + document.getElementById("color" + idx + "Picker").value = "#000000"; + } else { + var pickerValue = "#" + color.padStart(6,"0"); + if (document.getElementById("color" + idx + "Picker").value != pickerValue) { + document.getElementById("color" + idx + "Picker").value = pickerValue; + } + } + localStorage.setItem("devtool.color" + idx, color); + rawColors.push(devtool.getColorInt(idx)); } - - color = parseInt("0x" + document.getElementById("color4Text").value, 16).toString(16); - if (color === "NaN") { // Evaluation of the string. - document.getElementById("color4Picker").value = "#000000"; - localStorage.setItem("devtool.color4", ""); - } else { - document.getElementById("color4Picker").value = "#" + color.padStart(6,"0");; - localStorage.setItem("devtool.color4", color); + if (testAlgo.apiVersion >= 3) { + testAlgo.rgbMapSetColors(rawColors); } - color = parseInt("0x" + document.getElementById("color5Text").value, 16).toString(16); - if (color === "NaN") { // Evaluation of the string. - document.getElementById("color5Picker").value = "#000000"; - localStorage.setItem("devtool.color5", ""); - } else { - document.getElementById("color5Picker").value = "#" + color.padStart(6,"0");; - localStorage.setItem("devtool.color5", color); - } - devtool.writeCurrentStep(); } @@ -525,11 +474,11 @@ devtool.init = function() } devtool.initDefinitions(); devtool.initGridSize(); - devtool.setStep(0); - devtool.initSpeedValue(); - devtool.initColorValues(); devtool.initProperties(); devtool.initPixelColors(); + devtool.initColorValues(); + devtool.setStep(0); + devtool.initSpeedValue(); devtool.onGridSizeUpdated(); devtool.writeCurrentStep(); devtool.initTestStatus(); diff --git a/resources/rgbscripts/empty.js b/resources/rgbscripts/empty.js index 43ce62acf2..3be222b787 100644 --- a/resources/rgbscripts/empty.js +++ b/resources/rgbscripts/empty.js @@ -30,18 +30,39 @@ var testAlgo; algo.acceptColors = 2; algo.properties = new Array(); + var util = new Object; + util.colorArray = new Array(algo.acceptColors); + /** * Evaluates the rawColors parameter and returns the idx value * - * @param rawColors The array of colors * @param idx The index of the color in the array * @return The requested array color or zero in case of invalid input */ - algo.getRawColor = function (rawColors, idx) { - if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { - return rawColors[idx]; - } else { - return 0; + util.getRawColor = function (idx) { + var color = 0; + if (Array.isArray(util.colorArray) && util.colorArray.length > idx && ! isNaN(util.colorArray[idx])) { + color = util.colorArray[idx]; + } + return color; + } + + /** + * Ingests the colors as received through the parameter + * + * @param rawColors The array of colors + */ + algo.rgbMapSetColors = function(rawColors) + { + if (! Array.isArray(rawColors)) + return; + for (var i = 0; i < algo.acceptColors; i++) { + if (i < rawColors.length) + { + util.colorArray[i] = rawColors[i]; + } else { + util.colorArray[i] = 0; + } } } @@ -53,17 +74,16 @@ var testAlgo; * @param height The height of the matrix in pixels * @param rgb Tells the color requested by user in the UI, interpolated between stepCount. * @param step The step number that is requested (0 to (algo.rgbMapStepCount - 1)) - * @param rawColors The non-interpolated algo.acceptColors user-defined colors * @return A two-dimensional matrix array[height][width]. */ - algo.rgbMap = function(width, height, rgb, step, rawColors) + algo.rgbMap = function(width, height, rgb, step) { var map = new Array(height); for (var y = 0; y < height; y++) { map[y] = new Array(); for (var x = 0; x < width; x++) { - map[y][x] = rgb; // <-- color goes here + map[y][x] = rgb; // <-- step color goes here } } diff --git a/resources/rgbscripts/marqueecolorsdirect.js b/resources/rgbscripts/marqueecolorsdirect.js index 55f9d21000..c010b82f4b 100644 --- a/resources/rgbscripts/marqueecolorsdirect.js +++ b/resources/rgbscripts/marqueecolorsdirect.js @@ -1,6 +1,6 @@ /* Q Light Controller Plus - marquee2colors.js + marqueecolorsdirect.js Copyright (c) Branson Matheson @@ -46,6 +46,7 @@ var testAlgo; util.height = 0; util.featureColor = 0; util.step = algo.marqueeCount; + util.colorArray = new Array(algo.acceptColors); util.lights = new Array(); util.feature = new Array(); @@ -93,9 +94,32 @@ var testAlgo; return algo.marqueeCount; }; - util.initialize = function (width, height, rawColors) { + util.getRawColor = function (idx) { + var color = 0; + if (Array.isArray(util.colorArray) && util.colorArray.length > idx && ! isNaN(util.colorArray[idx])) { + color = util.colorArray[idx]; + } + return color; + } + + algo.rgbMapSetColors = function(rawColors) + { + if (! Array.isArray(rawColors)) + return; + for (var i = 0; i < algo.acceptColors; i++) { + if (i < rawColors.length) + { + util.colorArray[i] = rawColors[i]; + } else { + util.colorArray[i] = 0; + } + } + } + + + util.initialize = function (width, height) { // initialize feature - util.featureColor = algo.getRawColor(rawColors, 0); + util.featureColor = util.getRawColor(0); util.feature = new Array(); var maxDistance = Math.min(width, height) / 2; for (var y = 0; y < height; y++) { @@ -157,7 +181,7 @@ var testAlgo; return newRGB; }; - util.getNextStep = function (width, height, rawColors) { + util.getNextStep = function (width, height) { var map = new Array(height); for (var y = 0; y <= height - 1; y++) { map[y] = new Array(width); @@ -177,7 +201,7 @@ var testAlgo; } // create light map add lights, go around the outside - var marqueeColor = algo.getRawColor(rawColors, 1); + var marqueeColor = util.getRawColor(1); var p = 0; // left for (var y = 0; y < height; y++) { @@ -214,25 +238,17 @@ var testAlgo; return map; }; - algo.getRawColor = function (rawColors, idx) { - if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { - return rawColors[idx]; - } else { - return 0; - } - } - - algo.rgbMap = function(width, height, rgb, step, rawColors) { + algo.rgbMap = function(width, height, rgb, step) { if ( util.initialized === false || - util.featureColor != algo.getRawColor(rawColors, 0) || + util.featureColor != util.getRawColor(0) || util.width !== width || util.height !== height ) { - util.initialize(width, height, rawColors); + util.initialize(width, height); } - var map = util.getNextStep(width, height, rawColors); + var map = util.getNextStep(width, height); return map; }; diff --git a/resources/rgbscripts/plasmacolorsdirect.js b/resources/rgbscripts/plasmacolorsdirect.js index 38d2510532..c53fad83fd 100644 --- a/resources/rgbscripts/plasmacolorsdirect.js +++ b/resources/rgbscripts/plasmacolorsdirect.js @@ -1,6 +1,6 @@ /* Q Light Controller Plus - plasma5colors.js + plasmacolorsdirect.js Copyright (c) Nathan Durnan @@ -48,15 +48,7 @@ var testAlgo; var util = new Object; util.initialized = false; util.gradientData = new Array(); - util.colorArray = new Array(); - - algo.getRawColor = function (rawColors, idx) { - if (Array.isArray(rawColors) && rawColors.length > idx && ! isNaN(rawColors[idx])) { - return rawColors[idx]; - } else { - return 0; - } - } + util.colorArray = new Array(algo.acceptColors); algo.setSize = function(_size) { @@ -91,13 +83,32 @@ var testAlgo; return algo.stepsize; }; - util.initialize = function(rawColors) + util.getRawColor = function (idx) { + var color = 0; + if (Array.isArray(util.colorArray) && util.colorArray.length > idx && ! isNaN(util.colorArray[idx])) { + color = util.colorArray[idx]; + } + return color; + } + + algo.rgbMapSetColors = function(rawColors) { - // Get the colors from the external preset. + if (! Array.isArray(rawColors)) + return; for (var i = 0; i < algo.acceptColors; i++) { - util.colorArray[i] = algo.getRawColor(rawColors, i); + if (i < rawColors.length) + { + util.colorArray[i] = rawColors[i]; + } else { + util.colorArray[i] = 0; + } } + util.initialized = false; + } + + util.initialize = function() + { // calculate the gradient for the selected preset // with the given width var gradIdx = 0; @@ -228,21 +239,11 @@ var testAlgo; return scaled; } - algo.rgbMap = function(width, height, rgb, step, rawColors) + algo.rgbMap = function(width, height, rgb, step) { - if (util.colorArray.length === 0) { - util.initialized = false; - } else if (util.colorArray.length >= algo.acceptColors - 1 && Array.isArray(rawColors)) { - // Check if the externally provided color has changed. - for (var i = 0; i < Math.min(algo.acceptColors, rawColors.length); i++) { - if (util.colorArray[i] !== rawColors[i]) { - util.initialized = false; - } - } - } if (util.initialized === false) { - util.initialize(rawColors); + util.initialize(); } // set a scaling value From 82ed54c6bc8a3d3ecc4dd173f589e50af54414b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Tue, 15 Oct 2024 20:45:46 +0200 Subject: [PATCH 45/63] Add rgbMapSetColors script API to be called on color change. --- engine/src/rgbscript.cpp | 33 +++++++++++++++++++++++++++++++++ engine/src/rgbscript.h | 4 ++++ engine/src/rgbscriptv4.cpp | 37 +++++++++++++++++++++++++++++++++++++ engine/src/rgbscriptv4.h | 4 ++++ 4 files changed, 78 insertions(+) diff --git a/engine/src/rgbscript.cpp b/engine/src/rgbscript.cpp index 9edad258fc..135d71c5f0 100644 --- a/engine/src/rgbscript.cpp +++ b/engine/src/rgbscript.cpp @@ -117,6 +117,7 @@ bool RGBScript::load(const QDir& dir, const QString& fileName) m_script = QScriptValue(); m_rgbMap = QScriptValue(); m_rgbMapStepCount = QScriptValue(); + m_rgbMapSetColors = QScriptValue(); m_apiVersion = 0; m_fileName = fileName; @@ -154,6 +155,7 @@ bool RGBScript::evaluate() m_rgbMap = QScriptValue(); m_rgbMapStepCount = QScriptValue(); + m_rgbMapSetColors = QScriptValue(); m_apiVersion = 0; m_script = s_engine->evaluate(m_contents, m_fileName); @@ -184,6 +186,15 @@ bool RGBScript::evaluate() m_apiVersion = m_script.property("apiVersion").toInteger(); if (m_apiVersion > 0) { + if (m_apiVersion >= 3) + { + m_rgbMapSetColors = m_script.property("rgbMapSetColors"); + if (m_rgbMapSetColors.isFunction() == false) + { + qWarning() << m_fileName << "is missing the rgbMapSetColors() function!"; + return false; + } + } if (m_apiVersion >= 2) return loadProperties(); return true; @@ -249,6 +260,28 @@ int RGBScript::rgbMapStepCount(const QSize& size) } } +void RGBScript::rgbMapSetColors(QVector colors) +{ + QMutexLocker engineLocker(s_engineMutex); + if (m_apiVersion <= 2) + return; + if (m_rgbMapSetColors.isValid() == false) + return; + + int accColors = acceptColors(); + int rawColorCount = colors.count(); + QScriptValue jsRawColors = s_engine->newArray(accColors); + for (int i = 0; i < rawColorCount && i < accColors; i++) + jsRawColors.setProperty(i, QScriptValue(colors.at(i))); + + QScriptValueList args; + args << jsRawColors; + + QScriptValue value = m_rgbMapSetColors.call(QScriptValue(), args); + if (value.isError()) + displayError(value, m_fileName); +} + void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors) { QMutexLocker engineLocker(s_engineMutex); diff --git a/engine/src/rgbscript.h b/engine/src/rgbscript.h index ca462244bd..9e7e292fc4 100644 --- a/engine/src/rgbscript.h +++ b/engine/src/rgbscript.h @@ -90,6 +90,9 @@ class RGBScript : public RGBAlgorithm /** @reimp */ int rgbMapStepCount(const QSize& size); + /** @reimp */ + void rgbMapSetColors(QVector colors); + /** @reimp */ void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors); @@ -119,6 +122,7 @@ class RGBScript : public RGBAlgorithm QScriptValue m_script; //! The script itself QScriptValue m_rgbMap; //! rgbMap() function QScriptValue m_rgbMapStepCount; //! rgbMapStepCount() function + QScriptValue m_rgbMapSetColors; //! rgbMapSetColors() function /************************************************************************ * Properties diff --git a/engine/src/rgbscriptv4.cpp b/engine/src/rgbscriptv4.cpp index 67e9845a58..b542ffd9a8 100644 --- a/engine/src/rgbscriptv4.cpp +++ b/engine/src/rgbscriptv4.cpp @@ -109,6 +109,7 @@ bool RGBScript::load(const QDir& dir, const QString& fileName) m_script = QJSValue(); m_rgbMap = QJSValue(); m_rgbMapStepCount = QJSValue(); + m_rgbMapSetColors = QJSValue(); m_apiVersion = 0; m_fileName = fileName; @@ -137,6 +138,7 @@ bool RGBScript::evaluate() m_rgbMap = QJSValue(); m_rgbMapStepCount = QJSValue(); + m_rgbMapSetColors = QJSValue(); m_apiVersion = 0; if (m_fileName.isEmpty() || m_contents.isEmpty()) @@ -169,6 +171,15 @@ bool RGBScript::evaluate() m_apiVersion = m_script.property("apiVersion").toInt(); if (m_apiVersion > 0) { + if (m_apiVersion >= 3) + { + m_rgbMapSetColors = m_script.property("rgbMapSetColors"); + if (m_rgbMapSetColors.isCallable() == false) + { + qWarning() << m_fileName << "is missing the rgbMapSetColors() function!"; + return false; + } + } if (m_apiVersion >= 2) return loadProperties(); return true; @@ -233,6 +244,30 @@ int RGBScript::rgbMapStepCount(const QSize& size) } } +void RGBScript::rgbMapSetColors(QVector colors) +{ + QMutexLocker engineLocker(s_engineMutex); + if (m_apiVersion <= 2) + return; + if (m_rgbMap.isUndefined() == true) + return; + if (m_rgbMapSetColors.isCallable() == false) + return; + + int accColors = acceptColors(); + int rawColorCount = colors.count(); + QJSValue jsRawColors = s_engine->newArray(accColors); + for (int i = 0; i < rawColorCount && i < accColors; i++) + jsRawColors.setProperty(i, QJSValue(colors.at(i))); + + QJSValueList args; + args << jsRawColors; + + QJSValue value = m_rgbMapSetColors.call(args); + if (value.isError()) + displayError(value, m_fileName); +} + void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors) { QMutexLocker engineLocker(s_engineMutex); @@ -240,6 +275,7 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVect if (m_rgbMap.isUndefined() == true) return; + // Call the rgbMap function QJSValueList args; if (m_apiVersion <= 2) { args << size.width() << size.height() << rgb << step; @@ -257,6 +293,7 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVect if (yarray.isError()) displayError(yarray, m_fileName); + // Check the matrix to be a valid matrix if (yarray.isArray()) { QVariantList yvArray = yarray.toVariant().toList(); diff --git a/engine/src/rgbscriptv4.h b/engine/src/rgbscriptv4.h index 13e14598ac..c0e3418585 100644 --- a/engine/src/rgbscriptv4.h +++ b/engine/src/rgbscriptv4.h @@ -91,6 +91,9 @@ class RGBScript : public RGBAlgorithm /** @reimp */ int rgbMapStepCount(const QSize& size); + /** @reimp */ + void rgbMapSetColors(QVector colors); + /** @reimp */ void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors); @@ -120,6 +123,7 @@ class RGBScript : public RGBAlgorithm QJSValue m_script; //! The script itself QJSValue m_rgbMap; //! rgbMap() function QJSValue m_rgbMapStepCount; //! rgbMapStepCount() function + QJSValue m_rgbMapSetColors; //! rgbMapSetColors() function /************************************************************************ * Properties From 79dca9f90ee4415ffcdde9805de869f901747721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Wed, 16 Oct 2024 15:04:00 +0200 Subject: [PATCH 46/63] Implement Codacy recommendations --- resources/rgbscripts/alternate.js | 2 +- resources/rgbscripts/alternatecolorsdirect.js | 2 +- resources/rgbscripts/devtool/devtool.js | 8 +++---- resources/rgbscripts/marquee.js | 22 ++++++++++--------- resources/rgbscripts/marqueecolorsdirect.js | 22 ++++++++++--------- 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/resources/rgbscripts/alternate.js b/resources/rgbscripts/alternate.js index 32c1727ba9..893336e492 100644 --- a/resources/rgbscripts/alternate.js +++ b/resources/rgbscripts/alternate.js @@ -287,7 +287,7 @@ var testAlgo; lowRest = effectiveStep - realBlockCount * realBlockSize; highRest = (realBlockCount + 1) * realBlockSize - effectiveStep; rest = Math.min(lowRest, highRest); - if (rest < 0.5 || lowRest == 0.5) { + if (rest < 0.5 || lowRest === 0.5) { colorSelectOne = !colorSelectOne; } } else if (algo.orientation === 2) { diff --git a/resources/rgbscripts/alternatecolorsdirect.js b/resources/rgbscripts/alternatecolorsdirect.js index 1f3f190033..be851b9d4d 100644 --- a/resources/rgbscripts/alternatecolorsdirect.js +++ b/resources/rgbscripts/alternatecolorsdirect.js @@ -211,7 +211,7 @@ var testAlgo; lowRest = effectiveStep - realBlockCount * realBlockSize; highRest = (realBlockCount + 1) * realBlockSize - effectiveStep; rest = Math.min(lowRest, highRest); - if (rest < 0.5 || lowRest == 0.5) { + if (rest < 0.5 || lowRest === 0.5) { colorSelectOne = !colorSelectOne; } } else if (algo.orientation === 2) { diff --git a/resources/rgbscripts/devtool/devtool.js b/resources/rgbscripts/devtool/devtool.js index 32e3d9441c..8b64bafc81 100644 --- a/resources/rgbscripts/devtool/devtool.js +++ b/resources/rgbscripts/devtool/devtool.js @@ -203,14 +203,14 @@ devtool.initPixelColors = function() var row = colorTable.insertRow(); row.id = "color" + colorId + "Chooser"; var titleCell = row.insertCell(); - if (colorId == 1) + if (colorId === 1) titleCell.textContent = "Color " + colorId + " (rrggbb)"; else titleCell.textContent = "Color " + colorId + " (rrggbb, leave empty to disable)"; var colorInput = document.createElement("input"); colorInput.setAttribute("type", "text"); colorInput.setAttribute("id", "color" + colorId + "Text"); - if (colorId == 1) + if (colorId === 1) colorInput.value = "FF0000"; else colorInput.value = ""; @@ -223,7 +223,7 @@ devtool.initPixelColors = function() var colorPicker = document.createElement("input"); colorPicker.setAttribute("type", "color"); colorPicker.setAttribute("id", "color" + colorId + "Picker"); - if (colorId == 1) + if (colorId === 1) colorPicker.value = "#FF0000"; else colorPicker.value = "#000000"; @@ -262,7 +262,7 @@ devtool.initColorValues = function() var idx = i + 1; var color = localStorage.getItem("devtool.color" + idx); if (color === null || Number.isNaN(parseInt("0x" + color, 16))) { - if (idx == 1) + if (idx === 1) color = "ff0000"; else color = "000000"; diff --git a/resources/rgbscripts/marquee.js b/resources/rgbscripts/marquee.js index 3cab6d038a..033f0fb3a5 100644 --- a/resources/rgbscripts/marquee.js +++ b/resources/rgbscripts/marquee.js @@ -221,10 +221,12 @@ var testAlgo; }; util.getNextStep = function (width, height) { + var x = 0; + var y = 0; var map = new Array(height); - for (var y = 0; y <= height - 1; y++) { + for (y = 0; y <= height - 1; y++) { map[y] = new Array(width); - for (var x = 0; x <= width - 1; x++) { + for (x = 0; x <= width - 1; x++) { map[y][x] = util.feature[y][x]; } } @@ -243,32 +245,32 @@ var testAlgo; var marqueeColor = colorPalette.collection[algo.marqueeColorIndex][1]; var p = 0; // left - for (var y = 0; y < height; y++) { - var x = 0; + for (y = 0; y < height; y++) { + x = 0; if (util.lights[p] === 1) { map[y][x] = marqueeColor; } p += 1; } // bottom - for (var x = 1; x < width; x++) { - var y = height - 1; + for (x = 1; x < width; x++) { + y = height - 1; if (util.lights[p] === 1) { map[y][x] = marqueeColor; } p += 1; } // right - for (var y = height - 2; y >= 0; y--) { - var x = width - 1; + for (y = height - 2; y >= 0; y--) { + x = width - 1; if (util.lights[p] === 1) { map[y][x] = marqueeColor; } p += 1; } // top - for (var x = width - 2; x >= 0; x--) { - var y = 0; + for (x = width - 2; x >= 0; x--) { + y = 0; if (util.lights[p] === 1) { map[y][x] = marqueeColor; } diff --git a/resources/rgbscripts/marqueecolorsdirect.js b/resources/rgbscripts/marqueecolorsdirect.js index c010b82f4b..fd3c34dc0a 100644 --- a/resources/rgbscripts/marqueecolorsdirect.js +++ b/resources/rgbscripts/marqueecolorsdirect.js @@ -182,10 +182,12 @@ var testAlgo; }; util.getNextStep = function (width, height) { + var x = 0; + var y = 0; var map = new Array(height); - for (var y = 0; y <= height - 1; y++) { + for (y = 0; y <= height - 1; y++) { map[y] = new Array(width); - for (var x = 0; x <= width - 1; x++) { + for (x = 0; x <= width - 1; x++) { map[y][x] = util.feature[y][x]; } } @@ -204,32 +206,32 @@ var testAlgo; var marqueeColor = util.getRawColor(1); var p = 0; // left - for (var y = 0; y < height; y++) { - var x = 0; + for (y = 0; y < height; y++) { + x = 0; if (util.lights[p] === 1) { map[y][x] = marqueeColor; } p += 1; } // bottom - for (var x = 1; x < width; x++) { - var y = height - 1; + for (x = 1; x < width; x++) { + y = height - 1; if (util.lights[p] === 1) { map[y][x] = marqueeColor; } p += 1; } // right - for (var y = height - 2; y >= 0; y--) { - var x = width - 1; + for (y = height - 2; y >= 0; y--) { + x = width - 1; if (util.lights[p] === 1) { map[y][x] = marqueeColor; } p += 1; } // top - for (var x = width - 2; x >= 0; x--) { - var y = 0; + for (x = width - 2; x >= 0; x--) { + y = 0; if (util.lights[p] === 1) { map[y][x] = marqueeColor; } From 81ad09eb43a121d932235eb725ced315e660055f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Wed, 16 Oct 2024 21:06:22 +0200 Subject: [PATCH 47/63] Modify engine logic to support the separate color call. --- engine/src/rgbalgorithm.h | 6 ++- engine/src/rgbaudio.cpp | 8 +++- engine/src/rgbaudio.h | 5 ++- engine/src/rgbimage.cpp | 8 +++- engine/src/rgbimage.h | 5 ++- engine/src/rgbmatrix.cpp | 53 ++++++++++++++---------- engine/src/rgbmatrix.h | 3 ++ engine/src/rgbplain.cpp | 8 +++- engine/src/rgbplain.h | 5 ++- engine/src/rgbscript.cpp | 16 ++----- engine/src/rgbscript.h | 4 +- engine/src/rgbscriptv4.cpp | 16 ++----- engine/src/rgbscriptv4.h | 4 +- engine/src/rgbtext.cpp | 8 +++- engine/src/rgbtext.h | 5 ++- engine/test/rgbscript/rgbscript_test.cpp | 42 +++++++++++-------- engine/test/rgbtext/rgbtext_test.cpp | 37 ++++------------- 17 files changed, 120 insertions(+), 113 deletions(-) diff --git a/engine/src/rgbalgorithm.h b/engine/src/rgbalgorithm.h index ac8f3adf5c..8bd10c6904 100644 --- a/engine/src/rgbalgorithm.h +++ b/engine/src/rgbalgorithm.h @@ -74,9 +74,11 @@ class RGBAlgorithm /** Maximum step count for rgbMap() function. */ virtual int rgbMapStepCount(const QSize& size) = 0; + /** Set the colors for the RGBmap */ + virtual void rgbMapSetColors(QVector &colors) = 0; + /** Load a RGBMap for the given step. */ - virtual void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, - QVector &rawColors) = 0; + virtual void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) = 0; /** Release resources that may have been acquired in rgbMap() */ virtual void postRun() {} diff --git a/engine/src/rgbaudio.cpp b/engine/src/rgbaudio.cpp index 5c43457626..d6548e8186 100644 --- a/engine/src/rgbaudio.cpp +++ b/engine/src/rgbaudio.cpp @@ -123,10 +123,14 @@ int RGBAudio::rgbMapStepCount(const QSize& size) return 1; } -void RGBAudio::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors) +void RGBAudio::rgbMapSetColors(QVector &colors) +{ + Q_UNUSED(colors); +} + +void RGBAudio::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) { Q_UNUSED(step); - Q_UNUSED(rawColors); QMutexLocker locker(&m_mutex); diff --git a/engine/src/rgbaudio.h b/engine/src/rgbaudio.h index cb783cbd70..5769cc77b5 100644 --- a/engine/src/rgbaudio.h +++ b/engine/src/rgbaudio.h @@ -71,7 +71,10 @@ protected slots: int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors); + void rgbMapSetColors(QVector &colors); + + /** @reimp */ + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); /** @reimp */ virtual void postRun(); diff --git a/engine/src/rgbimage.cpp b/engine/src/rgbimage.cpp index a42e3fc8e4..a27e6318a3 100644 --- a/engine/src/rgbimage.cpp +++ b/engine/src/rgbimage.cpp @@ -235,10 +235,14 @@ int RGBImage::rgbMapStepCount(const QSize& size) } } -void RGBImage::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors) +void RGBImage::rgbMapSetColors(QVector &colors) +{ + Q_UNUSED(colors); +} + +void RGBImage::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) { Q_UNUSED(rgb); - Q_UNUSED(rawColors); QMutexLocker locker(&m_mutex); diff --git a/engine/src/rgbimage.h b/engine/src/rgbimage.h index fce605507e..d4c4a30f7a 100644 --- a/engine/src/rgbimage.h +++ b/engine/src/rgbimage.h @@ -103,7 +103,10 @@ class RGBImage : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors); + void rgbMapSetColors(QVector &colors); + + /** @reimp */ + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); /** @reimp */ QString name() const; diff --git a/engine/src/rgbmatrix.cpp b/engine/src/rgbmatrix.cpp index 7089aa87cc..447efacfb5 100644 --- a/engine/src/rgbmatrix.cpp +++ b/engine/src/rgbmatrix.cpp @@ -291,17 +291,8 @@ void RGBMatrix::previewMap(int step, RGBMatrixStep *handler) m_group = doc()->fixtureGroup(fixtureGroup()); if (m_group != NULL) { - int accColors = m_algorithm->acceptColors(); - QVector rawColors; - rawColors.resize(accColors); - QVectorIterator it(m_rgbColors); - int count = 0; - while (it.hasNext() && count < accColors) { - QColor color = it.next(); - rawColors.replace(count, color.isValid() ? color.rgb() : 0); - count ++; - }; - m_algorithm->rgbMap(m_group->size(), handler->stepColor().rgb(), step, handler->m_map, rawColors); + + m_algorithm->rgbMap(m_group->size(), handler->stepColor().rgb(), step, handler->m_map); } } @@ -322,6 +313,7 @@ void RGBMatrix::setColor(int i, QColor c) updateColorDelta(); } } + setMapColors(); emit changed(id()); } @@ -342,6 +334,33 @@ void RGBMatrix::updateColorDelta() m_stepHandler->calculateColorDelta(m_rgbColors[0], m_rgbColors[1], m_algorithm); } +void RGBMatrix::setMapColors() +{ + QMutexLocker algorithmLocker(&m_algorithmMutex); + if (m_algorithm == NULL) + return; + + if (m_algorithm->apiVersion() < 3) + return; + + if (m_group == NULL) + m_group = doc()->fixtureGroup(fixtureGroup()); + + if (m_group != NULL) { + QVector rawColors; + int accColors = m_algorithm->acceptColors(); + rawColors.resize(accColors); + QVectorIterator it(m_rgbColors); + int count = 0; + while (it.hasNext() && count < accColors) { + QColor color = it.next(); + rawColors.replace(count, color.isValid() ? color.rgb() : 0); + count ++; + }; + m_algorithm->rgbMapSetColors(rawColors); + }; +} + /************************************************************************ * Properties ************************************************************************/ @@ -601,19 +620,9 @@ void RGBMatrix::write(MasterTimer *timer, QList universes) if (tempoType() == Beats) m_stepBeatDuration = beatsToTime(duration(), timer->beatTimeDuration()); - int accColors = m_algorithm->acceptColors(); - QVector rawColors; - rawColors.resize(accColors); - QVectorIterator it(m_rgbColors); - int count = 0; - while (it.hasNext() && count < accColors) { - QColor color = it.next(); - rawColors.replace(count, color.isValid() ? color.rgb() : 0); - count ++; - }; //qDebug() << "RGBMatrix step" << m_stepHandler->currentStepIndex() << ", color:" << QString::number(m_stepHandler->stepColor().rgb(), 16); m_algorithm->rgbMap(m_group->size(), m_stepHandler->stepColor().rgb(), - m_stepHandler->currentStepIndex(), m_stepHandler->m_map, rawColors); + m_stepHandler->currentStepIndex(), m_stepHandler->m_map); updateMapChannels(m_stepHandler->m_map, m_group, universes); } } diff --git a/engine/src/rgbmatrix.h b/engine/src/rgbmatrix.h index ebfa989f25..52ebaafc28 100644 --- a/engine/src/rgbmatrix.h +++ b/engine/src/rgbmatrix.h @@ -194,6 +194,9 @@ class RGBMatrix : public Function void updateColorDelta(); + /** Set the colors of the current algorithm */ + void setMapColors(); + private: QVector m_rgbColors; RGBMatrixStep *m_stepHandler; diff --git a/engine/src/rgbplain.cpp b/engine/src/rgbplain.cpp index 3a1dd1b842..17d2ae1a4d 100644 --- a/engine/src/rgbplain.cpp +++ b/engine/src/rgbplain.cpp @@ -55,10 +55,14 @@ int RGBPlain::rgbMapStepCount(const QSize& size) return 1; } -void RGBPlain::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors) +void RGBPlain::rgbMapSetColors(QVector &colors) +{ + Q_UNUSED(colors); +} + +void RGBPlain::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) { Q_UNUSED(step); - Q_UNUSED(rawColors); map.resize(size.height()); for (int y = 0; y < size.height(); y++) { diff --git a/engine/src/rgbplain.h b/engine/src/rgbplain.h index a2d88116c9..526fccd0b5 100644 --- a/engine/src/rgbplain.h +++ b/engine/src/rgbplain.h @@ -50,7 +50,10 @@ class RGBPlain : public QObject, public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors); + void rgbMapSetColors(QVector &colors); + + /** @reimp */ + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); /** @reimp */ QString name() const; diff --git a/engine/src/rgbscript.cpp b/engine/src/rgbscript.cpp index 135d71c5f0..0a12843be1 100644 --- a/engine/src/rgbscript.cpp +++ b/engine/src/rgbscript.cpp @@ -260,7 +260,7 @@ int RGBScript::rgbMapStepCount(const QSize& size) } } -void RGBScript::rgbMapSetColors(QVector colors) +void RGBScript::rgbMapSetColors(QVector &colors) { QMutexLocker engineLocker(s_engineMutex); if (m_apiVersion <= 2) @@ -282,7 +282,7 @@ void RGBScript::rgbMapSetColors(QVector colors) displayError(value, m_fileName); } -void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors) +void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) { QMutexLocker engineLocker(s_engineMutex); @@ -290,18 +290,8 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVect return; QScriptValueList args; - if (m_apiVersion <= 2) { - args << size.width() << size.height() << rgb << step; - } else { - int accColors = acceptColors(); - int rawColorCount = rawColors.count(); - QScriptValue jsRawColors = s_engine->newArray(accColors); - for (int i = 0; i < rawColorCount && i < accColors; i++) { - jsRawColors.setProperty(i, QScriptValue(rawColors.at(i))); - } + args << size.width() << size.height() << rgb << step; - args << size.width() << size.height() << rgb << step << jsRawColors; - } QScriptValue yarray = m_rgbMap.call(QScriptValue(), args); if (yarray.isError()) diff --git a/engine/src/rgbscript.h b/engine/src/rgbscript.h index 9e7e292fc4..930c028a7e 100644 --- a/engine/src/rgbscript.h +++ b/engine/src/rgbscript.h @@ -91,10 +91,10 @@ class RGBScript : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMapSetColors(QVector colors); + void rgbMapSetColors(QVector &colors); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); /** @reimp */ QString name() const; diff --git a/engine/src/rgbscriptv4.cpp b/engine/src/rgbscriptv4.cpp index b542ffd9a8..1c41efa73a 100644 --- a/engine/src/rgbscriptv4.cpp +++ b/engine/src/rgbscriptv4.cpp @@ -244,7 +244,7 @@ int RGBScript::rgbMapStepCount(const QSize& size) } } -void RGBScript::rgbMapSetColors(QVector colors) +void RGBScript::rgbMapSetColors(QVector &colors) { QMutexLocker engineLocker(s_engineMutex); if (m_apiVersion <= 2) @@ -268,7 +268,7 @@ void RGBScript::rgbMapSetColors(QVector colors) displayError(value, m_fileName); } -void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors) +void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) { QMutexLocker engineLocker(s_engineMutex); @@ -277,18 +277,8 @@ void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVect // Call the rgbMap function QJSValueList args; - if (m_apiVersion <= 2) { - args << size.width() << size.height() << rgb << step; - } else { - int accColors = acceptColors(); - int rawColorCount = rawColors.count(); - QJSValue jsRawColors = s_engine->newArray(); - for (int i = 0; i < rawColorCount && i < accColors; i++) { - jsRawColors.setProperty(i, QJSValue(rawColors.at(i)));; - } + args << size.width() << size.height() << rgb << step; - args << size.width() << size.height() << rgb << step << jsRawColors; - } QJSValue yarray(m_rgbMap.call(args)); if (yarray.isError()) displayError(yarray, m_fileName); diff --git a/engine/src/rgbscriptv4.h b/engine/src/rgbscriptv4.h index c0e3418585..bdb189f67f 100644 --- a/engine/src/rgbscriptv4.h +++ b/engine/src/rgbscriptv4.h @@ -92,10 +92,10 @@ class RGBScript : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMapSetColors(QVector colors); + void rgbMapSetColors(QVector &colors); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors); + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); /** @reimp */ QString name() const; diff --git a/engine/src/rgbtext.cpp b/engine/src/rgbtext.cpp index 42b76cd7de..33b1ddd90a 100644 --- a/engine/src/rgbtext.cpp +++ b/engine/src/rgbtext.cpp @@ -266,9 +266,13 @@ int RGBText::rgbMapStepCount(const QSize& size) return scrollingTextStepCount(); } -void RGBText::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors) +void RGBText::rgbMapSetColors(QVector &colors) +{ + Q_UNUSED(colors); +} + +void RGBText::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) { - Q_UNUSED(rawColors); if (animationStyle() == StaticLetters) renderStaticLetters(size, rgb, step, map); else diff --git a/engine/src/rgbtext.h b/engine/src/rgbtext.h index 5c58c23bfb..b49faeb100 100644 --- a/engine/src/rgbtext.h +++ b/engine/src/rgbtext.h @@ -99,7 +99,10 @@ class RGBText : public RGBAlgorithm int rgbMapStepCount(const QSize& size); /** @reimp */ - void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map, QVector &rawColors); + void rgbMapSetColors(QVector &colors); + + /** @reimp */ + void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); /** @reimp */ QString name() const; diff --git a/engine/test/rgbscript/rgbscript_test.cpp b/engine/test/rgbscript/rgbscript_test.cpp index ac96cb4e15..b771bbaf2e 100644 --- a/engine/test/rgbscript/rgbscript_test.cpp +++ b/engine/test/rgbscript/rgbscript_test.cpp @@ -175,11 +175,7 @@ void RGBScript_Test::evaluateNoRgbMapFunction() RGBMap map; s.m_contents = code; QCOMPARE(s.evaluate(), false); - QVector rawRgbColors = { - QColor(Qt::red).rgb(), - QColor(Qt::green).rgb() - }; - s.rgbMap(QSize(5, 5), 1, 0, map, rawRgbColors); + s.rgbMap(QSize(5, 5), 1, 0, map); QCOMPARE(map, RGBMap()); } @@ -211,7 +207,7 @@ void RGBScript_Test::rgbMapStepCount() void RGBScript_Test::rgbMapColorArray() { RGBMap map; - RGBScript s = m_doc->rgbScriptsCache()->script("Alternate"); + RGBScript s = m_doc->rgbScriptsCache()->script("Alternate (2 Colors)"); QCOMPARE(s.evaluate(), true); QVector rawRgbColors = { QColor(Qt::red).rgb() & 0x00ffffff, @@ -219,7 +215,8 @@ void RGBScript_Test::rgbMapColorArray() }; QSize mapSize = QSize(5, 5); qDebug() << "C1: " << Qt::hex << rawRgbColors[0] << " C2: " << Qt::hex << rawRgbColors[1]; - s.rgbMap(mapSize, 0, 0, map, rawRgbColors); + s.rgbMapSetColors(rawRgbColors); + s.rgbMap(mapSize, 0, 0, map); QVERIFY(map.isEmpty() == false); // check that both initial colors are used in the same step @@ -244,7 +241,7 @@ void RGBScript_Test::rgbMap() QColor(Qt::red).rgb(), uint(0) }; - s.rgbMap(QSize(3, 4), 0, 0, map, rawRgbColors); + s.rgbMap(QSize(3, 4), 0, 0, map); // verify that an array within an array has been returned QVERIFY(map.isEmpty() == false); @@ -254,7 +251,7 @@ void RGBScript_Test::rgbMap() for (int step = 0; step < 5; step++) { RGBMap map; - s.rgbMap(QSize(5, 5), rawRgbColors[0], step, map, rawRgbColors); + s.rgbMap(QSize(5, 5), rawRgbColors[0], step, map); for (int y = 0; y < 5; y++) { for (int x = 0; x < 5; x++) @@ -312,7 +309,8 @@ void RGBScript_Test::runScripts() { // limit the scope of this map to keep it clean for future executions RGBMap map; - s.rgbMap(mapSize, 0, 0, map, rawRgbColors); + s.rgbMapSetColors(rawRgbColors); + s.rgbMap(mapSize, 0, 0, map); QVERIFY(map.isEmpty() == false); } @@ -334,7 +332,8 @@ void RGBScript_Test::runScripts() RGBMap rgbMap; for (int step = 0; step < realsteps; step++) { - s.rgbMap(mapSize, rawRgbColors[0], step, rgbMap, rawRgbColors); + s.rgbMapSetColors(rawRgbColors); + s.rgbMap(mapSize, rawRgbColors[0], step, rgbMap); QVERIFY(rgbMap.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) @@ -356,12 +355,14 @@ void RGBScript_Test::runScripts() RGBMap rgbRefMap; if (1 < s.acceptColors() && 2 < steps && ! randomScript) { // When more than 2 colors are accepted, the steps shall be reproducible to allow back and forth color fade. - s.rgbMap(mapSizePlus, rawRgbColors[0], 0, rgbRefMap, rawRgbColors); + s.rgbMapSetColors(rawRgbColors); + s.rgbMap(mapSizePlus, rawRgbColors[0], 0, rgbRefMap); } // Switch to the larger map and step a few times. for (int step = 0; step < realsteps; step++) { - s.rgbMap(mapSizePlus, rawRgbColors[0], step, rgbMap, rawRgbColors); + s.rgbMapSetColors(rawRgbColors); + s.rgbMap(mapSizePlus, rawRgbColors[0], step, rgbMap); // Check that the color values are limited to a valid range for (int y = 0; y < mapSizePlus.height(); y++) { @@ -435,7 +436,8 @@ void RGBScript_Test::runScripts() for (int step = 0; step < realsteps; step++) { RGBMap map; - s.rgbMap(mapSize, rawRgbColors[0], step, map, rawRgbColors); + s.rgbMapSetColors(rawRgbColors); + s.rgbMap(mapSize, rawRgbColors[0], step, map); QVERIFY(map.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) @@ -464,7 +466,8 @@ void RGBScript_Test::runScripts() for (int step = 0; step < realsteps; step++) { RGBMap map; - s.rgbMap(mapSize, rawRgbColors[0], step, map, rawRgbColors); + s.rgbMapSetColors(rawRgbColors); + s.rgbMap(mapSize, rawRgbColors[0], step, map); QVERIFY(map.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) @@ -482,7 +485,8 @@ void RGBScript_Test::runScripts() for (int step = 0; step < realsteps; step++) { RGBMap map; - s.rgbMap(mapSize, rawRgbColors[0], step, map, rawRgbColors); + s.rgbMapSetColors(rawRgbColors); + s.rgbMap(mapSize, rawRgbColors[0], step, map); QVERIFY(map.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) @@ -502,7 +506,8 @@ void RGBScript_Test::runScripts() for (int step = 0; step < realsteps; step++) { RGBMap map; - s.rgbMap(mapSize, rawRgbColors[0], step, map, rawRgbColors); + s.rgbMapSetColors(rawRgbColors); + s.rgbMap(mapSize, rawRgbColors[0], step, map); QVERIFY(map.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) @@ -522,7 +527,8 @@ void RGBScript_Test::runScripts() for (int step = 0; step < realsteps; step++) { RGBMap map; - s.rgbMap(mapSize, rawRgbColors[0], step, map, rawRgbColors); + s.rgbMapSetColors(rawRgbColors); + s.rgbMap(mapSize, rawRgbColors[0], step, map); QVERIFY(map.isEmpty() == false); // Check that the color values are limited to a valid range for (int y = 0; y < mapSize.height(); y++) diff --git a/engine/test/rgbtext/rgbtext_test.cpp b/engine/test/rgbtext/rgbtext_test.cpp index bccf54e2c5..73a09cbc40 100644 --- a/engine/test/rgbtext/rgbtext_test.cpp +++ b/engine/test/rgbtext/rgbtext_test.cpp @@ -324,35 +324,28 @@ void RGBText_Test::staticLetters() QRgb color(0xFFFFFFFF); RGBMap map; - QVector rawRgbColors = { - QColor(Qt::red).rgb() - ,QColor(Qt::green).rgb() - ,0 - ,0 - ,0 - }; // Since fonts and their rendering differs from installation to installation, // these tests are here only to check that nothing crashes. The end result is // more or less OS, platform, HW and SW dependent and testing individual pixels // would thus be rather pointless. - text.rgbMap(QSize(10, 10), color, 0, map, rawRgbColors); + text.rgbMap(QSize(10, 10), color, 0, map); QCOMPARE(map.size(), 10); for (int i = 0; i < 10; i++) QCOMPARE(map[i].size(), 10); - text.rgbMap(QSize(10, 10), color, 1, map, rawRgbColors); + text.rgbMap(QSize(10, 10), color, 1, map); QCOMPARE(map.size(), 10); for (int i = 0; i < 10; i++) QCOMPARE(map[i].size(), 10); - text.rgbMap(QSize(10, 10), color, 2, map, rawRgbColors); + text.rgbMap(QSize(10, 10), color, 2, map); QCOMPARE(map.size(), 10); for (int i = 0; i < 10; i++) QCOMPARE(map[i].size(), 10); // Invalid step - text.rgbMap(QSize(10, 10), color, 3, map, rawRgbColors); + text.rgbMap(QSize(10, 10), color, 3, map); QCOMPARE(map.size(), 10); for (int i = 0; i < 10; i++) { @@ -369,13 +362,6 @@ void RGBText_Test::horizontalScroll() RGBText text(m_doc); text.setText("QLC"); text.setAnimationStyle(RGBText::Horizontal); - QVector rawRgbColors = { - QColor(Qt::red).rgb() - ,QColor(Qt::green).rgb() - ,0 - ,0 - ,0 - }; QFontMetrics fm(text.font()); #if (QT_VERSION < QT_VERSION_CHECK(5, 11, 0)) @@ -395,7 +381,7 @@ void RGBText_Test::horizontalScroll() #endif { RGBMap map; - text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), i, map, rawRgbColors); + text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), i, map); QCOMPARE(map.size(), 10); for (int y = 0; y < 10; y++) QCOMPARE(map[y].size(), 10); @@ -406,7 +392,7 @@ void RGBText_Test::horizontalScroll() #if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0)) text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), fm.width("QLC"), map, rawRgbColors); #else - text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), fm.horizontalAdvance("QLC"), map, rawRgbColors); + text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), fm.horizontalAdvance("QLC"), map); #endif QCOMPARE(map.size(), 10); for (int i = 0; i < 10; i++) @@ -424,13 +410,6 @@ void RGBText_Test::verticalScroll() RGBText text(m_doc); text.setText("QLC"); text.setAnimationStyle(RGBText::Vertical); - QVector rawRgbColors = { - QColor(Qt::red).rgb() - ,QColor(Qt::green).rgb() - ,0 - ,0 - ,0 - }; QFontMetrics fm(text.font()); QCOMPARE(text.rgbMapStepCount(QSize()), fm.ascent() * 3); // Q, L, C @@ -442,7 +421,7 @@ void RGBText_Test::verticalScroll() for (int i = 0; i < fm.ascent() * 3; i++) { RGBMap map; - text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), i, map, rawRgbColors); + text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), i, map); QCOMPARE(map.size(), 10); for (int y = 0; y < 10; y++) QCOMPARE(map[y].size(), 10); @@ -450,7 +429,7 @@ void RGBText_Test::verticalScroll() // Invalid step RGBMap map; - text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), fm.ascent() * 4, map, rawRgbColors); + text.rgbMap(QSize(10, 10), QRgb(0xFFFFFFFF), fm.ascent() * 4, map); QCOMPARE(map.size(), 10); for (int i = 0; i < 10; i++) { From 6cd67bd387a727d47ff74c4fdb11904727d42bda Mon Sep 17 00:00:00 2001 From: Massimo Callegari Date: Thu, 24 Oct 2024 16:55:33 +0200 Subject: [PATCH 48/63] engine: add rgbMapGetColors to RGBAlgorithm In this way the UI can dinamycally load colors from scripts depending on presets (see updated plasma.js) Reviewed inefficient code blocks. On XML save "Color" tag + index attribute rather than changing tags (Color1, Color2, etc) --- engine/src/rgbalgorithm.h | 3 ++ engine/src/rgbaudio.cpp | 5 ++ engine/src/rgbaudio.h | 3 ++ engine/src/rgbimage.cpp | 5 ++ engine/src/rgbimage.h | 3 ++ engine/src/rgbmatrix.cpp | 74 +++++++++++++------------- engine/src/rgbplain.cpp | 5 ++ engine/src/rgbplain.h | 3 ++ engine/src/rgbscript.cpp | 28 ++++++++++ engine/src/rgbscript.h | 4 ++ engine/src/rgbscriptv4.cpp | 19 +++++++ engine/src/rgbscriptv4.h | 4 ++ engine/src/rgbtext.cpp | 5 ++ engine/src/rgbtext.h | 3 ++ resources/rgbscripts/plasma.js | 73 +++++++++++++++++++------- ui/src/rgbmatrixeditor.cpp | 95 +++++++--------------------------- ui/src/rgbmatrixeditor.h | 1 + 17 files changed, 201 insertions(+), 132 deletions(-) diff --git a/engine/src/rgbalgorithm.h b/engine/src/rgbalgorithm.h index 8bd10c6904..47214bdcfa 100644 --- a/engine/src/rgbalgorithm.h +++ b/engine/src/rgbalgorithm.h @@ -77,6 +77,9 @@ class RGBAlgorithm /** Set the colors for the RGBmap */ virtual void rgbMapSetColors(QVector &colors) = 0; + /** Get the colors from the RGB script */ + virtual QVector rgbMapGetColors() = 0; + /** Load a RGBMap for the given step. */ virtual void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) = 0; diff --git a/engine/src/rgbaudio.cpp b/engine/src/rgbaudio.cpp index d6548e8186..817b4be649 100644 --- a/engine/src/rgbaudio.cpp +++ b/engine/src/rgbaudio.cpp @@ -128,6 +128,11 @@ void RGBAudio::rgbMapSetColors(QVector &colors) Q_UNUSED(colors); } +QVector RGBAudio::rgbMapGetColors() +{ + return QVector(); +} + void RGBAudio::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) { Q_UNUSED(step); diff --git a/engine/src/rgbaudio.h b/engine/src/rgbaudio.h index 5769cc77b5..a8ea5742ae 100644 --- a/engine/src/rgbaudio.h +++ b/engine/src/rgbaudio.h @@ -73,6 +73,9 @@ protected slots: /** @reimp */ void rgbMapSetColors(QVector &colors); + /** @reimp */ + QVector rgbMapGetColors(); + /** @reimp */ void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); diff --git a/engine/src/rgbimage.cpp b/engine/src/rgbimage.cpp index a27e6318a3..114c0e62d5 100644 --- a/engine/src/rgbimage.cpp +++ b/engine/src/rgbimage.cpp @@ -240,6 +240,11 @@ void RGBImage::rgbMapSetColors(QVector &colors) Q_UNUSED(colors); } +QVector RGBImage::rgbMapGetColors() +{ + return QVector(); +} + void RGBImage::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) { Q_UNUSED(rgb); diff --git a/engine/src/rgbimage.h b/engine/src/rgbimage.h index d4c4a30f7a..96042e6186 100644 --- a/engine/src/rgbimage.h +++ b/engine/src/rgbimage.h @@ -105,6 +105,9 @@ class RGBImage : public RGBAlgorithm /** @reimp */ void rgbMapSetColors(QVector &colors); + /** @reimp */ + QVector rgbMapGetColors(); + /** @reimp */ void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); diff --git a/engine/src/rgbmatrix.cpp b/engine/src/rgbmatrix.cpp index 0873a77998..5919c8bfd6 100644 --- a/engine/src/rgbmatrix.cpp +++ b/engine/src/rgbmatrix.cpp @@ -36,7 +36,8 @@ #define KXMLQLCRGBMatrixStartColor QString("MonoColor") #define KXMLQLCRGBMatrixEndColor QString("EndColor") -#define KXMLQLCRGBMatrixColorBase QString("Color") +#define KXMLQLCRGBMatrixColor QString("Color") +#define KXMLQLCRGBMatrixColorIndex QString("Index") #define KXMLQLCRGBMatrixFixtureGroup QString("FixtureGroup") #define KXMLQLCRGBMatrixDimmerControl QString("DimmerControl") @@ -66,13 +67,6 @@ RGBMatrix::RGBMatrix(Doc* doc) #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) , m_algorithmMutex(QMutex::Recursive) #endif - , m_rgbColors{ - Qt::red, - QColor(), - QColor(), - QColor(), - QColor() - } , m_stepHandler(new RGBMatrixStep()) , m_roundTime(new QElapsedTimer()) , m_stepsCount(0) @@ -82,6 +76,9 @@ RGBMatrix::RGBMatrix(Doc* doc) setName(tr("New RGB Matrix")); setDuration(500); + m_rgbColors.fill(QColor(), RGBAlgorithmColorDisplayCount); + setColor(0, Qt::red); + RGBScript scr = doc->rgbScriptsCache()->script("Stripes"); setAlgorithm(scr.clone()); } @@ -169,19 +166,14 @@ bool RGBMatrix::copyFrom(const Function* function) setDimmerControl(mtx->dimmerControl()); setFixtureGroup(mtx->fixtureGroup()); + foreach (QColor col, mtx->getColors()) + m_rgbColors.append(col); + if (mtx->algorithm() != NULL) setAlgorithm(mtx->algorithm()->clone()); else setAlgorithm(NULL); - QVectorIterator it(mtx->getColors()); - uint count = 0; - while (it.hasNext()) { - QColor color = it.next(); - setColor(count, color); - count ++; - } - setControlMode(mtx->controlMode()); return Function::copyFrom(function); @@ -303,8 +295,12 @@ void RGBMatrix::previewMap(int step, RGBMatrixStep *handler) void RGBMatrix::setColor(int i, QColor c) { + if (i < 0) + return; + if (i >= m_rgbColors.count()) m_rgbColors.resize(i + 1); + m_rgbColors.replace(i, c); { QMutexLocker algorithmLocker(&m_algorithmMutex); @@ -320,8 +316,9 @@ void RGBMatrix::setColor(int i, QColor c) QColor RGBMatrix::getColor(int i) const { - if (i >= m_rgbColors.count()) + if (i < 0 || i >= m_rgbColors.count()) return QColor(); + return m_rgbColors.at(i); } @@ -347,19 +344,17 @@ void RGBMatrix::setMapColors() if (m_group == NULL) m_group = doc()->fixtureGroup(fixtureGroup()); - if (m_group != NULL) { + if (m_group != NULL) + { QVector rawColors; - int accColors = m_algorithm->acceptColors(); - rawColors.resize(accColors); - QVectorIterator it(m_rgbColors); - int count = 0; - while (it.hasNext() && count < accColors) { - QColor color = it.next(); - rawColors.replace(count, color.isValid() ? color.rgb() : 0); - count ++; - }; + for (int i = 0; i < m_algorithm->acceptColors(); i++) + { + QColor col = m_rgbColors.at(i); + rawColors.append(col.isValid() ? col.rgb() : 0); + } + m_algorithm->rgbMapSetColors(rawColors); - }; + } } /************************************************************************ @@ -374,6 +369,10 @@ void RGBMatrix::setProperty(QString propName, QString value) { RGBScript *script = static_cast (m_algorithm); script->setProperty(propName, value); + + QVector colors = script->rgbMapGetColors(); + for (int i = 0; i < colors.count(); i++) + setColor(i, QColor::fromRgb(colors.at(i))); } m_stepsCount = stepsCount(); } @@ -446,11 +445,9 @@ bool RGBMatrix::loadXML(QXmlStreamReader &root) { setColor(1, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); } - else if (root.name().startsWith(KXMLQLCRGBMatrixColorBase, Qt::CaseSensitive)) + else if (root.name() == KXMLQLCRGBMatrixColor) { - QString colorNumText = root.name().string()->right( - root.name().length() - KXMLQLCRGBMatrixColorBase.length()); - uint colorIdx = colorNumText.toUInt() - 1; + int colorIdx = root.attributes().value(KXMLQLCRGBMatrixColorIndex).toInt(); setColor(colorIdx, QColor::fromRgb(QRgb(root.readElementText().toUInt()))); } else if (root.name() == KXMLQLCRGBMatrixControlMode) @@ -506,13 +503,12 @@ bool RGBMatrix::saveXML(QXmlStreamWriter *doc) doc->writeTextElement(KXMLQLCRGBMatrixDimmerControl, QString::number(dimmerControl())); /* Colors */ - QVectorIterator colorIt(m_rgbColors); - uint count = 0; - while (colorIt.hasNext()) { - QColor color = colorIt.next(); - QString elementName = KXMLQLCRGBMatrixColorBase.append(QString::number(count + 1)); - doc->writeTextElement(elementName, QString::number(color.rgb())); - count ++; + for (int i = 0; i < m_rgbColors.count(); i++) + { + doc->writeStartElement(KXMLQLCRGBMatrixColor); + doc->writeAttribute(KXMLQLCRGBMatrixColorIndex, QString::number(i)); + doc->writeCharacters(QString::number(m_rgbColors.at(i).rgb())); + doc->writeEndElement(); } /* Control Mode */ diff --git a/engine/src/rgbplain.cpp b/engine/src/rgbplain.cpp index 17d2ae1a4d..5a43f630a8 100644 --- a/engine/src/rgbplain.cpp +++ b/engine/src/rgbplain.cpp @@ -60,6 +60,11 @@ void RGBPlain::rgbMapSetColors(QVector &colors) Q_UNUSED(colors); } +QVector RGBPlain::rgbMapGetColors() +{ + return QVector(); +} + void RGBPlain::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) { Q_UNUSED(step); diff --git a/engine/src/rgbplain.h b/engine/src/rgbplain.h index 526fccd0b5..1624b4193a 100644 --- a/engine/src/rgbplain.h +++ b/engine/src/rgbplain.h @@ -52,6 +52,9 @@ class RGBPlain : public QObject, public RGBAlgorithm /** @reimp */ void rgbMapSetColors(QVector &colors); + /** @reimp */ + QVector rgbMapGetColors(); + /** @reimp */ void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); diff --git a/engine/src/rgbscript.cpp b/engine/src/rgbscript.cpp index 0a12843be1..755bd7a382 100644 --- a/engine/src/rgbscript.cpp +++ b/engine/src/rgbscript.cpp @@ -194,6 +194,11 @@ bool RGBScript::evaluate() qWarning() << m_fileName << "is missing the rgbMapSetColors() function!"; return false; } + + // retrieve the non-mandatory get color function + m_rgbMapGetColors = m_script.property("rgbMapGetColors"); + if (m_rgbMapGetColors.isFunction() == false) + qWarning() << m_fileName << "is missing the rgbMapGetColors() function!"; } if (m_apiVersion >= 2) return loadProperties(); @@ -265,6 +270,7 @@ void RGBScript::rgbMapSetColors(QVector &colors) QMutexLocker engineLocker(s_engineMutex); if (m_apiVersion <= 2) return; + if (m_rgbMapSetColors.isValid() == false) return; @@ -282,6 +288,28 @@ void RGBScript::rgbMapSetColors(QVector &colors) displayError(value, m_fileName); } +QVector RGBScript::rgbMapGetColors() +{ + QMutexLocker engineLocker(s_engineMutex); + QVector colArray; + + if (m_apiVersion <= 2) + return colArray; + + if (m_rgbMapGetColors.isValid() == false) + return colArray; + + QScriptValue colors = m_rgbMapGetColors.call(); + if (colors.isValid() && colors.isArray()) + { + QVariantList arr = colors.toVariant().toList(); + foreach (QVariant color, arr) + colArray.append(color.toUInt()); + } + + return colArray; +} + void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) { QMutexLocker engineLocker(s_engineMutex); diff --git a/engine/src/rgbscript.h b/engine/src/rgbscript.h index 930c028a7e..b05c6e93b5 100644 --- a/engine/src/rgbscript.h +++ b/engine/src/rgbscript.h @@ -93,6 +93,9 @@ class RGBScript : public RGBAlgorithm /** @reimp */ void rgbMapSetColors(QVector &colors); + /** @reimp */ + QVector rgbMapGetColors(); + /** @reimp */ void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); @@ -123,6 +126,7 @@ class RGBScript : public RGBAlgorithm QScriptValue m_rgbMap; //! rgbMap() function QScriptValue m_rgbMapStepCount; //! rgbMapStepCount() function QScriptValue m_rgbMapSetColors; //! rgbMapSetColors() function + QScriptValue m_rgbMapGetColors; //! rgbMapSetColors() function /************************************************************************ * Properties diff --git a/engine/src/rgbscriptv4.cpp b/engine/src/rgbscriptv4.cpp index 1c41efa73a..93242b762e 100644 --- a/engine/src/rgbscriptv4.cpp +++ b/engine/src/rgbscriptv4.cpp @@ -268,6 +268,25 @@ void RGBScript::rgbMapSetColors(QVector &colors) displayError(value, m_fileName); } +QVector RGBScript::rgbMapGetColors() +{ + QMutexLocker engineLocker(s_engineMutex); + QVector colArray; + + if (m_rgbMap.isUndefined() == true) + return colArray; + + QJSValue colors = m_rgbMapGetColors.call(); + if (colors.isValid() && colors.isArray()) + { + QVariantList arr = colors.toVariant().toList(); + foreach (QVariant color, arr) + colArray.append(color.toUInt()); + } + + return colArray; +} + void RGBScript::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) { QMutexLocker engineLocker(s_engineMutex); diff --git a/engine/src/rgbscriptv4.h b/engine/src/rgbscriptv4.h index bdb189f67f..4e1fcee93a 100644 --- a/engine/src/rgbscriptv4.h +++ b/engine/src/rgbscriptv4.h @@ -94,6 +94,9 @@ class RGBScript : public RGBAlgorithm /** @reimp */ void rgbMapSetColors(QVector &colors); + /** @reimp */ + QVector rgbMapGetColors(); + /** @reimp */ void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); @@ -124,6 +127,7 @@ class RGBScript : public RGBAlgorithm QJSValue m_rgbMap; //! rgbMap() function QJSValue m_rgbMapStepCount; //! rgbMapStepCount() function QJSValue m_rgbMapSetColors; //! rgbMapSetColors() function + QJSValue m_rgbMapGetColors; //! rgbMapSetColors() function /************************************************************************ * Properties diff --git a/engine/src/rgbtext.cpp b/engine/src/rgbtext.cpp index 33b1ddd90a..d4d13f0fad 100644 --- a/engine/src/rgbtext.cpp +++ b/engine/src/rgbtext.cpp @@ -271,6 +271,11 @@ void RGBText::rgbMapSetColors(QVector &colors) Q_UNUSED(colors); } +QVector RGBText::rgbMapGetColors() +{ + return QVector(); +} + void RGBText::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map) { if (animationStyle() == StaticLetters) diff --git a/engine/src/rgbtext.h b/engine/src/rgbtext.h index b49faeb100..2e4d5cafcc 100644 --- a/engine/src/rgbtext.h +++ b/engine/src/rgbtext.h @@ -101,6 +101,9 @@ class RGBText : public RGBAlgorithm /** @reimp */ void rgbMapSetColors(QVector &colors); + /** @reimp */ + QVector rgbMapGetColors(); + /** @reimp */ void rgbMap(const QSize& size, uint rgb, int step, RGBMap &map); diff --git a/resources/rgbscripts/plasma.js b/resources/rgbscripts/plasma.js index c2afb92c6a..ac9c0f994d 100644 --- a/resources/rgbscripts/plasma.js +++ b/resources/rgbscripts/plasma.js @@ -24,9 +24,9 @@ var testAlgo; function() { var algo = new Object; - algo.apiVersion = 2; + algo.apiVersion = 3; algo.name = "Plasma"; - algo.author = "Tim Cullingworth"; + algo.author = "Tim Cullingworth, Massimo Callegari"; algo.acceptColors = 0; algo.properties = new Array(); algo.rstepcount = 0; @@ -35,7 +35,7 @@ var testAlgo; algo.presetIndex = 0; algo.properties.push( "name:presetIndex|type:list|display:Preset|" + - "values:Rainbow,Fire,Abstract,Ocean|" + + "values:Rainbow,Fire,Abstract,Ocean,User Defined|" + "write:setPreset|read:getPreset"); algo.presetSize = 5; algo.properties.push( @@ -53,18 +53,37 @@ var testAlgo; var util = new Object; util.initialized = false; util.gradientData = new Array(); - util.presets = new Array(); - util.presets.push(new Array(0xFF0000, 0x00FF00, 0x0000FF)); - util.presets.push(new Array(0xFFFF00, 0xFF0000, 0x000040, 0xFF0000)); - util.presets.push(new Array(0x5571FF, 0x00FFFF, 0xFF00FF, 0xFFFF00)); - util.presets.push(new Array(0x003AB9, 0x02EAFF)); + util.colorArray = new Array(); algo.setPreset = function(_preset) { - if (_preset === "Rainbow") { algo.presetIndex = 0; } - else if (_preset === "Fire") { algo.presetIndex = 1; } - else if (_preset === "Abstract") { algo.presetIndex = 2; } - else if (_preset === "Ocean") { algo.presetIndex = 3; } + algo.acceptColors = 0; + if (_preset === "Rainbow") + { + algo.presetIndex = 0; + util.colorArray = [ 0xFF0000, 0x00FF00, 0x0000FF ]; + } + else if (_preset === "Fire") + { + algo.presetIndex = 1; + util.colorArray = [ 0xFFFF00, 0xFF0000, 0x000040, 0xFF0000 ]; + } + else if (_preset === "Abstract") + { + algo.presetIndex = 2; + util.colorArray = [ 0x5571FF, 0x00FFFF, 0xFF00FF, 0xFFFF00 ]; + } + else if (_preset === "Ocean") + { + algo.presetIndex = 3; + util.colorArray = [ 0x003AB9, 0x02EAFF ]; + } + else if (_preset === "User Defined") + { + algo.presetIndex = 4; + algo.acceptColors = 5; + util.colorArray = [ 0x00FF00, 0xFFAA00, 0x0000FF, 0xFFFF00, 0xFFFFFF ]; + } else { algo.presetIndex = 0; } util.initialized = false; }; @@ -75,6 +94,7 @@ var testAlgo; else if (algo.presetIndex === 1) { return "Fire"; } else if (algo.presetIndex === 2) { return "Abstract"; } else if (algo.presetIndex === 3) { return "Ocean"; } + else if (algo.presetIndex === 4) { return "User Defined"; } else { return "Rainbow"; } }; @@ -117,13 +137,10 @@ var testAlgo; // with the given width var gradIdx = 0; util.gradientData = new Array(); - for (var i = 0; i < util.presets[algo.presetIndex].length; i++) + for (var i = 0; i < util.colorArray.length; i++) { - var sColor = util.presets[algo.presetIndex][i]; - var eColor = util.presets[algo.presetIndex][0]; - if (i < util.presets.length - 1) { - eColor = util.presets[algo.presetIndex][i + 1]; - } + var sColor = util.colorArray[i]; + var eColor = util.colorArray[0]; util.gradientData[gradIdx++] = sColor; var sr = (sColor >> 16) & 0x00FF; var sg = (sColor >> 8) & 0x00FF; @@ -243,6 +260,26 @@ var testAlgo; return scaled; } + algo.rgbMapSetColors = function(rawColors) + { + if (! Array.isArray(rawColors)) + return; + for (var i = 0; i < algo.acceptColors; i++) { + if (i < rawColors.length) + { + util.colorArray[i] = rawColors[i]; + } else { + util.colorArray[i] = 0; + } + } + util.initialized = false; + } + + algo.rgbMapGetColors = function() + { + return util.colorArray; + } + algo.rgbMap = function(width, height, rgb, step) { if (util.initialized === false) diff --git a/ui/src/rgbmatrixeditor.cpp b/ui/src/rgbmatrixeditor.cpp index a6c35cc167..a151eeed65 100644 --- a/ui/src/rgbmatrixeditor.cpp +++ b/ui/src/rgbmatrixeditor.cpp @@ -394,85 +394,27 @@ void RGBMatrixEditor::updateExtraOptions() m_yOffsetSpin->setValue(text->yOffset()); } + updateColorOptions(); +} + +void RGBMatrixEditor::updateColorOptions() +{ if (m_matrix->algorithm() != NULL) { int accColors = m_matrix->algorithm()->acceptColors(); - if (accColors == 0) - { - m_mtxColor1Button->hide(); - m_mtxColor2Button->hide(); - m_resetMtxColor2Button->hide(); - m_mtxColor3Button->hide(); - m_resetMtxColor3Button->hide(); - m_mtxColor4Button->hide(); - m_resetMtxColor4Button->hide(); - m_mtxColor5Button->hide(); - m_resetMtxColor5Button->hide(); - m_blendModeLabel->hide(); - m_blendModeCombo->hide(); - } - else - { - m_mtxColor1Button->show(); - if (accColors == 1 || m_blendModeCombo->currentIndex() == Universe::MaskBlend) - { - m_mtxColor2Button->hide(); - m_resetMtxColor2Button->hide(); - m_mtxColor3Button->hide(); - m_resetMtxColor3Button->hide(); - m_mtxColor4Button->hide(); - m_resetMtxColor4Button->hide(); - m_mtxColor5Button->hide(); - m_resetMtxColor5Button->hide(); - } - else if (accColors == 2) - { - m_mtxColor2Button->show(); - m_resetMtxColor2Button->show(); - m_mtxColor3Button->hide(); - m_resetMtxColor3Button->hide(); - m_mtxColor4Button->hide(); - m_resetMtxColor4Button->hide(); - m_mtxColor5Button->hide(); - m_resetMtxColor5Button->hide(); - } - else if (accColors == 3) - { - m_mtxColor2Button->show(); - m_resetMtxColor2Button->show(); - m_mtxColor3Button->show(); - m_resetMtxColor3Button->show(); - m_mtxColor4Button->hide(); - m_resetMtxColor4Button->hide(); - m_mtxColor5Button->hide(); - m_resetMtxColor5Button->hide(); - } - else if (accColors == 4) - { - m_mtxColor2Button->show(); - m_resetMtxColor2Button->show(); - m_mtxColor3Button->show(); - m_resetMtxColor3Button->show(); - m_mtxColor4Button->show(); - m_resetMtxColor4Button->show(); - m_mtxColor5Button->hide(); - m_resetMtxColor5Button->hide(); - } - else - { - m_mtxColor2Button->show(); - m_resetMtxColor2Button->show(); - m_mtxColor3Button->show(); - m_resetMtxColor3Button->show(); - m_mtxColor4Button->show(); - m_resetMtxColor4Button->show(); - m_mtxColor5Button->show(); - m_resetMtxColor5Button->show(); - } - m_blendModeLabel->show(); - m_blendModeCombo->show(); - } + m_mtxColor1Button->setVisible(accColors == 0 ? false : true); + m_mtxColor2Button->setVisible(accColors > 1 ? true : false); + m_resetMtxColor2Button->setVisible(accColors > 1 ? true : false); + m_mtxColor3Button->setVisible(accColors > 2 ? true : false); + m_resetMtxColor3Button->setVisible(accColors > 2 ? true : false); + m_mtxColor4Button->setVisible(accColors > 3 ? true : false); + m_resetMtxColor4Button->setVisible(accColors > 3 ? true : false); + m_mtxColor5Button->setVisible(accColors > 4 ? true : false); + m_resetMtxColor5Button->setVisible(accColors > 4 ? true : false); + + m_blendModeLabel->setVisible(accColors == 0 ? false : true); + m_blendModeCombo->setVisible(accColors == 0 ? false : true); } } @@ -1524,6 +1466,9 @@ void RGBMatrixEditor::slotPropertyComboChanged(int index) QString pValue = combo->itemText(index); qDebug() << "Property combo changed to" << pValue; m_matrix->setProperty(pName, pValue); + + updateColorOptions(); + updateColors(); } } diff --git a/ui/src/rgbmatrixeditor.h b/ui/src/rgbmatrixeditor.h index 150bc70fc6..22ccb63531 100644 --- a/ui/src/rgbmatrixeditor.h +++ b/ui/src/rgbmatrixeditor.h @@ -63,6 +63,7 @@ public slots: void fillAnimationCombo(); void fillImageAnimationCombo(); void updateExtraOptions(); + void updateColorOptions(); void updateColors(); void resetProperties(QLayoutItem *item); void displayProperties(RGBScript *script); From bdced4f1bda5392dd33987a7d4444992a1d3a2ee Mon Sep 17 00:00:00 2001 From: Massimo Callegari Date: Thu, 24 Oct 2024 17:14:58 +0200 Subject: [PATCH 49/63] engine: fix QJSValue usage --- engine/src/rgbscriptv4.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/rgbscriptv4.cpp b/engine/src/rgbscriptv4.cpp index 93242b762e..f2254e0681 100644 --- a/engine/src/rgbscriptv4.cpp +++ b/engine/src/rgbscriptv4.cpp @@ -277,7 +277,7 @@ QVector RGBScript::rgbMapGetColors() return colArray; QJSValue colors = m_rgbMapGetColors.call(); - if (colors.isValid() && colors.isArray()) + if (!colors.isError() && colors.isArray()) { QVariantList arr = colors.toVariant().toList(); foreach (QVariant color, arr) From 7a521454f387268b66a80b773c5b228f891b4ba4 Mon Sep 17 00:00:00 2001 From: Massimo Callegari Date: Thu, 24 Oct 2024 17:53:56 +0200 Subject: [PATCH 50/63] engine: fix RGBMatrix copy and test unit --- engine/src/rgbmatrix.cpp | 2 ++ engine/test/rgbmatrix/rgbmatrix_test.cpp | 46 ++++++++++++------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/engine/src/rgbmatrix.cpp b/engine/src/rgbmatrix.cpp index 5919c8bfd6..e9ae57318a 100644 --- a/engine/src/rgbmatrix.cpp +++ b/engine/src/rgbmatrix.cpp @@ -166,6 +166,8 @@ bool RGBMatrix::copyFrom(const Function* function) setDimmerControl(mtx->dimmerControl()); setFixtureGroup(mtx->fixtureGroup()); + + m_rgbColors.clear(); foreach (QColor col, mtx->getColors()) m_rgbColors.append(col); diff --git a/engine/test/rgbmatrix/rgbmatrix_test.cpp b/engine/test/rgbmatrix/rgbmatrix_test.cpp index 1dfb801ea2..e1c74362c9 100644 --- a/engine/test/rgbmatrix/rgbmatrix_test.cpp +++ b/engine/test/rgbmatrix/rgbmatrix_test.cpp @@ -241,7 +241,6 @@ void RGBMatrix_Test::loadSave() QCOMPARE(xmlReader.attributes().value("Name").toString(), QString("Xyzzy")); int speed = 0, dir = 0, run = 0, algo = 0, grp = 0, color1 = 0, color2 = 0, color3 = 0, color4 = 0, color5 = 0, colormode = 0; - QVector colors; while (xmlReader.readNextStartElement()) { @@ -269,38 +268,37 @@ void RGBMatrix_Test::loadSave() algo++; xmlReader.skipCurrentElement(); } - else if (xmlReader.name().toString().startsWith("Color", Qt::CaseSensitive)) + else if (xmlReader.name().toString() == "Color") { bool ok = false; - QString colorNumText = xmlReader.name().toString().right( - xmlReader.name().toString().length() - QString("Color").length()); - int colorNum = colorNumText.toInt(&ok, 10); + int colorNum = xmlReader.attributes().value("Index").toInt(&ok); QVERIFY(ok); - switch (colorNum) { - case 1: - QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::magenta).rgb()); - color1 ++; + switch (colorNum) + { + case 0: + QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::magenta).rgb()); + color1++; break; - case 2: - QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::blue).rgb()); - color2++; + case 1: + QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::blue).rgb()); + color2++; break; - case 3: - QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::green).rgb()); - color3++; + case 2: + QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::green).rgb()); + color3++; break; - case 4: - QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::red).rgb()); - color4++; + case 3: + QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::red).rgb()); + color4++; break; - case 5: - QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::yellow).rgb()); - color5++; + case 4: + QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::yellow).rgb()); + color5++; break; - default: - // The color number can be between 1 and MAXINT, but here we expect only 5. - QVERIFY(colorNum > 0 && colorNum <= 5); + default: + // The color number can be between 1 and MAXINT, but here we expect only 5. + QVERIFY(colorNum > 0 && colorNum <= 5); break; } } From 3b53dd1c3c97b7cd11b6b0c22fc5c08e20633450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Mon, 28 Oct 2024 14:37:53 +0100 Subject: [PATCH 51/63] Update pixel colors when properties change This covers properties with an effect on acceptColors. --- resources/rgbscripts/devtool/devtool.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/rgbscripts/devtool/devtool.js b/resources/rgbscripts/devtool/devtool.js index 8b64bafc81..f71515cd70 100644 --- a/resources/rgbscripts/devtool/devtool.js +++ b/resources/rgbscripts/devtool/devtool.js @@ -526,6 +526,8 @@ devtool.writeFunction = function(functionName, propertyName, value) { window.testAlgo[functionName](value); localStorage.setItem(propertyName, value); + devtool.initPixelColors(); + devtool.initColorValues(); devtool.updateStepCount(); } From ea8186f6855cd7fcbb73749e4c872014ecc7ab69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Mon, 28 Oct 2024 14:38:41 +0100 Subject: [PATCH 52/63] Gracefully handle unset colors by setting them to black. --- resources/rgbscripts/plasma.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/resources/rgbscripts/plasma.js b/resources/rgbscripts/plasma.js index ac9c0f994d..906381516a 100644 --- a/resources/rgbscripts/plasma.js +++ b/resources/rgbscripts/plasma.js @@ -140,7 +140,12 @@ var testAlgo; for (var i = 0; i < util.colorArray.length; i++) { var sColor = util.colorArray[i]; - var eColor = util.colorArray[0]; + if (Number.isNaN(sColor)) + sColor = 0; + var eColor = util.colorArray[(i + 1) % util.colorArray.length]; + if (Number.isNaN(eColor)) + eColor = 0; + util.gradientData[gradIdx++] = sColor; var sr = (sColor >> 16) & 0x00FF; var sg = (sColor >> 8) & 0x00FF; @@ -244,6 +249,7 @@ var testAlgo; { return a + t * (b - a); } + // https://en.wikipedia.org/wiki/Gradient function grad(hash, x, y, z) { From 6d74f373d17805ad52620c4ffdb67e60cae3ef08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Mon, 28 Oct 2024 18:10:25 +0100 Subject: [PATCH 53/63] Replace isNaN by different null check in plasma.js --- resources/rgbscripts/plasma.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/rgbscripts/plasma.js b/resources/rgbscripts/plasma.js index 906381516a..7ef8cbccdf 100644 --- a/resources/rgbscripts/plasma.js +++ b/resources/rgbscripts/plasma.js @@ -140,10 +140,10 @@ var testAlgo; for (var i = 0; i < util.colorArray.length; i++) { var sColor = util.colorArray[i]; - if (Number.isNaN(sColor)) - sColor = 0; var eColor = util.colorArray[(i + 1) % util.colorArray.length]; - if (Number.isNaN(eColor)) + if (! sColor) + sColor = 0; + if (! eColor) eColor = 0; util.gradientData[gradIdx++] = sColor; From c34427346534a753cf4fc104c3d463a343eb9b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Mon, 28 Oct 2024 18:17:57 +0100 Subject: [PATCH 54/63] Remove isNaN from other productive code. It is not available in the used JS implementation. --- resources/rgbscripts/alternatecolorsdirect.js | 2 +- resources/rgbscripts/ballscolorsdirect.js | 2 +- resources/rgbscripts/empty.js | 2 +- resources/rgbscripts/marqueecolorsdirect.js | 2 +- resources/rgbscripts/plasmacolorsdirect.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/resources/rgbscripts/alternatecolorsdirect.js b/resources/rgbscripts/alternatecolorsdirect.js index be851b9d4d..25b53d5d35 100644 --- a/resources/rgbscripts/alternatecolorsdirect.js +++ b/resources/rgbscripts/alternatecolorsdirect.js @@ -109,7 +109,7 @@ var testAlgo; util.getRawColor = function (idx) { var color = 0; - if (Array.isArray(util.colorArray) && util.colorArray.length > idx && ! isNaN(util.colorArray[idx])) { + if (Array.isArray(util.colorArray) && util.colorArray.length > idx && util.colorArray[idx]) { color = util.colorArray[idx]; } return color; diff --git a/resources/rgbscripts/ballscolorsdirect.js b/resources/rgbscripts/ballscolorsdirect.js index c4ba230570..9d329fcb5c 100644 --- a/resources/rgbscripts/ballscolorsdirect.js +++ b/resources/rgbscripts/ballscolorsdirect.js @@ -66,7 +66,7 @@ var testAlgo; util.getRawColor = function (idx) { var color = 0; - if (Array.isArray(util.colorArray) && util.colorArray.length > idx && ! isNaN(util.colorArray[idx])) { + if (Array.isArray(util.colorArray) && util.colorArray.length > idx && util.colorArray[idx]) { color = util.colorArray[idx]; } return color; diff --git a/resources/rgbscripts/empty.js b/resources/rgbscripts/empty.js index 3be222b787..4d7f8f0e57 100644 --- a/resources/rgbscripts/empty.js +++ b/resources/rgbscripts/empty.js @@ -41,7 +41,7 @@ var testAlgo; */ util.getRawColor = function (idx) { var color = 0; - if (Array.isArray(util.colorArray) && util.colorArray.length > idx && ! isNaN(util.colorArray[idx])) { + if (Array.isArray(util.colorArray) && util.colorArray.length > idx && util.colorArray[idx]) { color = util.colorArray[idx]; } return color; diff --git a/resources/rgbscripts/marqueecolorsdirect.js b/resources/rgbscripts/marqueecolorsdirect.js index fd3c34dc0a..dd190c8388 100644 --- a/resources/rgbscripts/marqueecolorsdirect.js +++ b/resources/rgbscripts/marqueecolorsdirect.js @@ -96,7 +96,7 @@ var testAlgo; util.getRawColor = function (idx) { var color = 0; - if (Array.isArray(util.colorArray) && util.colorArray.length > idx && ! isNaN(util.colorArray[idx])) { + if (Array.isArray(util.colorArray) && util.colorArray.length > idx && util.colorArray[idx]) { color = util.colorArray[idx]; } return color; diff --git a/resources/rgbscripts/plasmacolorsdirect.js b/resources/rgbscripts/plasmacolorsdirect.js index c53fad83fd..3b09f02edb 100644 --- a/resources/rgbscripts/plasmacolorsdirect.js +++ b/resources/rgbscripts/plasmacolorsdirect.js @@ -85,7 +85,7 @@ var testAlgo; util.getRawColor = function (idx) { var color = 0; - if (Array.isArray(util.colorArray) && util.colorArray.length > idx && ! isNaN(util.colorArray[idx])) { + if (Array.isArray(util.colorArray) && util.colorArray.length > idx && util.colorArray[idx]) { color = util.colorArray[idx]; } return color; From 7d943f00ebf9ee2bc977b979142b6a4a55214e58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Mon, 28 Oct 2024 19:08:46 +0100 Subject: [PATCH 55/63] Merge new scripts over existing ones. --- engine/test/rgbscript/rgbscript_test.cpp | 2 +- resources/rgbscripts/alternate.js | 136 ++----- resources/rgbscripts/alternatecolorsdirect.js | 273 -------------- resources/rgbscripts/marquee.js | 103 ++--- resources/rgbscripts/marqueecolorsdirect.js | 266 ------------- resources/rgbscripts/plasmacolors.js | 357 ------------------ resources/rgbscripts/plasmacolorsdirect.js | 287 -------------- resources/rgbscripts/rgbscripts.pro | 4 - 8 files changed, 63 insertions(+), 1365 deletions(-) delete mode 100644 resources/rgbscripts/alternatecolorsdirect.js delete mode 100644 resources/rgbscripts/marqueecolorsdirect.js delete mode 100644 resources/rgbscripts/plasmacolors.js delete mode 100644 resources/rgbscripts/plasmacolorsdirect.js diff --git a/engine/test/rgbscript/rgbscript_test.cpp b/engine/test/rgbscript/rgbscript_test.cpp index b771bbaf2e..d3770e6354 100644 --- a/engine/test/rgbscript/rgbscript_test.cpp +++ b/engine/test/rgbscript/rgbscript_test.cpp @@ -207,7 +207,7 @@ void RGBScript_Test::rgbMapStepCount() void RGBScript_Test::rgbMapColorArray() { RGBMap map; - RGBScript s = m_doc->rgbScriptsCache()->script("Alternate (2 Colors)"); + RGBScript s = m_doc->rgbScriptsCache()->script("Alternate"); QCOMPARE(s.evaluate(), true); QVector rawRgbColors = { QColor(Qt::red).rgb() & 0x00ffffff, diff --git a/resources/rgbscripts/alternate.js b/resources/rgbscripts/alternate.js index 893336e492..be9aa487f8 100644 --- a/resources/rgbscripts/alternate.js +++ b/resources/rgbscripts/alternate.js @@ -21,117 +21,18 @@ var testAlgo; (function() { - var colorPalette = new Object; - colorPalette.collection = new Array( - ["White", 0xFFFFFF], // 0 - ["Cream", 0xFFFF7F], // 1 - ["Pink", 0xFF7F7F], // 2 - ["Rose", 0x7F3F3F], // 3 - ["Coral", 0x7F3F1F], // 4 - ["Dim Red", 0x7F0000], // 5 - ["Red", 0xFF0000], // 6 - ["Orange", 0xFF3F00], // 7 - ["Dim Orange", 0x7F1F00], // 8 - ["Goldenrod", 0x7F3F00], // 9 - ["Gold", 0xFF7F00], // 10 - ["Yellow", 0xFFFF00], // 11 - ["Dim Yellow", 0x7F7F00], // 12 - ["Lime", 0x7FFF00], // 13 - ["Pale Green", 0x3F7F00], // 14 - ["Dim Green", 0x007F00], // 15 - ["Green", 0x00FF00], // 16 - ["Seafoam", 0x00FF3F], // 17 - ["Turquoise", 0x007F3F], // 18 - ["Teal", 0x007F7F], // 19 - ["Cyan", 0x00FFFF], // 20 - ["Electric Blue", 0x007FFF], // 21 - ["Blue", 0x0000FF], // 22 - ["Dim Blue", 0x00007F], // 23 - ["Pale Blue", 0x1F1F7F], // 24 - ["Indigo", 0x1F00BF], // 25 - ["Purple", 0x3F00BF], // 26 - ["Violet", 0x7F007F], // 27 - ["Magenta", 0xFF00FF], // 28 - ["Hot Pink", 0xFF003F], // 29 - ["Deep Pink", 0x7F001F], // 30 - ["OFF", 0x000000]); // 31 - - colorPalette.makeSubArray = function(_index) { - var _array = new Array(); - for (var i = 0; i < colorPalette.collection.length; i++) { - _array.push(colorPalette.collection[i][_index]); - } - return _array; - }; - colorPalette.names = colorPalette.makeSubArray(0); var algo = new Object; - algo.apiVersion = 2; + algo.apiVersion = 3; algo.name = "Alternate"; algo.author = "Hans-Jürgen Tappe"; var x = 0; var y = 0; - algo.acceptColors = 0; + algo.acceptColors = 2; algo.properties = new Array(); - algo.getColorIndex = function(_name) { - var idx = colorPalette.names.indexOf(_name); - if (idx === -1) { - idx = (colorPalette.collection.length - 1); - } - return idx; - }; - - algo.color1Index = algo.getColorIndex("Red"); - algo.properties.push("name:color1Index|type:list|display:Color 1|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor1Index|read:getColor1Name"); - algo.color2Index = algo.getColorIndex("Green"); - algo.properties.push("name:color2Index|type:list|display:Color 2|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor2Index|read:getColor2Name"); - - algo.getColorName = function(_index) { - if (_index < 0) { - _index = 0; - } - if (_index >= colorPalette.collection.length) { - _index = (colorPalette.collection.length - 1); - } - return colorPalette.collection[parseInt(_index, 10)][0]; - }; - algo.getColorValue = function(_index) { - if (_index < 0) { - _index = 0; - } - else if (_index >= colorPalette.collection.length) { - _index = (colorPalette.collection.length - 1); - } - return colorPalette.collection[parseInt(_index, 10)][1]; - }; - - algo.setColor1Index = function(_name) { - algo.color1Index = algo.getColorIndex(_name); - }; - algo.getColor1Name = function() { - return algo.getColorName(algo.color1Index); - }; - algo.getColor1Value = function() { - return algo.getColorValue(algo.color1Index); - }; - - algo.setColor2Index = function(_name) { - algo.color2Index = algo.getColorIndex(_name); - }; - algo.getColor2Name = function() { - return algo.getColorName(algo.color2Index); - }; - algo.getColor2Value = function() { - return algo.getColorValue(algo.color2Index); - }; - algo.align = 0; algo.properties.push("name:align|type:list|" + "display:Align (for even width)|values:Left,Centered,Split|" + @@ -203,17 +104,40 @@ var testAlgo; return algo.offset; }; + var util = new Object; + util.colorArray = new Array(algo.acceptColors); + + util.getRawColor = function (idx) { + var color = 0; + if (Array.isArray(util.colorArray) && util.colorArray.length > idx && util.colorArray[idx]) { + color = util.colorArray[idx]; + } + return color; + } + + algo.rgbMapSetColors = function(rawColors) + { + if (! Array.isArray(rawColors)) + return; + for (var i = 0; i < algo.acceptColors; i++) { + if (i < rawColors.length) + { + util.colorArray[i] = rawColors[i]; + } else { + util.colorArray[i] = 0; + } + } + } + algo.rgbMap = function(width, height, rgb, step) { var map = new Array(height); var colorSelectOne = (step === 1) ? false : true; var rowColorOne = colorSelectOne; var realBlockSize = algo.blockSize; + // Setup the rgb map for (y = 0; y < height; y++) { map[y] = new Array(width); - for (x = 0; x < width; x++) { - map[y][x] = 0; - } } var xMax = width; @@ -303,9 +227,9 @@ var testAlgo; } } if (colorSelectOne) { - map[y][x] = algo.getColor1Value(); + map[y][x] = util.getRawColor(0); } else { - map[y][x] = algo.getColor2Value(); + map[y][x] = util.getRawColor(1); } } } diff --git a/resources/rgbscripts/alternatecolorsdirect.js b/resources/rgbscripts/alternatecolorsdirect.js deleted file mode 100644 index 25b53d5d35..0000000000 --- a/resources/rgbscripts/alternatecolorsdirect.js +++ /dev/null @@ -1,273 +0,0 @@ -/* - Q Light Controller Plus - alternatecolorsdirect.js - - Copyright (c) Hans-Jürgen Tappe - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0.txt - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -// Development tool access -var testAlgo; - -(function() { - - var algo = new Object; - algo.apiVersion = 3; - algo.name = "Alternate (2 Colors)"; - algo.author = "Hans-Jürgen Tappe"; - - var x = 0; - var y = 0; - - algo.acceptColors = 2; - algo.properties = new Array(); - - algo.align = 0; - algo.properties.push("name:align|type:list|" + - "display:Align (for even width)|values:Left,Centered,Split|" + - "write:setAlign|read:getAlign"); - // Left aligned is default. - algo.setAlign = function(_align) { - if (_align === "Centered") { - algo.align = 1; - } else if (_align === "Split") { - algo.align = 2; - } else { - algo.align = 0; - } - }; - algo.getAlign = function() { - if (algo.align === 1) { - return "Centered"; - } else if (algo.align === 2) { - return "Split"; - } else { - return "Left"; - } - }; - - algo.orientation = 0; - algo.properties.push("name:orientation|type:list|" + - "display:Orientation|values:Horizontal,Vertical,Interleaved|" + - "write:setOrientation|read:getOrientation"); - algo.setOrientation = function(_orientation) { - if (_orientation === "Vertical") { - algo.orientation = 1; - } else if (_orientation === "Interleaved") { - algo.orientation = 2; - } else { - algo.orientation = 0; - } - }; - algo.getOrientation = function() { - if (parseInt(algo.orientation, 10) === 1) { - return "Vertical"; - } else if (algo.orientation === 2) { - return "Interleaved"; - } else { - return "Horizontal"; - } - }; - - algo.blockSize = 1; - algo.properties.push("name:blockSize|type:range|" - + "display:Block Size / Split (>= 1)|" - + "values:1,32000|" - + "write:setBlockSize|read:getBlockSize"); - algo.setBlockSize = function(_size) { - algo.blockSize = parseInt(_size, 10); - }; - algo.getBlockSize = function() { - return algo.blockSize; - }; - - algo.offset = 0; - algo.properties.push("name:offset|type:range|" - + "display:Offset (>= 0)|" - + "values:0,32000|" - + "write:setOffset|read:getOffset"); - algo.setOffset = function(_size) { - algo.offset = parseInt(_size, 10); - }; - algo.getOffset = function() { - return algo.offset; - }; - - var util = new Object; - util.colorArray = new Array(algo.acceptColors); - - util.getRawColor = function (idx) { - var color = 0; - if (Array.isArray(util.colorArray) && util.colorArray.length > idx && util.colorArray[idx]) { - color = util.colorArray[idx]; - } - return color; - } - - algo.rgbMapSetColors = function(rawColors) - { - if (! Array.isArray(rawColors)) - return; - for (var i = 0; i < algo.acceptColors; i++) { - if (i < rawColors.length) - { - util.colorArray[i] = rawColors[i]; - } else { - util.colorArray[i] = 0; - } - } - } - - algo.rgbMap = function(width, height, rgb, step) { - var map = new Array(height); - var colorSelectOne = (step === 1) ? false : true; - var rowColorOne = colorSelectOne; - var realBlockSize = algo.blockSize; - - // Setup the rgb map - for (y = 0; y < height; y++) { - map[y] = new Array(width); - } - - var xMax = width; - var yMax = height; - if (algo.align === 1) { - if (algo.orientation === 0 || algo.orientation === 2) { - // Centered mode - xMax = Math.ceil(width / 2); - } - if (algo.orientation === 1 || algo.orientation === 2) { - // Centered mode - yMax = Math.ceil(height / 2); - } - } - - if (algo.align === 2) { - // Split mode - if (algo.orientation === 0) { - // Horizontal - realBlockSize = width / algo.blockSize; - } else if (algo.orientation === 1) { - // Vertical - realBlockSize = height / algo.blockSize; - } else if (algo.orientation === 2) { - // Interleaved - realBlockSize = Math.min(width, height) / algo.blockSize; - } - } - - var effectiveStep; - var realBlockCount; - var lowRest; - var highRest; - var rest; - for (y = 0; y < yMax; y++) { - if (algo.orientation === 0) { - // Horizontal split; vertical lines - // Initialize vertical bars, each column the same - colorSelectOne = (step === 1) ? false : true; - } else if (algo.orientation === 1) { - // Horizontal Bars, count steps by row - effectiveStep = y + Math.round(step * realBlockSize) + algo.offset; - - // Initialize start color for each row. - realBlockCount = Math.floor(effectiveStep / realBlockSize); - lowRest = effectiveStep - realBlockCount * realBlockSize; - highRest = (realBlockCount + 1) * realBlockSize - effectiveStep; - rest = Math.min(lowRest, highRest); - if (rest < 0.5 || lowRest === 0.5) { - colorSelectOne = !colorSelectOne; - } - } else if (algo.orientation === 2) { - // Interleaved - var effectiveY = y + Math.floor(step * realBlockSize) + algo.offset; - - realBlockCount = Math.floor(effectiveY / realBlockSize); - lowRest = effectiveY - realBlockCount * realBlockSize; - highRest = (realBlockCount + 1) * realBlockSize - effectiveY; - rest = Math.min(lowRest, highRest); - if (rest < 0.5 || lowRest === 0.5) { - rowColorOne = !rowColorOne; - } - colorSelectOne = rowColorOne; - } - - for (x = 0; x < xMax; x++) { - if (algo.orientation === 0) { - // Horizontal split, vertical bars, count steps by column - effectiveStep = x + algo.offset; - realBlockCount = Math.floor(effectiveStep / realBlockSize); - lowRest = effectiveStep - realBlockCount * realBlockSize; - highRest = (realBlockCount + 1) * realBlockSize - effectiveStep; - rest = Math.min(lowRest, highRest); - if (rest < 0.5 || lowRest === 0.5) { - colorSelectOne = !colorSelectOne; - } - } else if (algo.orientation === 2) { - // vertical split, horizontal Bars, count steps by row and column - var effectiveX = x + Math.floor(step * realBlockSize) + algo.offset; - // Change color each step. - realBlockCount = Math.floor(effectiveX / realBlockSize); - lowRest = effectiveX - realBlockCount * realBlockSize; - highRest = (realBlockCount + 1) * realBlockSize - effectiveX; - rest = Math.min(lowRest, highRest); - if (rest < 0.5 || lowRest == 0.5) { - colorSelectOne = !colorSelectOne; - } - } - if (colorSelectOne) { - map[y][x] = util.getRawColor(0); - } else { - map[y][x] = util.getRawColor(1); - } - } - } - // Align centered - if (algo.align === 1) { - if (algo.orientation === 0) { - for (y = 0; y < yMax; y++) { - for (x = 0; x < xMax; x++) { - map[y][width - x - 1] = map[y][x]; - } - } - } else if (algo.orientation === 1) { - for (y = 0; y < yMax; y++) { - for (x = 0; x < xMax; x++) { - map[height - y - 1][x] = map[y][x]; - } - } - } else if (algo.orientation === 2) { - for (y = 0; y < yMax; y++) { - for (x = 0; x < xMax; x++) { - map[height - y - 1][x] = map[y][x]; - map[y][width - x - 1] = map[y][x]; - map[height - y - 1][width - x - 1] = map[y][x]; - } - } - } - } - - return map; - }; - - algo.rgbMapStepCount = function(width, height) { - // Only two steps; one for even pixels and another for odd pixels - return 2; - }; - - // Development tool access - testAlgo = algo; - - return algo; -})(); diff --git a/resources/rgbscripts/marquee.js b/resources/rgbscripts/marquee.js index 033f0fb3a5..0b7d5068b2 100644 --- a/resources/rgbscripts/marquee.js +++ b/resources/rgbscripts/marquee.js @@ -21,59 +21,11 @@ var testAlgo; (function () { - var colorPalette = new Object(); - colorPalette.collection = new Array( - ["White" , 0xFFFFFF], - ["LightGrey" , 0xAAAAAA], - ["MediumGrey" , 0x999999], - ["DarkGrey" , 0x666666], - ["Cream" , 0xFFFF7F], - ["Pink" , 0xFF7F7F], - ["Rose" , 0x7F3F3F], - ["Coral" , 0x7F3F1F], - ["Dim Red" , 0x7F0000], - ["Red" , 0xFF0000], - ["Orange" , 0xFF3F00], - ["Dim Orange" , 0x7F1F00], - ["Goldenrod" , 0x7F3F00], - ["Gold" , 0xFF7F00], - ["Yellow" , 0xFFFF00], - ["Dim Yellow" , 0x7F7F00], - ["Lime" , 0x7FFF00], - ["Pale Green" , 0x3F7F00], - ["Dim Green" , 0x007F00], - ["Green" , 0x00FF00], - ["Seafoam" , 0x00FF3F], - ["Turquoise" , 0x007F3F], - ["Teal" , 0x007F7F], - ["Cyan" , 0x00FFFF], - ["Electric Blue", 0x007FFF], - ["Blue" , 0x0000FF], - ["Dim Blue" , 0x00007F], - ["Pale Blue" , 0x1F1F7F], - ["Indigo" , 0x1F00BF], - ["Purple" , 0x3F00BF], - ["Violet" , 0x7F007F], - ["Magenta" , 0xFF00FF], - ["Hot Pink" , 0xFF003F], - ["Deep Pink" , 0x7F001F], - ["Black" , 0x000000] - ); - - colorPalette.makeSubArray = function (_index) { - var _array = new Array(); - for (var i = 0; i < colorPalette.collection.length; i++) { - _array.push(colorPalette.collection[i][_index]); - } - return _array; - }; - colorPalette.names = colorPalette.makeSubArray(0); - var algo = new Object(); - algo.apiVersion = 2; + algo.apiVersion = 3; algo.name = "Marquee"; algo.author = "Branson Matheson"; - algo.acceptColors = 1; + algo.acceptColors = 2; algo.properties = new Array(); algo.edgeDepth = 2; algo.properties.push( @@ -87,14 +39,6 @@ var testAlgo; algo.properties.push( "name:marqueeCount|type:range|display:Marquee Spaces|values:1,100|write:setMarqueeCount|read:getMarqueeCount" ); - algo.marqueeColorIndex = 0; - algo.properties.push( - "name:marqueColor|type:list|display:Marquee Light Color|" + - "values:" + - colorPalette.names.toString() + - "|" + - "write:setMarqueeColorIndex|read:getMarqueeColorIndex" - ); var util = new Object(); util.initialized = false; @@ -102,6 +46,7 @@ var testAlgo; util.height = 0; util.featureColor = 0; util.step = algo.marqueeCount; + util.colorArray = new Array(algo.acceptColors); util.lights = new Array(); util.feature = new Array(); @@ -149,18 +94,32 @@ var testAlgo; return algo.marqueeCount; }; - algo.setMarqueeColorIndex = function (_preset) { - algo.marqueeColorIndex = colorPalette.names.indexOf(_preset); - util.initialized = false; - }; + util.getRawColor = function (idx) { + var color = 0; + if (Array.isArray(util.colorArray) && util.colorArray.length > idx && util.colorArray[idx]) { + color = util.colorArray[idx]; + } + return color; + } + + algo.rgbMapSetColors = function(rawColors) + { + if (! Array.isArray(rawColors)) + return; + for (var i = 0; i < algo.acceptColors; i++) { + if (i < rawColors.length) + { + util.colorArray[i] = rawColors[i]; + } else { + util.colorArray[i] = 0; + } + } + } - algo.getMarqueeColorIndex = function () { - return colorPalette.collection[algo.marqueeColorIndex][0]; - }; - util.initialize = function (width, height, rgb) { + util.initialize = function (width, height) { // initialize feature - util.featureColor = rgb; + util.featureColor = util.getRawColor(0); util.feature = new Array(); var maxDistance = Math.min(width, height) / 2; for (var y = 0; y < height; y++) { @@ -184,6 +143,8 @@ var testAlgo; if (distance <= algo.edgeDepth && distance <= maxDistance) { var percent = ((algo.edgeDepth - distance) / algo.edgeDepth) * 100; util.feature[y][x] = util.fadeColor(util.featureColor, percent); + } else { + util.feature[y][x] = 0; } } } @@ -242,7 +203,7 @@ var testAlgo; } // create light map add lights, go around the outside - var marqueeColor = colorPalette.collection[algo.marqueeColorIndex][1]; + var marqueeColor = util.getRawColor(1); var p = 0; // left for (y = 0; y < height; y++) { @@ -279,14 +240,14 @@ var testAlgo; return map; }; - algo.rgbMap = function (width, height, rgb, step) { + algo.rgbMap = function(width, height, rgb, step) { if ( util.initialized === false || - util.featureColor != rgb || + util.featureColor != util.getRawColor(0) || util.width !== width || util.height !== height ) { - util.initialize(width, height, rgb); + util.initialize(width, height); } var map = util.getNextStep(width, height); diff --git a/resources/rgbscripts/marqueecolorsdirect.js b/resources/rgbscripts/marqueecolorsdirect.js deleted file mode 100644 index dd190c8388..0000000000 --- a/resources/rgbscripts/marqueecolorsdirect.js +++ /dev/null @@ -1,266 +0,0 @@ -/* - Q Light Controller Plus - marqueecolorsdirect.js - - Copyright (c) Branson Matheson - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0.txt - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Development tool access -var testAlgo; - -(function () { - var algo = new Object(); - algo.apiVersion = 3; - algo.name = "Marquee (2 Colors)"; - algo.author = "Branson Matheson"; - algo.acceptColors = 2; - algo.properties = new Array(); - algo.edgeDepth = 2; - algo.properties.push( - "name:depth|type:range|display:Depth|values:1,10000|write:setDepth|read:getDepth" - ); - algo.marquee = 0; - algo.properties.push( - "name:marquee|type:list|display:Marquee|values:None,Forward,Backward|write:setMarquee|read:getMarquee" - ); - algo.marqueeCount = 3; - algo.properties.push( - "name:marqueeCount|type:range|display:Marquee Spaces|values:1,100|write:setMarqueeCount|read:getMarqueeCount" - ); - - var util = new Object(); - util.initialized = false; - util.width = 0; - util.height = 0; - util.featureColor = 0; - util.step = algo.marqueeCount; - util.colorArray = new Array(algo.acceptColors); - - util.lights = new Array(); - util.feature = new Array(); - - algo.setDepth = function (_amount) { - algo.edgeDepth = parseInt(_amount, 10); - util.initialized = false; - }; - - algo.getDepth = function () { - return algo.edgeDepth; - }; - - algo.setMarquee = function (_marquee) { - if (_marquee === "None") { - algo.marquee = 0; - } - if (_marquee === "Forward") { - algo.marquee = 1; - } - if (_marquee === "Backward") { - algo.marquee = 2; - } - util.initialized = false; - }; - - algo.getMarquee = function () { - if (algo.marquee === 0) { - return "None"; - } - if (algo.marquee === 1) { - return "Forward"; - } - if (algo.marquee === 2) { - return "Backward"; - } - }; - - algo.setMarqueeCount = function (_amount) { - algo.marqueeCount = parseInt(_amount, 10); - util.initialized = false; - }; - - algo.getMarqueeCount = function () { - return algo.marqueeCount; - }; - - util.getRawColor = function (idx) { - var color = 0; - if (Array.isArray(util.colorArray) && util.colorArray.length > idx && util.colorArray[idx]) { - color = util.colorArray[idx]; - } - return color; - } - - algo.rgbMapSetColors = function(rawColors) - { - if (! Array.isArray(rawColors)) - return; - for (var i = 0; i < algo.acceptColors; i++) { - if (i < rawColors.length) - { - util.colorArray[i] = rawColors[i]; - } else { - util.colorArray[i] = 0; - } - } - } - - - util.initialize = function (width, height) { - // initialize feature - util.featureColor = util.getRawColor(0); - util.feature = new Array(); - var maxDistance = Math.min(width, height) / 2; - for (var y = 0; y < height; y++) { - util.feature[y] = new Array(); - var y_distance = y; - if (y >= height / 2) { - y_distance = height - y - 1; - } - - for (var x = 0; x < width; x++) { - // write color - var distance = algo.edgeDepth + 1; - util.feature[y][x] = 0; - - var x_distance = x; - if (x >= width / 2) { - x_distance = width - x - 1; - } - - distance = Math.min(x_distance, y_distance); - if (distance <= algo.edgeDepth && distance <= maxDistance) { - var percent = ((algo.edgeDepth - distance) / algo.edgeDepth) * 100; - util.feature[y][x] = util.fadeColor(util.featureColor, percent); - } else { - util.feature[y][x] = 0; - } - } - } - - // initialize lights array: 2 heights, 2 widths, 4 duplicate corner pixels - // only if the dimensions have changes (not on color change) - if (util.width != width || util.height != height || util.initialized !== true) { - var length = height * 2 + width * 2 - 4; - util.lights = new Array(length); - var pointAmount = Math.floor(util.lights.length / (algo.marqueeCount + 1)); - var mediumDistance = length / pointAmount; - for (var i = 0; i < util.lights.length; i++) { - if (i % mediumDistance < 1) { - util.lights[i] = 1; - } else { - util.lights[i] = 0; - } - } - } - // for testing for change - util.width = width; - util.height = height; - util.initialized = true; - }; - - util.fadeColor = function (rgb, percent) { - var r = (rgb >> 16) & 0x00ff; - var g = (rgb >> 8) & 0x00ff; - var b = rgb & 0x00ff; - var newR = Math.round(r * (percent / 100)); - var newG = Math.round(g * (percent / 100)); - var newB = Math.round(b * (percent / 100)); - var newRGB = (newR << 16) + (newG << 8) + newB; - return newRGB; - }; - - util.getNextStep = function (width, height) { - var x = 0; - var y = 0; - var map = new Array(height); - for (y = 0; y <= height - 1; y++) { - map[y] = new Array(width); - for (x = 0; x <= width - 1; x++) { - map[y][x] = util.feature[y][x]; - } - } - - if (algo.marquee === 0) { return map } - - if (algo.marquee === 1) { - var first = util.lights.shift(); - util.lights.push(first); - } else if (algo.marquee === 2) { - var last = util.lights.pop(); - util.lights.unshift(last); - } - - // create light map add lights, go around the outside - var marqueeColor = util.getRawColor(1); - var p = 0; - // left - for (y = 0; y < height; y++) { - x = 0; - if (util.lights[p] === 1) { - map[y][x] = marqueeColor; - } - p += 1; - } - // bottom - for (x = 1; x < width; x++) { - y = height - 1; - if (util.lights[p] === 1) { - map[y][x] = marqueeColor; - } - p += 1; - } - // right - for (y = height - 2; y >= 0; y--) { - x = width - 1; - if (util.lights[p] === 1) { - map[y][x] = marqueeColor; - } - p += 1; - } - // top - for (x = width - 2; x >= 0; x--) { - y = 0; - if (util.lights[p] === 1) { - map[y][x] = marqueeColor; - } - p += 1; - } - return map; - }; - - algo.rgbMap = function(width, height, rgb, step) { - if ( - util.initialized === false || - util.featureColor != util.getRawColor(0) || - util.width !== width || - util.height !== height - ) { - util.initialize(width, height); - } - - var map = util.getNextStep(width, height); - return map; - }; - - algo.rgbMapStepCount = function (width, height) { - var size = Number(algo.marqueeCount); - return size - }; - - // Development tool access - testAlgo = algo; - - return algo; -})(); diff --git a/resources/rgbscripts/plasmacolors.js b/resources/rgbscripts/plasmacolors.js deleted file mode 100644 index 168d7d4c5e..0000000000 --- a/resources/rgbscripts/plasmacolors.js +++ /dev/null @@ -1,357 +0,0 @@ -/* - Q Light Controller Plus - plasmacolors.js - - Copyright (c) Nathan Durnan - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0.txt - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Development tool access -var testAlgo; - -( -function() -{ - var colorPalette = new Object; - colorPalette.collection = new Array( - ["White" , 0xFFFFFF], // 0 - ["Cream" , 0xFFFF7F], // 1 - ["Pink" , 0xFF7F7F], // 2 - ["Rose" , 0x7F3F3F], // 3 - ["Coral" , 0x7F3F1F], // 4 - ["Dim Red" , 0x7F0000], // 5 - ["Red" , 0xFF0000], // 6 - ["Orange" , 0xFF3F00], // 7 - ["Dim Orange" , 0x7F1F00], // 8 - ["Goldenrod" , 0x7F3F00], // 9 - ["Gold" , 0xFF7F00], // 10 - ["Yellow" , 0xFFFF00], // 11 - ["Dim Yellow" , 0x7F7F00], // 12 - ["Lime" , 0x7FFF00], // 13 - ["Pale Green" , 0x3F7F00], // 14 - ["Dim Green" , 0x007F00], // 15 - ["Green" , 0x00FF00], // 16 - ["Seafoam" , 0x00FF3F], // 17 - ["Turquoise" , 0x007F3F], // 18 - ["Teal" , 0x007F7F], // 19 - ["Cyan" , 0x00FFFF], // 20 - ["Electric Blue", 0x007FFF], // 21 - ["Blue" , 0x0000FF], // 22 - ["Dim Blue" , 0x00007F], // 23 - ["Pale Blue" , 0x1F1F7F], // 24 - ["Indigo" , 0x1F00BF], // 25 - ["Purple" , 0x3F00BF], // 26 - ["Violet" , 0x7F007F], // 27 - ["Magenta" , 0xFF00FF], // 28 - ["Hot Pink" , 0xFF003F], // 29 - ["Deep Pink" , 0x7F001F], // 30 - ["OFF" , 0x000000]); // 31 - - colorPalette.makeSubArray = function(_index) - { - var _array = new Array(); - for (var i = 0; i < colorPalette.collection.length; i++) - { - _array.push(colorPalette.collection[i][_index]); - } - return _array; - }; - colorPalette.names = colorPalette.makeSubArray(0); - - var algo = new Object; - algo.apiVersion = 2; - algo.name = "Plasma (Colors)"; - algo.author = "Nathan Durnan"; - algo.acceptColors = 0; - algo.properties = new Array(); - algo.rstepcount = 0; - algo.gstepcount = 50; - algo.bstepcount = 100; - algo.color1Index = 0; - algo.properties.push( - "name:color1Index|type:list|display:Color 1|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor1|read:getColor1"); - algo.color2Index = 6; - algo.properties.push( - "name:color2Index|type:list|display:Color 2|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor2|read:getColor2"); - algo.color3Index = 16; - algo.properties.push( - "name:color3Index|type:list|display:Color 3|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor3|read:getColor3"); - algo.color4Index = 22; - algo.properties.push( - "name:color4Index|type:list|display:Color 4|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor4|read:getColor4"); - algo.color5Index = 31; - algo.properties.push( - "name:color5Index|type:list|display:Color 5|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor5|read:getColor5"); - algo.presetSize = 5; - algo.properties.push( - "name:presetSize|type:range|display:Size|" + - "values:1,20|write:setSize|read:getSize"); - algo.ramp = 15; - algo.properties.push( - "name:ramp|type:range|display:Ramp|" + - "values:10,30|write:setRamp|read:getRamp"); - algo.stepsize = 25; - algo.properties.push( - "name:stepsize|type:range|display:Speed|" + - "values:1,50|write:setStep|read:getStep"); - algo.colorIndex = new Array( - algo.color1Index, - algo.color2Index, - algo.color3Index, - algo.color4Index, - algo.color5Index); - - var util = new Object; - util.initialized = false; - util.gradientData = new Array(); - util.colorArray = new Array(); - - algo.setColor = function(_index, _preset) - { - var i = colorPalette.names.indexOf(_preset); - if (i === -1) { - i = (colorPalette.collection.length - 1); - } - algo.colorIndex[_index] = i; - return algo.colorIndex[_index]; - }; - - algo.getColor = function(_index) - { - var i = algo.colorIndex[_index]; - if (i < 0) { i = 0; } - if (i >= colorPalette.collection.length) { - i = (colorPalette.collection.length - 1); - } - return colorPalette.collection[i][0]; - }; - - algo.setColor1 = function(_preset) - { - algo.color1Index = algo.setColor(0, _preset); - util.initialize(); - }; - algo.getColor1 = function() - { - return algo.getColor(0); - }; - - algo.setColor2 = function(_preset) - { - algo.color2Index = algo.setColor(1, _preset); - util.initialize(); - }; - algo.getColor2 = function() - { - return algo.getColor(1); - }; - - algo.setColor3 = function(_preset) - { - algo.color3Index = algo.setColor(2, _preset); - util.initialize(); - }; - algo.getColor3 = function() - { - return algo.getColor(2); - }; - - algo.setColor4 = function(_preset) - { - algo.color4Index = algo.setColor(3, _preset); - util.initialize(); - }; - algo.getColor4 = function() - { - return algo.getColor(3); - }; - - algo.setColor5 = function(_preset) - { - algo.color5Index = algo.setColor(4, _preset); - util.initialize(); - }; - algo.getColor5 = function() - { - return algo.getColor(4); - }; - - algo.setSize = function(_size) - { - algo.presetSize = _size; - util.initialize(); - }; - algo.getSize = function() - { - return algo.presetSize; - }; - - algo.setRamp = function(_ramp) - { - algo.ramp = _ramp; - util.initialize(); - }; - algo.getRamp = function() - { - return algo.ramp; - }; - - algo.setStep = function(_step) - { - algo.stepsize = _step; - util.initialize(); - }; - algo.getStep = function() - { - return algo.stepsize; - }; - - util.initialize = function() - { - // calculate the gradient for the selected preset - // with the given width - var gradIdx = 0; - util.gradientData = new Array(); - util.colorArray = new Array(); - for (var j = 0; j < algo.colorIndex.length; j++) - { - util.colorArray[j] = colorPalette.collection[algo.colorIndex[j]][1]; - } - for (var i = 0; i < util.colorArray.length; i++) - { - var sColor = util.colorArray[i]; - var eColor = util.colorArray[i + 1]; - if (eColor == undefined) { - eColor = util.colorArray[0]; - } - util.gradientData[gradIdx++] = sColor; - var sr = (sColor >> 16) & 0x00FF; - var sg = (sColor >> 8) & 0x00FF; - var sb = sColor & 0x00FF; - var er = (eColor >> 16) & 0x00FF; - var eg = (eColor >> 8) & 0x00FF; - var eb = eColor & 0x00FF; - - var stepR = ((er - sr) / 300); - var stepG = ((eg - sg) / 300); - var stepB = ((eb - sb) / 300); - - for (var s = 1; s < 300; s++) - { - var gradR = Math.floor(sr + (stepR * s)) & 0x00FF; - var gradG = Math.floor(sg + (stepG * s)) & 0x00FF; - var gradB = Math.floor(sb + (stepB * s)) & 0x00FF; - var gradRGB = (gradR << 16) + (gradG << 8) + gradB; - util.gradientData[gradIdx++] = gradRGB; - } - } - util.initialized = true; - }; - - function fade(t) { return t * t * t * (t * (t * 6 - 15) + 10); } - function lerp( t, a, b) { return a + t * (b - a); } - function grad(hash, x, y, z) { - var h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE - var u = h<8 ? x : y, // INTO 12 GRADIENT DIRECTIONS. - v = h<4 ? y : h===12||h===14 ? x : z; - return ((h&1) === 0 ? u : -u) + ((h&2) === 0 ? v : -v); - } - function scale(n) { return (1 + n)/2; } - - // This is a port of Ken Perlin's Java code. The - // original Java code is at http://cs.nyu.edu/%7Eperlin/noise/. - // Note that in this version, a number from 0 to 1 is returned. - util.noise = function(x, y, z) - { - var p = new Array(512); - var permutation = [ 151,160,137,91,90,15,131,13,201,95,96,53,194,233, 7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190, 6,148,247,120,234,75, 0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20, 125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229, 122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54, 65,25,63,161,1, 216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100, 109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212, 207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152, 2,44,154, 163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232, 178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,49,192,214, 31,181,199,106,157,184, 84,204,176,115, 121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180]; - - for (var i=0; i < 256 ; i++) { - p[256+i] = p[i] = permutation[i]; - } - var X = Math.floor(x) & 255, // FIND UNIT CUBE THAT - Y = Math.floor(y) & 255, // CONTAINS POINT. - Z = Math.floor(z) & 255; - x -= Math.floor(x); // FIND RELATIVE X,Y,Z - y -= Math.floor(y); // OF POINT IN CUBE. - z -= Math.floor(z); - var u = fade(x), // COMPUTE FADE CURVES - v = fade(y), // FOR EACH OF X,Y,Z. - w = fade(z); - var A = p[X ]+Y, AA = p[A]+Z, AB = p[A+1]+Z, // HASH COORDINATES OF - B = p[X+1]+Y, BA = p[B]+Z, BB = p[B+1]+Z; // THE 8 CUBE CORNERS, - - return scale(lerp(w, lerp(v, lerp(u, grad(p[AA ], x , y , z ), // AND ADD - grad(p[BA ], x-1, y , z )), // BLENDED - lerp(u, grad(p[AB ], x , y-1, z ), // RESULTS - grad(p[BB ], x-1, y-1, z ))), // FROM 8 - lerp(v, lerp(u, grad(p[AA+1], x , y , z-1 ), // CORNERS - grad(p[BA+1], x-1, y , z-1 )), // OF CUBE - lerp(u, grad(p[AB+1], x , y-1, z-1 ), - grad(p[BB+1], x-1, y-1, z-1 ))))); - }; - - algo.rgbMap = function(width, height, rgb, step) - { - if (util.initialized === false) { - util.initialize(); - } - var size = algo.presetSize/2; // set a scaling value - var speed = Math.pow(100 , (algo.stepsize / 50)); // create a more uniform speed control - algo.bstepcount += (speed / 500); - algo.bstepcount = (algo.bstepcount % 256); // A rolling step count for the noise function - var square = width>height ? width : height; // keep the patten square - - var map = new Array(height); - for (var y = 0; y < height; y++) - { - map[y] = new Array(); - - for (var x = 0; x < width; x++) - { - var nx = x / square; // Normalize nx & ny to 0 - 1 - var ny = y / square; - var n = util.noise( size*nx, size*ny, algo.bstepcount); - var gradStep = Math.round( Math.pow(n , (algo.ramp/10)) * util.gradientData.length); - map[y][x] = util.gradientData[gradStep]; - } - } - - return map; - }; - - algo.rgbMapStepCount = function(width, height) - { - if (util.initialized === false) { - util.initialize(); - } - return width * height; // This make no difference to the script ;-) - }; - - // Development tool access - testAlgo = algo; - - return algo; -} -)(); diff --git a/resources/rgbscripts/plasmacolorsdirect.js b/resources/rgbscripts/plasmacolorsdirect.js deleted file mode 100644 index 3b09f02edb..0000000000 --- a/resources/rgbscripts/plasmacolorsdirect.js +++ /dev/null @@ -1,287 +0,0 @@ -/* - Q Light Controller Plus - plasmacolorsdirect.js - - Copyright (c) Nathan Durnan - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0.txt - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Development tool access -var testAlgo; - -( - function() - { - var algo = new Object; - algo.apiVersion = 3; - algo.name = "Plasma (5 Colors)"; - algo.author = "Nathan Durnan"; - algo.acceptColors = 5; - algo.properties = new Array(); - algo.rstepcount = 0; - algo.gstepcount = 50; - algo.bstepcount = 100; - algo.presetSize = 5; - algo.properties.push( - "name:presetSize|type:range|display:Size|" + - "values:1,20|write:setSize|read:getSize"); - algo.ramp = 15; - algo.properties.push( - "name:ramp|type:range|display:Ramp|" + - "values:10,30|write:setRamp|read:getRamp"); - algo.stepsize = 25; - algo.properties.push( - "name:stepsize|type:range|display:Speed|" + - "values:1,50|write:setStep|read:getStep"); - - var util = new Object; - util.initialized = false; - util.gradientData = new Array(); - util.colorArray = new Array(algo.acceptColors); - - algo.setSize = function(_size) - { - algo.presetSize = _size; - util.initialized = false; - }; - - algo.getSize = function() - { - return algo.presetSize; - }; - - algo.setRamp = function(_ramp) - { - algo.ramp = _ramp; - util.initialized = false; - }; - - algo.getRamp = function() - { - return algo.ramp; - }; - - algo.setStep = function(_step) - { - algo.stepsize = _step; - util.initialized = false; - }; - - algo.getStep = function() - { - return algo.stepsize; - }; - - util.getRawColor = function (idx) { - var color = 0; - if (Array.isArray(util.colorArray) && util.colorArray.length > idx && util.colorArray[idx]) { - color = util.colorArray[idx]; - } - return color; - } - - algo.rgbMapSetColors = function(rawColors) - { - if (! Array.isArray(rawColors)) - return; - for (var i = 0; i < algo.acceptColors; i++) { - if (i < rawColors.length) - { - util.colorArray[i] = rawColors[i]; - } else { - util.colorArray[i] = 0; - } - } - util.initialized = false; - } - - - util.initialize = function() - { - // calculate the gradient for the selected preset - // with the given width - var gradIdx = 0; - util.gradientData = new Array(); - for (var i = 0; i < util.colorArray.length; i++) - { - var sColor = util.colorArray[i]; - var eColor = util.colorArray[0]; - if (i < util.colorArray.length - 1) { - eColor = util.colorArray[i + 1]; - } - util.gradientData[gradIdx++] = sColor; - var sr = (sColor >> 16) & 0x00FF; - var sg = (sColor >> 8) & 0x00FF; - var sb = sColor & 0x00FF; - var er = (eColor >> 16) & 0x00FF; - var eg = (eColor >> 8) & 0x00FF; - var eb = eColor & 0x00FF; - - var stepR = ((er - sr) / 300); - var stepG = ((eg - sg) / 300); - var stepB = ((eb - sb) / 300); - - for (var s = 1; s < 300; s++) - { - var gradR = Math.floor(sr + (stepR * s)) & 0x00FF; - var gradG = Math.floor(sg + (stepG * s)) & 0x00FF; - var gradB = Math.floor(sb + (stepB * s)) & 0x00FF; - var gradRGB = (gradR << 16) + (gradG << 8) + gradB; - util.gradientData[gradIdx++] = gradRGB; - } - } - util.initialized = true; - }; - - // This is a port of Ken Perlin's Java code. The - // original Java code is at http://cs.nyu.edu/%7Eperlin/noise/. - // Note that in this version, a number from 0 to 1 is returned. - util.noise = function(x, y, z) - { - var p = new Array(512); - var permutation = [ // 256 members - 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, - 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, - 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, - 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, - 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, - 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, - 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, - 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, - 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, - 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, - 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, - 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, - 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, - 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, - 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, - 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, - 78, 66, 215, 61, 156, 180 - ]; - - // initialize symmetrical permutation array(512) - for (var i = 0; i < 256; i++) { - p[i] = permutation[i]; - p[256 + i] = permutation[i]; - } - // Find unit cube that contains point. - var X = Math.floor(x) & 255; - var Y = Math.floor(y) & 255; - var Z = Math.floor(z) & 255; - // Find relative x,y,z of point in cube. - x -= Math.floor(x); - y -= Math.floor(y); - z -= Math.floor(z); - // Compute fade curves for each of y, y, z - var u = fade(x); - var v = fade(y); - var w = fade(z); - // Hash coordinates of the 8 cube corners, - var A = p[X] + Y; - var AA = p[A] + Z; - var AB = p[A + 1] + Z; - var B = p[X + 1] + Y; - var BA = p[B] + Z; - var BB = p[B + 1] + Z; - - // And add blended results from8 corners of cube - var rawNoise = lerp(w, - lerp(v, lerp(u, grad(p[AA ], x , y , z ), - grad(p[BA ], x-1, y , z )), - lerp(u, grad(p[AB ], x , y - 1, z ), - grad(p[BB ], x-1, y - 1, z ))), - lerp(v, lerp(u, grad(p[AA + 1], x , y , z - 1), - grad(p[BA + 1], x-1, y , z - 1)), - lerp(u, grad(p[AB + 1], x , y - 1, z - 1), - grad(p[BB + 1], x-1, y - 1, z - 1))) - ); - // Scale to range between 0 and 1 - var noise = scale(rawNoise); - return noise; - }; - // Fade function for values between 0 and 1 - function fade(t) - { - // https://www.geogebra.org/calculator - // f(t)=t^(3) (t (t*6-15)+10) - var fade = t * t * t * (t * (t * 6 - 15) + 10); - return fade; - } - // https://en.wikipedia.org/wiki/Linear_interpolation - function lerp(t, a, b) - { - return a + t * (b - a); - } - // https://en.wikipedia.org/wiki/Gradient - function grad(hash, x, y, z) - { - // CONVERT TO 4 BITS OF HASH CODE - var h = hash & 0x0000000f; - // INTO 12 GRADIENT DIRECTIONS. - var u = (h < 8) ? x : y; - var v = (h < 4) ? y : (h === 12 || h === 14) ? x : z; - return (((h & 1) === 0) ? u : -1 * u) + (((h & 2) === 0) ? v : -1 * v); - } - function scale(n) - { - var scaled = (1 + n) / 2; - return scaled; - } - - algo.rgbMap = function(width, height, rgb, step) - { - if (util.initialized === false) - { - util.initialize(); - } - - // set a scaling value - var size = algo.presetSize / 2; - // create a more uniform speed control - var speed = Math.pow(100, (algo.stepsize / 50)); - algo.bstepcount += (speed / 500); - // A rolling step count for the noise function - algo.bstepcount = (algo.bstepcount % 256); - // keep the patten square - var square = (width > height) ? width : height; - - var map = new Array(height); - for (var y = 0; y < height; y++) - { - map[y] = new Array(); - - for (var x = 0; x < width; x++) - { - var nx = x / square; // Normalize nx & ny to 0 - 1 - var ny = y / square; - var n = util.noise(size * nx, size * ny, algo.bstepcount); - var gradStep = Math.round(Math.pow(n, (algo.ramp / 10)) * util.gradientData.length); - map[y][x] = util.gradientData[gradStep]; - } - } - - return map; - }; - - algo.rgbMapStepCount = function(width, height) - { - return 2; // This make no difference to the script ;-) - }; - - // Development tool access - testAlgo = algo; - - return algo; - } -)(); diff --git a/resources/rgbscripts/rgbscripts.pro b/resources/rgbscripts/rgbscripts.pro index 71190322a4..9b50cb1b15 100644 --- a/resources/rgbscripts/rgbscripts.pro +++ b/resources/rgbscripts/rgbscripts.pro @@ -4,7 +4,6 @@ TEMPLATE = subdirs TARGET = scripts scripts.files += alternate.js -scripts.files += alternatecolorsdirect.js scripts.files += balls.js scripts.files += ballscolors.js scripts.files += ballscolorsdirect.js @@ -22,13 +21,10 @@ scripts.files += flyingobjects.js scripts.files += gradient.js scripts.files += lines.js scripts.files += marquee.js -scripts.files += marqueecolorsdirect.js scripts.files += noise.js scripts.files += onebyone.js scripts.files += opposite.js scripts.files += plasma.js -scripts.files += plasmacolors.js -scripts.files += plasmacolorsdirect.js scripts.files += randomcolumn.js scripts.files += randomfillcolumn.js scripts.files += randomfillrow.js From 56a2fa88dbc94a7c32a3e6cdbed8232d44070051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Mon, 28 Oct 2024 20:44:00 +0100 Subject: [PATCH 56/63] In ballscolorsdirect, populate the colors with the colors that have been set. --- resources/rgbscripts/ballscolorsdirect.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/resources/rgbscripts/ballscolorsdirect.js b/resources/rgbscripts/ballscolorsdirect.js index 9d329fcb5c..9aa1dddb5e 100644 --- a/resources/rgbscripts/ballscolorsdirect.js +++ b/resources/rgbscripts/ballscolorsdirect.js @@ -65,10 +65,8 @@ var testAlgo; }; util.getRawColor = function (idx) { - var color = 0; - if (Array.isArray(util.colorArray) && util.colorArray.length > idx && util.colorArray[idx]) { - color = util.colorArray[idx]; - } + idx = idx % util.colorArray.length; + var color = util.colorArray[idx]; return color; } @@ -76,12 +74,13 @@ var testAlgo; { if (! Array.isArray(rawColors)) return; + util.colorArray = Array(); for (var i = 0; i < algo.acceptColors; i++) { - if (i < rawColors.length) + var isNumber = (rawColors[i] === rawColors[i]); + var color = rawColors[i]; + if (i < rawColors.length && isNumber) { - util.colorArray[i] = rawColors[i]; - } else { - util.colorArray[i] = 0; + util.colorArray.push(color); } } } @@ -117,7 +116,7 @@ var testAlgo; } for (var i = 0; i < algo.presetNumber; i++) { // for each ball displayed - rgb = util.getRawColor(i % algo.acceptColors); // use RGB for ball random colour + rgb = util.getRawColor(i); // use RGB for ball random colour var r = (rgb >> 16) & 0x00FF; // split colour in to var g = (rgb >> 8) & 0x00FF; // separate parts var b = rgb & 0x00FF; From eec1965f84e57ad49417cbfb19caca7e7dba911d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Mon, 28 Oct 2024 21:55:40 +0100 Subject: [PATCH 57/63] Merge ballsColors.js into balls.js including random colors and direct color settings --- resources/rgbscripts/balls.js | 215 ++++++++------- resources/rgbscripts/ballscolors.js | 317 ---------------------- resources/rgbscripts/ballscolorsdirect.js | 206 -------------- resources/rgbscripts/rgbscripts.pro | 2 - 4 files changed, 119 insertions(+), 621 deletions(-) delete mode 100644 resources/rgbscripts/ballscolors.js delete mode 100644 resources/rgbscripts/ballscolorsdirect.js diff --git a/resources/rgbscripts/balls.js b/resources/rgbscripts/balls.js index f957953ce3..fdfdc1e91b 100644 --- a/resources/rgbscripts/balls.js +++ b/resources/rgbscripts/balls.js @@ -2,16 +2,16 @@ Q Light Controller Plus balls.js - Copyright (c) Tim Cullingworth + Copyright (c) Rob Nieuwenhuizen, Tim Cullingworth - Licensed under the Apache License, Version 2.0 (the "License"); + Licensed under the Apache License, Version 2.0 (the 'License'); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.txt Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, + distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. @@ -21,122 +21,149 @@ var testAlgo; ( - function() - { + function () { var algo = new Object; - algo.apiVersion = 2; + algo.apiVersion = 3; algo.name = "Balls"; - algo.author = "Tim Cullingworth"; - algo.acceptColors = 1; + algo.author = "Rob Nieuwenhuizen, Tim Cullingworth"; + algo.acceptColors = 5; algo.properties = new Array(); - algo.rstepcount = 0; - algo.gstepcount = 50; - algo.bstepcount = 100; - algo.presetSize = 1; - algo.properties.push("name:presetSize|type:range|display:Size|values:1,20|write:setSize|read:getSize"); + algo.properties.push( + "name:presetSize|type:range|display:Size|" + + "values:1,20|write:setSize|read:getSize"); algo.presetNumber = 5; - algo.properties.push("name:presetNumber|type:range|display:Number|values:1,50|write:setNumber|read:getNumber"); - algo.presetRandom = 1; - algo.properties.push("name:presetRandom|type:list|display:Random Colour|values:No,Yes|write:setRandom|read:getRandom"); - algo.presetCollision = 1; - algo.properties.push("name:presetCollision|type:list|display:Self Collision|values:No,Yes|write:setCollision|read:getCollision"); - var util = new Object; + algo.properties.push( + "name:presetNumber|type:range|display:Number|" + + "values:1,15|write:setNumber|read:getNumber"); + algo.presetCollision = 0; + algo.properties.push( + "name:presetCollision|type:list|display:Self Collision|" + + "values:No,Yes|write:setCollision|read:getCollision"); + algo.presetSize = 5; + algo.properties.push( + "name:presetIndex|type:list|display:Preset|" + + "values:User Defined,Random|" + + "write:setPreset|read:getPreset"); + algo.presetIndex = 0; + algo.initialized = false; + + var util = new Object; + util.colorArray = new Array(algo.acceptColors); - algo.setSize = function(_size) - { + algo.setSize = function (_size) { algo.presetSize = _size; }; - - algo.getSize = function() - { + algo.getSize = function () { return algo.presetSize; }; - algo.setNumber = function(_step) - { + algo.setNumber = function (_step) { algo.presetNumber = _step; algo.initialized = false; }; - - algo.getNumber = function() - { + algo.getNumber = function () { return algo.presetNumber; }; - - algo.setRandom = function(_random) - { - if (_random === "Yes") { algo.presetRandom = 0; } - else if (_random === "No") { algo.presetRandom = 1; } + algo.setCollision = function (_colision) { + if (_colision === "Yes") { algo.presetCollision = 0; } + else if (_colision === "No") { algo.presetCollision = 1; } }; - - algo.getRandom = function() - { - if (algo.presetRandom === 0) { return "Yes"; } - else if (algo.presetRandom === 1) { return "No"; } + algo.getCollision = function () { + if (algo.presetCollision === 0) { return "Yes"; } + else if (algo.presetCollision === 1) { return "No"; } }; - algo.setCollision = function(_colision) + util.getRawColor = function (idx) { + idx = idx % util.colorArray.length; + var color = util.colorArray[idx]; + return color; + } + + algo.setPreset = function(_preset) { - if (_colision === "Yes") { algo.presetCollision = 0; } - else if (_colision === "No") { algo.presetCollision = 1; } + algo.acceptColors = 0; + if (_preset === "User Defined") + { + algo.presetIndex = 0; + algo.acceptColors = 5; + util.colorArray = [ 0x00FF00, 0xFFAA00, 0x0000FF, 0xFFFF00, 0x00AAFF ]; + } + else if (_preset === "Random") + { + algo.presetIndex = 1; + util.colorArray = new Array(); + for (var i = 0; i < algo.presetNumber; i++) + { + do + { + var ballR = Math.round(Math.random() * 255); // Chose random + var ballG = Math.round(Math.random() * 255); // colour for + var ballB = Math.round(Math.random() * 255); // each Ball + } while ((ballR + ballG + ballB) < 356); // if it it to dim try again + util.colorArray[i] = (ballR << 16) + (ballG << 8) + ballB; + } + } + else { algo.presetIndex = 0; } + util.initialized = false; }; - algo.getCollision = function() + algo.getPreset = function() { - if (algo.presetCollision === 0) { return "Yes"; } - else if (algo.presetCollision === 1) { return "No"; } + if (algo.presetIndex === 0) { return "User Defined"; } + else if (algo.presetIndex === 1) { return "Random"; } + else { return "Rainbow"; } }; - - util.initialize = function(width, height) + + algo.rgbMapSetColors = function(rawColors) { + if (! Array.isArray(rawColors)) + return; + if (algo.acceptColors > 0) + util.colorArray = Array(); + for (var i = 0; i < algo.acceptColors; i++) { + var isNumber = (rawColors[i] === rawColors[i]); + var color = rawColors[i]; + if (i < rawColors.length && isNumber) + { + util.colorArray.push(color); + } + } + } + + util.initialize = function (width, height) { algo.ball = new Array(algo.presetNumber); algo.direction = new Array(algo.presetNumber); - algo.colour = new Array(algo.presetNumber); - for (var i = 0; i < algo.presetNumber; i++) - { + for (var i = 0; i < algo.presetNumber; i++) { var x = Math.random() * (width - 1); // set random start var y = Math.random() * (height - 1); // locations for balls algo.ball[i] = [y, x]; var yDirection = (Math.random() * 2) - 1; // and random directions var xDirection = (Math.random() * 2) - 1; algo.direction[i] = [yDirection, xDirection]; - do - { - var ballR = Math.round(Math.random() * 255); // Chose random - var ballG = Math.round(Math.random() * 255); // colour for - var ballB = Math.round(Math.random() * 255); // each Ball - } while ((ballR + ballG + ballB) < 356); // if it it to dim try again - algo.colour[i] = (ballR << 16) + (ballG << 8) + ballB; } - - algo.initialized = true; - return; + algo.initialized = true; + return; }; - algo.rgbMap = function(width, height, rgb, progstep) - { - if (algo.initialized === false) - { + algo.rgbMap = function (width, height, rgb, progstep) { + if (algo.initialized === false) { util.initialize(width, height); } - var map = new Array(height); // Clear map data - for (var y = 0; y < height; y++) - { - map[y] = new Array(); + var map = new Array(height); // Clear map data + for (var y = 0; y < height; y++) { + map[y] = new Array(); - for (var x = 0; x < width; x++) - { - map[y][x] = 0; - } + for (var x = 0; x < width; x++) { + map[y][x] = 0; + } } - for (var i = 0; i < algo.presetNumber; i++) // for each ball displayed - { - if (algo.presetRandom === 0) { rgb = algo.colour[i]; } // use RGB or ball random colour + for (var i = 0; i < algo.presetNumber; i++) { // for each ball displayed + rgb = util.getRawColor(i); // use RGB for ball random colour var r = (rgb >> 16) & 0x00FF; // split colour in to var g = (rgb >> 8) & 0x00FF; // separate parts var b = rgb & 0x00FF; @@ -146,13 +173,12 @@ var testAlgo; var mx = Math.floor(yx[1]); var boxSize = Math.round(algo.presetSize / 2); // area size to draw ball - for (var ry = my-boxSize; ry < my+boxSize+2; ry++) // area for faded edges - { - for (var rx = mx-boxSize; rx < mx+boxSize+2; rx++) // to display ball - { - if (rx < width && rx > -1 && ry < height && ry > -1) // if edges are off the map - { // dont draw - var pointRGB = map[ry][rx]; // get curent colour on the map + for (var ry = my - boxSize; ry < my + boxSize + 2; ry++) { // area for faded edges + + for (var rx = mx - boxSize; rx < mx + boxSize + 2; rx++) { // to display ball + + if (rx < width && rx > -1 && ry < height && ry > -1) { // if edges are off the map dont draw + var pointRGB = map[ry][rx]; // get curent colour on the map var pointr = (pointRGB >> 16) & 0x00FF;// so that colours mix and don't over var pointg = (pointRGB >> 8) & 0x00FF; // write. var pointb = pointRGB & 0x00FF; // splt rgb in to components @@ -161,7 +187,8 @@ var testAlgo; var ballb = b; var offx = rx - yx[1]; // calculate the off set differance of map location var offy = ry - yx[0]; // to the float location of the ball, using the hypotenuse - var hyp = 1 - (Math.sqrt( (offx * offx) + (offy * offy))/((algo.presetSize/2)+1)); + var hyp = 1 - (Math.sqrt((offx * offx) + (offy * offy)) / ((algo.presetSize / 2) + 1)); + if (hyp < 0) { hyp = 0; } // if the distance multiplyed by ball size is negative = 0 pointr += Math.round(ballr * hyp); // dim mapped ball colours by the distance from pointg += Math.round(ballg * hyp); // the ball center ( hyp = 1, full colour / 0, off) @@ -176,18 +203,16 @@ var testAlgo; } } } - if (algo.presetCollision === 0) // if colision detection is on - { + + if (algo.presetCollision === 0) { // if colision detection is on // Ball collision detection - for (var ti = 0; ti < algo.presetNumber; ti++) // check all balls - { - if (ti !== i) // but not the current one - { + for (var ti = 0; ti < algo.presetNumber; ti++) { // check all balls + + if (ti !== i) { // but not the current one var disy = (yx[0] + step[0]) - algo.ball[ti][0]; // calculate distance var disx = (yx[1] + step[1]) - algo.ball[ti][1]; // to current ball var dish = Math.sqrt((disx * disx) + (disy * disy)); - if (dish < (1.414) * (algo.presetSize/2)) // if to close - { + if (dish < (1.414) * (algo.presetSize / 2)) { // if to close var stepy = step[0]; // swap speed / direction of current ball var stepx = step[1]; // with ball that is to close algo.direction[i][0] = algo.direction[ti][0]; @@ -201,10 +226,10 @@ var testAlgo; // edge collision detection if (yx[0] <= 0 && step[0] < 0) { step[0] *= -1; } // top edge and moving up - else if (yx[0] >= height-1 && step[0] > 0) { step[0] *= -1; } // bottom edge and moving down + else if (yx[0] >= height - 1 && step[0] > 0) { step[0] *= -1; } // bottom edge and moving down if (yx[1] <= 0 && step[1] < 0) { step[1] *= -1; } // left edge and moving left - else if (yx[1] >= width-1 && step[1] > 0) { step[1] *= -1; } // right edge and moving right + else if (yx[1] >= width - 1 && step[1] > 0) { step[1] *= -1; } // right edge and moving right yx[0] += step[0]; // set ball's next location yx[1] += step[1]; @@ -212,12 +237,10 @@ var testAlgo; algo.ball[i] = yx; // update location algo.direction[i] = step; // and direction / speed } - return map; }; - algo.rgbMapStepCount = function(width, height) - { + algo.rgbMapStepCount = function (width, height) { // This make no difference to the script ;-) return 2; }; diff --git a/resources/rgbscripts/ballscolors.js b/resources/rgbscripts/ballscolors.js deleted file mode 100644 index 994cacfde4..0000000000 --- a/resources/rgbscripts/ballscolors.js +++ /dev/null @@ -1,317 +0,0 @@ -/* - Q Light Controller Plus - ballscolors.js - - Copyright (c) Rob Nieuwenhuizen - - Licensed under the Apache License, Version 2.0 (the 'License'); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0.txt - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an 'AS IS' BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Development tool access -var testAlgo; - -( - function () { - var colorPalette = new Object; - colorPalette.collection = new Array( - ["White" , 0xFFFFFF], // 0 - ["Cream" , 0xFFFF7F], // 1 - ["Pink" , 0xFF7F7F], // 2 - ["Rose" , 0x7F3F3F], // 3 - ["Coral" , 0x7F3F1F], // 4 - ["Dim Red" , 0x7F0000], // 5 - ["Red" , 0xFF0000], // 6 - ["Orange" , 0xFF3F00], // 7 - ["Dim Orange" , 0x7F1F00], // 8 - ["Goldenrod" , 0x7F3F00], // 9 - ["Gold" , 0xFF7F00], // 10 - ["Yellow" , 0xFFFF00], // 11 - ["Dim Yellow" , 0x7F7F00], // 12 - ["Lime" , 0x7FFF00], // 13 - ["Pale Green" , 0x3F7F00], // 14 - ["Dim Green" , 0x007F00], // 15 - ["Green" , 0x00FF00], // 16 - ["Seafoam" , 0x00FF3F], // 17 - ["Turquoise" , 0x007F3F], // 18 - ["Teal" , 0x007F7F], // 19 - ["Cyan" , 0x00FFFF], // 20 - ["Electric Blue", 0x007FFF], // 21 - ["Blue" , 0x0000FF], // 22 - ["Dim Blue" , 0x00007F], // 23 - ["Pale Blue" , 0x1F1F7F], // 24 - ["Indigo" , 0x1F00BF], // 25 - ["Purple" , 0x3F00BF], // 26 - ["Violet" , 0x7F007F], // 27 - ["Magenta" , 0xFF00FF], // 28 - ["Hot Pink" , 0xFF003F], // 29 - ["Deep Pink" , 0x7F001F], // 30 - ["Black" , 0x000000]); // 31 - - colorPalette.makeSubArray = function (_index) { - var _array = new Array(); - for (var i = 0; i < colorPalette.collection.length; i++) { - _array.push(colorPalette.collection[i][_index]); - } - return _array; - }; - colorPalette.names = colorPalette.makeSubArray(0); - - var algo = new Object; - algo.apiVersion = 2; - algo.name = "Balls (Colors)"; - algo.author = "Rob Nieuwenhuizen"; - algo.acceptColors = 0; - algo.properties = new Array(); - algo.presetSize = 1; - algo.properties.push("name:presetSize|type:range|display:Size|values:1,20|write:setSize|read:getSize"); - algo.presetNumber = 5; - algo.properties.push("name:presetNumber|type:range|display:Number|values:1,5|write:setNumber|read:getNumber"); - algo.presetCollision = 0; - algo.properties.push("name:presetCollision|type:list|display:Self Collision|values:No,Yes|write:setCollision|read:getCollision"); - algo.color1Index = 0; - algo.properties.push( - "name:color1Index|type:list|display:Color 1|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor1|read:getColor1"); - algo.color2Index = 6; - algo.properties.push( - "name:color2Index|type:list|display:Color 2|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor2|read:getColor2"); - algo.color3Index = 16; - algo.properties.push( - "name:color3Index|type:list|display:Color 3|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor3|read:getColor3"); - algo.color4Index = 22; - algo.properties.push( - "name:color4Index|type:list|display:Color 4|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor4|read:getColor4"); - algo.color5Index = 7; - algo.properties.push( - "name:color5Index|type:list|display:Color 5|" + - "values:" + colorPalette.names.toString() + "|" + - "write:setColor5|read:getColor5"); - algo.presetSize = 5; - - algo.colorIndex = new Array( - algo.color1Index, - algo.color2Index, - algo.color3Index, - algo.color4Index, - algo.color5Index); - - var util = new Object; - algo.initialized = false; - - algo.setSize = function (_size) { - algo.presetSize = _size; - }; - algo.getSize = function () { - return algo.presetSize; - }; - - algo.setNumber = function (_step) { - algo.presetNumber = _step; - algo.initialized = false; - }; - algo.getNumber = function () { - return algo.presetNumber; - }; - algo.setCollision = function (_colision) { - if (_colision === "Yes") { algo.presetCollision = 0; } - else if (_colision === "No") { algo.presetCollision = 1; } - }; - algo.getCollision = function () { - if (algo.presetCollision === 0) { return "Yes"; } - else if (algo.presetCollision === 1) { return "No"; } - }; - - algo.setColor = function (_index, _preset) { - var i = colorPalette.names.indexOf(_preset); - if (i === -1) { - i = (colorPalette.collection.length - 1); - } - algo.colorIndex[_index] = i; - return algo.colorIndex[_index]; - }; - algo.getColor = function (_index) { - var i = algo.colorIndex[_index]; - if (i < 0) { i = 0; } - if (i >= colorPalette.collection.length) { - i = (colorPalette.collection.length - 1); - } - return colorPalette.collection[i][0]; - }; - - algo.setColor1 = function (_preset) { - algo.color1Index = algo.setColor(0, _preset); - algo.initialized = false; - }; - algo.getColor1 = function () { - return algo.getColor(0); - }; - - algo.setColor2 = function (_preset) { - algo.color2Index = algo.setColor(1, _preset); - algo.initialized = false; - }; - algo.getColor2 = function () { - return algo.getColor(1); - }; - - algo.setColor3 = function (_preset) { - algo.color3Index = algo.setColor(2, _preset); - algo.initialized = false; - }; - algo.getColor3 = function () { - return algo.getColor(2); - }; - - algo.setColor4 = function (_preset) { - algo.color4Index = algo.setColor(3, _preset); - algo.initialized = false; - }; - algo.getColor4 = function () { - return algo.getColor(3); - }; - - algo.setColor5 = function (_preset) { - algo.color5Index = algo.setColor(4, _preset); - algo.initialized = false; - }; - algo.getColor5 = function () { - return algo.getColor(4); - }; - - util.initialize = function (width, height) { - algo.ball = new Array(algo.presetNumber); - algo.direction = new Array(algo.presetNumber); - algo.colour = new Array(algo.presetNumber); - - for (var i = 0; i < algo.presetNumber; i++) { - var x = Math.random() * (width - 1); // set random start - var y = Math.random() * (height - 1); // locations for balls - algo.ball[i] = [y, x]; - var yDirection = (Math.random() * 2) - 1; // and random directions - var xDirection = (Math.random() * 2) - 1; - algo.direction[i] = [yDirection, xDirection]; - algo.colour[i] = colorPalette.collection[algo.colorIndex[i]][1]; - } - algo.initialized = true; - return; - }; - - algo.rgbMap = function (width, height, rgb, progstep) { - if (algo.initialized === false) { - util.initialize(width, height); - } - var map = new Array(height); // Clear map data - for (var y = 0; y < height; y++) { - map[y] = new Array(); - - for (var x = 0; x < width; x++) { - map[y][x] = 0; - } - } - - for (var i = 0; i < algo.presetNumber; i++) { // for each ball displayed - rgb = algo.colour[i]; // use RGB for ball random colour - var r = (rgb >> 16) & 0x00FF; // split colour in to - var g = (rgb >> 8) & 0x00FF; // separate parts - var b = rgb & 0x00FF; - var yx = algo.ball[i]; // ball's location, as float - var step = algo.direction[i]; // ball's direction / speed, as float - var my = Math.floor(yx[0]); // workout closest map location for ball - var mx = Math.floor(yx[1]); - var boxSize = Math.round(algo.presetSize / 2); // area size to draw ball - - for (var ry = my - boxSize; ry < my + boxSize + 2; ry++) { // area for faded edges - - for (var rx = mx - boxSize; rx < mx + boxSize + 2; rx++) { // to display ball - - if (rx < width && rx > -1 && ry < height && ry > -1) { // if edges are off the map dont draw - var pointRGB = map[ry][rx]; // get curent colour on the map - var pointr = (pointRGB >> 16) & 0x00FF;// so that colours mix and don't over - var pointg = (pointRGB >> 8) & 0x00FF; // write. - var pointb = pointRGB & 0x00FF; // splt rgb in to components - var ballr = r; - var ballg = g; - var ballb = b; - var offx = rx - yx[1]; // calculate the off set differance of map location - var offy = ry - yx[0]; // to the float location of the ball, using the hypotenuse - var hyp = 1 - (Math.sqrt((offx * offx) + (offy * offy)) / ((algo.presetSize / 2) + 1)); - - if (hyp < 0) { hyp = 0; } // if the distance multiplyed by ball size is negative = 0 - pointr += Math.round(ballr * hyp); // dim mapped ball colours by the distance from - pointg += Math.round(ballg * hyp); // the ball center ( hyp = 1, full colour / 0, off) - pointb += Math.round(ballb * hyp); // add the ball colour to the mapped location - if (pointr > 255) { pointr = 255; } // if addind the colours over saturates - if (pointg > 255) { pointg = 255; } // reduce it to the maximum - if (pointb > 255) { pointb = 255; } - - pointRGB = (pointr << 16) + (pointg << 8) + pointb; // combine colours - - map[ry][rx] = pointRGB; // set mapped point - } - } - } - - if (algo.presetCollision === 0) { // if colision detection is on - // Ball collision detection - for (var ti = 0; ti < algo.presetNumber; ti++) { // check all balls - - if (ti !== i) { // but not the current one - var disy = (yx[0] + step[0]) - algo.ball[ti][0]; // calculate distance - var disx = (yx[1] + step[1]) - algo.ball[ti][1]; // to current ball - var dish = Math.sqrt((disx * disx) + (disy * disy)); - if (dish < (1.414) * (algo.presetSize / 2)) { // if to close - var stepy = step[0]; // swap speed / direction of current ball - var stepx = step[1]; // with ball that is to close - algo.direction[i][0] = algo.direction[ti][0]; - algo.direction[i][1] = algo.direction[ti][1]; - algo.direction[ti][0] = stepy; - algo.direction[ti][1] = stepx; - } - } - } - } - - // edge collision detection - if (yx[0] <= 0 && step[0] < 0) { step[0] *= -1; } // top edge and moving up - else if (yx[0] >= height - 1 && step[0] > 0) { step[0] *= -1; } // bottom edge and moving down - - if (yx[1] <= 0 && step[1] < 0) { step[1] *= -1; } // left edge and moving left - else if (yx[1] >= width - 1 && step[1] > 0) { step[1] *= -1; } // right edge and moving right - - yx[0] += step[0]; // set ball's next location - yx[1] += step[1]; - - algo.ball[i] = yx; // update location - algo.direction[i] = step; // and direction / speed - } - return map; - }; - - algo.rgbMapStepCount = function (width, height) { - // This make no difference to the script ;-) - return 2; - }; - - // Development tool access - testAlgo = algo; - - return algo; - } -)(); diff --git a/resources/rgbscripts/ballscolorsdirect.js b/resources/rgbscripts/ballscolorsdirect.js deleted file mode 100644 index 9aa1dddb5e..0000000000 --- a/resources/rgbscripts/ballscolorsdirect.js +++ /dev/null @@ -1,206 +0,0 @@ -/* - Q Light Controller Plus - ballscolorsdirect.js - - Copyright (c) Rob Nieuwenhuizen - - Licensed under the Apache License, Version 2.0 (the 'License'); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0.txt - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an 'AS IS' BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Development tool access -var testAlgo; - -( - function () { - var algo = new Object; - algo.apiVersion = 3; - algo.name = "Balls (5 Colors)"; - algo.author = "Rob Nieuwenhuizen"; - algo.acceptColors = 5; - algo.properties = new Array(); - algo.presetSize = 1; - algo.properties.push("name:presetSize|type:range|display:Size|values:1,20|write:setSize|read:getSize"); - algo.presetNumber = 5; - algo.properties.push("name:presetNumber|type:range|display:Number|values:1,15|write:setNumber|read:getNumber"); - algo.presetCollision = 0; - algo.properties.push("name:presetCollision|type:list|display:Self Collision|values:No,Yes|write:setCollision|read:getCollision"); - algo.presetSize = 5; - - algo.initialized = false; - - var util = new Object; - util.colorArray = new Array(algo.acceptColors); - - algo.setSize = function (_size) { - algo.presetSize = _size; - }; - algo.getSize = function () { - return algo.presetSize; - }; - - algo.setNumber = function (_step) { - algo.presetNumber = _step; - algo.initialized = false; - }; - algo.getNumber = function () { - return algo.presetNumber; - }; - algo.setCollision = function (_colision) { - if (_colision === "Yes") { algo.presetCollision = 0; } - else if (_colision === "No") { algo.presetCollision = 1; } - }; - algo.getCollision = function () { - if (algo.presetCollision === 0) { return "Yes"; } - else if (algo.presetCollision === 1) { return "No"; } - }; - - util.getRawColor = function (idx) { - idx = idx % util.colorArray.length; - var color = util.colorArray[idx]; - return color; - } - - algo.rgbMapSetColors = function(rawColors) - { - if (! Array.isArray(rawColors)) - return; - util.colorArray = Array(); - for (var i = 0; i < algo.acceptColors; i++) { - var isNumber = (rawColors[i] === rawColors[i]); - var color = rawColors[i]; - if (i < rawColors.length && isNumber) - { - util.colorArray.push(color); - } - } - } - - util.initialize = function (width, height) { - algo.ball = new Array(algo.presetNumber); - algo.direction = new Array(algo.presetNumber); - - for (var i = 0; i < algo.presetNumber; i++) { - var x = Math.random() * (width - 1); // set random start - var y = Math.random() * (height - 1); // locations for balls - algo.ball[i] = [y, x]; - var yDirection = (Math.random() * 2) - 1; // and random directions - var xDirection = (Math.random() * 2) - 1; - algo.direction[i] = [yDirection, xDirection]; - } - algo.initialized = true; - return; - }; - - algo.rgbMap = function (width, height, rgb, progstep) { - if (algo.initialized === false) { - util.initialize(width, height); - } - - var map = new Array(height); // Clear map data - for (var y = 0; y < height; y++) { - map[y] = new Array(); - - for (var x = 0; x < width; x++) { - map[y][x] = 0; - } - } - - for (var i = 0; i < algo.presetNumber; i++) { // for each ball displayed - rgb = util.getRawColor(i); // use RGB for ball random colour - var r = (rgb >> 16) & 0x00FF; // split colour in to - var g = (rgb >> 8) & 0x00FF; // separate parts - var b = rgb & 0x00FF; - var yx = algo.ball[i]; // ball's location, as float - var step = algo.direction[i]; // ball's direction / speed, as float - var my = Math.floor(yx[0]); // workout closest map location for ball - var mx = Math.floor(yx[1]); - var boxSize = Math.round(algo.presetSize / 2); // area size to draw ball - - for (var ry = my - boxSize; ry < my + boxSize + 2; ry++) { // area for faded edges - - for (var rx = mx - boxSize; rx < mx + boxSize + 2; rx++) { // to display ball - - if (rx < width && rx > -1 && ry < height && ry > -1) { // if edges are off the map dont draw - var pointRGB = map[ry][rx]; // get curent colour on the map - var pointr = (pointRGB >> 16) & 0x00FF;// so that colours mix and don't over - var pointg = (pointRGB >> 8) & 0x00FF; // write. - var pointb = pointRGB & 0x00FF; // splt rgb in to components - var ballr = r; - var ballg = g; - var ballb = b; - var offx = rx - yx[1]; // calculate the off set differance of map location - var offy = ry - yx[0]; // to the float location of the ball, using the hypotenuse - var hyp = 1 - (Math.sqrt((offx * offx) + (offy * offy)) / ((algo.presetSize / 2) + 1)); - - if (hyp < 0) { hyp = 0; } // if the distance multiplyed by ball size is negative = 0 - pointr += Math.round(ballr * hyp); // dim mapped ball colours by the distance from - pointg += Math.round(ballg * hyp); // the ball center ( hyp = 1, full colour / 0, off) - pointb += Math.round(ballb * hyp); // add the ball colour to the mapped location - if (pointr > 255) { pointr = 255; } // if addind the colours over saturates - if (pointg > 255) { pointg = 255; } // reduce it to the maximum - if (pointb > 255) { pointb = 255; } - - pointRGB = (pointr << 16) + (pointg << 8) + pointb; // combine colours - - map[ry][rx] = pointRGB; // set mapped point - } - } - } - - if (algo.presetCollision === 0) { // if colision detection is on - // Ball collision detection - for (var ti = 0; ti < algo.presetNumber; ti++) { // check all balls - - if (ti !== i) { // but not the current one - var disy = (yx[0] + step[0]) - algo.ball[ti][0]; // calculate distance - var disx = (yx[1] + step[1]) - algo.ball[ti][1]; // to current ball - var dish = Math.sqrt((disx * disx) + (disy * disy)); - if (dish < (1.414) * (algo.presetSize / 2)) { // if to close - var stepy = step[0]; // swap speed / direction of current ball - var stepx = step[1]; // with ball that is to close - algo.direction[i][0] = algo.direction[ti][0]; - algo.direction[i][1] = algo.direction[ti][1]; - algo.direction[ti][0] = stepy; - algo.direction[ti][1] = stepx; - } - } - } - } - - // edge collision detection - if (yx[0] <= 0 && step[0] < 0) { step[0] *= -1; } // top edge and moving up - else if (yx[0] >= height - 1 && step[0] > 0) { step[0] *= -1; } // bottom edge and moving down - - if (yx[1] <= 0 && step[1] < 0) { step[1] *= -1; } // left edge and moving left - else if (yx[1] >= width - 1 && step[1] > 0) { step[1] *= -1; } // right edge and moving right - - yx[0] += step[0]; // set ball's next location - yx[1] += step[1]; - - algo.ball[i] = yx; // update location - algo.direction[i] = step; // and direction / speed - } - return map; - }; - - algo.rgbMapStepCount = function (width, height) { - // This make no difference to the script ;-) - return 2; - }; - - // Development tool access - testAlgo = algo; - - return algo; - } -)(); diff --git a/resources/rgbscripts/rgbscripts.pro b/resources/rgbscripts/rgbscripts.pro index 9b50cb1b15..a50c513885 100644 --- a/resources/rgbscripts/rgbscripts.pro +++ b/resources/rgbscripts/rgbscripts.pro @@ -5,8 +5,6 @@ TARGET = scripts scripts.files += alternate.js scripts.files += balls.js -scripts.files += ballscolors.js -scripts.files += ballscolorsdirect.js scripts.files += blinder.js scripts.files += circles.js scripts.files += circular.js From 7b74247b19f6d6b31a47d4a6142b97dbb93729a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Mon, 28 Oct 2024 22:14:48 +0100 Subject: [PATCH 58/63] Fix cmake / Windows build. --- resources/rgbscripts/CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/resources/rgbscripts/CMakeLists.txt b/resources/rgbscripts/CMakeLists.txt index 2e6925a3c8..8571758ea7 100644 --- a/resources/rgbscripts/CMakeLists.txt +++ b/resources/rgbscripts/CMakeLists.txt @@ -2,10 +2,7 @@ project(scripts) set(SCRIPT_FILES alternate.js - alternatecolorsdirect.js balls.js - ballscolors.js - ballscolorsdirect.js blinder.js circles.js circular.js @@ -20,13 +17,11 @@ set(SCRIPT_FILES gradient.js lines.js marquee.js - marqueecolorsdirect.js noise.js onebyone.js opposite.js plasma.js plasmacolors.js - plasmacolorsdirect.js randomcolumn.js randomfillcolumn.js randomfillrow.js From 90d14b0124d7e72a4d2c9bac209e150e8489294c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Mon, 28 Oct 2024 22:29:31 +0100 Subject: [PATCH 59/63] Also remove plasmaColors.js in cmake. --- resources/rgbscripts/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/rgbscripts/CMakeLists.txt b/resources/rgbscripts/CMakeLists.txt index 8571758ea7..21a8b28607 100644 --- a/resources/rgbscripts/CMakeLists.txt +++ b/resources/rgbscripts/CMakeLists.txt @@ -21,7 +21,6 @@ set(SCRIPT_FILES onebyone.js opposite.js plasma.js - plasmacolors.js randomcolumn.js randomfillcolumn.js randomfillrow.js From 0cc5540737a7222e2d173d39d54b178933d497fd Mon Sep 17 00:00:00 2001 From: Massimo Callegari Date: Mon, 30 Dec 2024 12:04:09 +0100 Subject: [PATCH 60/63] engine: improve some coverage --- engine/src/rgbalgorithm.cpp | 16 +++++++------ .../test/rgbalgorithm/rgbalgorithm_test.cpp | 23 ++++++++++++++----- engine/test/rgbtext/rgbtext_test.cpp | 8 +++++++ engine/test/rgbtext/rgbtext_test.h | 1 + 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/engine/src/rgbalgorithm.cpp b/engine/src/rgbalgorithm.cpp index 3b87ef052d..86cabdce4d 100644 --- a/engine/src/rgbalgorithm.cpp +++ b/engine/src/rgbalgorithm.cpp @@ -44,19 +44,21 @@ RGBAlgorithm::RGBAlgorithm(Doc * doc) void RGBAlgorithm::setColors(QVector colors) { + int nCols = acceptColors(); m_colors.clear(); - QVectorIterator it(colors); - int count = 0; - while (it.hasNext()) { - QColor color = it.next(); - if (acceptColors() < count) - m_colors.append(color); - count ++; + + for (int i = 0; i < nCols; i++) + { + if (i < colors.count()) + m_colors.append(colors.at(i)); } } QColor RGBAlgorithm::getColor(uint i) const { + if (i >= (uint)m_colors.count()) + return QColor(); + return m_colors[i]; } diff --git a/engine/test/rgbalgorithm/rgbalgorithm_test.cpp b/engine/test/rgbalgorithm/rgbalgorithm_test.cpp index d73c505d45..89d6b558b9 100644 --- a/engine/test/rgbalgorithm/rgbalgorithm_test.cpp +++ b/engine/test/rgbalgorithm/rgbalgorithm_test.cpp @@ -85,12 +85,23 @@ void RGBAlgorithm_Test::algorithm() QVERIFY(algo != NULL); QCOMPARE(algo->type(), RGBAlgorithm::Script); QCOMPARE(algo->name(), QString("Stripes")); - printf("%s\n", algo->name().toStdString().c_str()); - printf("%s\n", algo->name().toStdString().c_str()); - printf("%s\n", algo->name().toStdString().c_str()); - printf("%s\n", algo->name().toStdString().c_str()); - printf("%s\n", algo->name().toStdString().c_str()); - printf("%s\n", algo->name().toStdString().c_str()); + delete algo; + + algo = RGBAlgorithm::algorithm(m_doc, "Balls"); + QVERIFY(algo != NULL); + QCOMPARE(algo->type(), RGBAlgorithm::Script); + QCOMPARE(algo->name(), QString("Balls")); + QCOMPARE(algo->apiVersion(), 3); + QCOMPARE(algo->acceptColors(), 5); + QVector colors; + colors << Qt::red; + colors << Qt::green; + colors << Qt::blue; + algo->setColors(colors); + + QCOMPARE(algo->getColor(0), Qt::red); + QCOMPARE(algo->getColor(1), Qt::green); + QCOMPARE(algo->getColor(2), Qt::blue); delete algo; } diff --git a/engine/test/rgbtext/rgbtext_test.cpp b/engine/test/rgbtext/rgbtext_test.cpp index 73a09cbc40..afc1a6ae01 100644 --- a/engine/test/rgbtext/rgbtext_test.cpp +++ b/engine/test/rgbtext/rgbtext_test.cpp @@ -441,4 +441,12 @@ void RGBText_Test::verticalScroll() } } +void RGBText_Test::unused() +{ + RGBText text(m_doc); + QVector colors; + text.rgbMapSetColors(colors); + QCOMPARE(text.rgbMapGetColors().isEmpty(), true); +} + QTEST_MAIN(RGBText_Test) diff --git a/engine/test/rgbtext/rgbtext_test.h b/engine/test/rgbtext/rgbtext_test.h index c6656854e1..df66141499 100644 --- a/engine/test/rgbtext/rgbtext_test.h +++ b/engine/test/rgbtext/rgbtext_test.h @@ -42,6 +42,7 @@ private slots: void staticLetters(); void horizontalScroll(); void verticalScroll(); + void unused(); private: Doc * m_doc; From a53cc94c473b64f5f3cf70787205d474bd7b1c94 Mon Sep 17 00:00:00 2001 From: Massimo Callegari Date: Mon, 30 Dec 2024 13:17:28 +0100 Subject: [PATCH 61/63] qmlui: improve RGBMatrix editor code --- .../qml/fixturesfunctions/RGBMatrixEditor.qml | 167 +++++++++--------- qmlui/rgbmatrixeditor.cpp | 166 +---------------- qmlui/rgbmatrixeditor.h | 52 +----- 3 files changed, 95 insertions(+), 290 deletions(-) diff --git a/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml b/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml index e39416d31d..eb2288dea2 100644 --- a/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml +++ b/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml @@ -58,6 +58,40 @@ Rectangle } } + ColorTool + { + id: colorTool + x: -width - (UISettings.iconSizeDefault * 1.25) + y: UISettings.bigItemHeight + visible: false + closeOnSelect: true + + property int colorIndex: -1 + property Item previewBtn + + function showTool(index, button) + { + colorIndex = index + previewBtn = button + currentRGB = rgbMatrixEditor.colorAtIndex(colorIndex) + visible = true + } + + function hide() + { + visible = false + colorIndex = -1 + previewBtn = null + } + + onColorChanged: + { + previewBtn.color = Qt.rgba(r, g, b, 1.0) + rgbMatrixEditor.setColorAtIndex(colorIndex, previewBtn.color) + } + onClose: visible = false + } + EditorTopBar { id: topBar @@ -273,7 +307,7 @@ Rectangle radius: 5 border.color: color1MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 - color: rgbMatrixEditor.color1 + color: rgbMatrixEditor.colorAtIndex(0) visible: rgbMatrixEditor.algoColors > 0 ? true : false MouseArea @@ -281,27 +315,23 @@ Rectangle id: color1MouseArea anchors.fill: parent hoverEnabled: true - onClicked: color1Tool.visible = !color1Tool.visible - } - - ColorTool - { - id: color1Tool - parent: rgbmeContainer - x: -width - (UISettings.iconSizeDefault * 1.25) - y: UISettings.bigItemHeight - visible: false - closeOnSelect: true - currentRGB: rgbMatrixEditor.color1 - - onColorChanged: + onClicked: { - color1Button.color = Qt.rgba(r, g, b, 1.0) - rgbMatrixEditor.color1 = color1Button.color + if (colorTool.visible) + colorTool.hide() + else + colorTool.showTool(0, color1Button) } - onClose: visible = false } } + Rectangle + { + width: UISettings.listItemHeight + height: width + color: "transparent" + visible: rgbMatrixEditor.algoColors > 2 ? true : false + } + Rectangle { id: color2Button @@ -310,7 +340,7 @@ Rectangle radius: 5 border.color: color2MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 - color: rgbMatrixEditor.hasColor2 ? rgbMatrixEditor.color2 : "transparent" + color: rgbMatrixEditor.colorAtIndex(1) visible: rgbMatrixEditor.algoColors > 1 ? true : false MouseArea @@ -318,21 +348,13 @@ Rectangle id: color2MouseArea anchors.fill: parent hoverEnabled: true - onClicked: color2Tool.visible = !color2Tool.visible - } - - ColorTool - { - id: color2Tool - parent: rgbmeContainer - x: -width - (UISettings.iconSizeDefault * 1.25) - y: UISettings.bigItemHeight - visible: false - closeOnSelect: true - currentRGB: rgbMatrixEditor.color2 - - onColorChanged: rgbMatrixEditor.color2 = Qt.rgba(r, g, b, 1.0) - onClose: visible = false + onClicked: + { + if (colorTool.visible) + colorTool.hide() + else + colorTool.showTool(1, color2Button) + } } } IconButton @@ -355,13 +377,14 @@ Rectangle spacing: 4 visible: rgbMatrixEditor.algoColors > 4 ? true : false - //leftPadding: Qt.binding(function() { return editorColumn.firstColumnWidth }) Rectangle { id: colorRow1 height: editorColumn.itemsHeight + width: editorColumn.firstColumnWidth color: "transparent" visible: rgbMatrixEditor.algoColors > 4 ? true : false + onWidthChanged: { editorColumn.checkLabelWidth(width) @@ -377,7 +400,7 @@ Rectangle radius: 5 border.color: color3MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 - color: rgbMatrixEditor.hasColor3 ? rgbMatrixEditor.color3 : "transparent" + color: rgbMatrixEditor.colorAtIndex(2) visible: rgbMatrixEditor.algoColors > 2 ? true : false MouseArea @@ -385,21 +408,13 @@ Rectangle id: color3MouseArea anchors.fill: parent hoverEnabled: true - onClicked: color3Tool.visible = !color3Tool.visible - } - - ColorTool - { - id: color3Tool - parent: rgbmeContainer - x: -width - (UISettings.iconSizeDefault * 1.25) - y: UISettings.bigItemHeight - visible: false - closeOnSelect: true - currentRGB: rgbMatrixEditor.color3 - - onColorChanged: rgbMatrixEditor.color3 = Qt.rgba(r, g, b, 1.0) - onClose: visible = false + onClicked: + { + if (colorTool.visible) + colorTool.hide() + else + colorTool.showTool(2, color3Button) + } } } IconButton @@ -419,7 +434,7 @@ Rectangle radius: 5 border.color: color4MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 - color: rgbMatrixEditor.hasColor4 ? rgbMatrixEditor.color4 : "transparent" + color: rgbMatrixEditor.colorAtIndex(3) visible: rgbMatrixEditor.algoColors > 3 ? true : false MouseArea @@ -427,21 +442,13 @@ Rectangle id: color4MouseArea anchors.fill: parent hoverEnabled: true - onClicked: color4Tool.visible = !color4Tool.visible - } - - ColorTool - { - id: color4Tool - parent: rgbmeContainer - x: -width - (UISettings.iconSizeDefault * 1.25) - y: UISettings.bigItemHeight - visible: false - closeOnSelect: true - currentRGB: rgbMatrixEditor.color4 - - onColorChanged: rgbMatrixEditor.color4 = Qt.rgba(r, g, b, 1.0) - onClose: visible = false + onClicked: + { + if (colorTool.visible) + colorTool.hide() + else + colorTool.showTool(3, color4Button) + } } } IconButton @@ -464,11 +471,11 @@ Rectangle spacing: 4 visible: rgbMatrixEditor.algoColors > 4 ? true : false - //leftPadding: Qt.binding(function() { return editorColumn.firstColumnWidth }) Rectangle { id: colorRow2 height: editorColumn.itemsHeight + width: editorColumn.firstColumnWidth color: "transparent" visible: rgbMatrixEditor.algoColors > 4 ? true : false onWidthChanged: @@ -486,7 +493,7 @@ Rectangle radius: 5 border.color: color5MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 - color: rgbMatrixEditor.hasColor5 ? rgbMatrixEditor.color5 : "transparent" + color: rgbMatrixEditor.colorAtIndex(4) visible: rgbMatrixEditor.algoColors > 4 ? true : false MouseArea @@ -494,21 +501,13 @@ Rectangle id: color5MouseArea anchors.fill: parent hoverEnabled: true - onClicked: color5Tool.visible = !color5Tool.visible - } - - ColorTool - { - id: color5Tool - parent: rgbmeContainer - x: -width - (UISettings.iconSizeDefault * 1.25) - y: UISettings.bigItemHeight - visible: false - closeOnSelect: true - currentRGB: rgbMatrixEditor.color5 - - onColorChanged: rgbMatrixEditor.color5 = Qt.rgba(r, g, b, 1.0) - onClose: visible = false + onClicked: + { + if (colorTool.visible) + colorTool.hide() + else + colorTool.showTool(4, color5Button) + } } } IconButton diff --git a/qmlui/rgbmatrixeditor.cpp b/qmlui/rgbmatrixeditor.cpp index 81f555ed6f..f115b13cb6 100644 --- a/qmlui/rgbmatrixeditor.cpp +++ b/qmlui/rgbmatrixeditor.cpp @@ -162,180 +162,32 @@ int RGBMatrixEditor::algoColors() return m_matrix->algorithm()->acceptColors(); } -QColor RGBMatrixEditor::color1() const +QColor RGBMatrixEditor::colorAtIndex(int index) { - if (m_matrix == nullptr) - return Qt::red; - - return m_matrix->getColor(0); -} - -void RGBMatrixEditor::setColor1(QColor algoColor) -{ - if (m_matrix == nullptr || m_matrix->getColor(0) == algoColor) - return; - - Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor1, m_matrix->id(), m_matrix->getColor(0), algoColor); - m_matrix->setColor(0, algoColor); - m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm()); - - emit color1Changed(algoColor); -} - -QColor RGBMatrixEditor::color2() const -{ - if (m_matrix == nullptr) + if (m_matrix == nullptr || m_matrix->algorithm() == nullptr) return QColor(); - return m_matrix->getColor(1); + return m_matrix->getColor(index); } -void RGBMatrixEditor::setColor2(QColor algoColor) +void RGBMatrixEditor::setColorAtIndex(int index, QColor color) { - if (m_matrix == nullptr || m_matrix->getColor(1) == algoColor) + if (m_matrix == nullptr || m_matrix->getColor(index) == color) return; - Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor2, m_matrix->id(), m_matrix->getColor(1), algoColor); - m_matrix->setColor(1, algoColor); + Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor1, m_matrix->id(), m_matrix->getColor(index), color); + m_matrix->setColor(index, color); m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm()); - - emit color2Changed(algoColor); - if (algoColor.isValid()) - emit hasColor2Changed(true); -} - -QColor RGBMatrixEditor::color3() const -{ - if (m_matrix == nullptr) - return QColor(); - - return m_matrix->getColor(2); -} - -void RGBMatrixEditor::setColor3(QColor algoColor) -{ - if (m_matrix == nullptr || m_matrix->getColor(2) == algoColor) - return; - - Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor3, m_matrix->id(), m_matrix->getColor(2), algoColor); - m_matrix->setColor(2, algoColor); - - emit color3Changed(algoColor); - if (algoColor.isValid()) - emit hasColor3Changed(true); -} - -QColor RGBMatrixEditor::color4() const -{ - if (m_matrix == nullptr) - return QColor(); - - return m_matrix->getColor(3); -} - -void RGBMatrixEditor::setColor4(QColor algoColor) -{ - if (m_matrix == nullptr || m_matrix->getColor(3) == algoColor) - return; - - Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor4, m_matrix->id(), m_matrix->getColor(3), algoColor); - m_matrix->setColor(3, algoColor); - - emit color4Changed(algoColor); - if (algoColor.isValid()) - emit hasColor4Changed(true); -} - -QColor RGBMatrixEditor::color5() const -{ - if (m_matrix == nullptr) - return QColor(); - - return m_matrix->getColor(4); } -void RGBMatrixEditor::setColor5(QColor algoColor) +bool RGBMatrixEditor::hasColorAtIndex(int index) { - if (m_matrix == nullptr || m_matrix->getColor(4) == algoColor) - return; - - Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor5, m_matrix->id(), m_matrix->getColor(4), algoColor); - m_matrix->setColor(4, algoColor); - - emit color5Changed(algoColor); - if (algoColor.isValid()) - emit hasColor5Changed(true); -} - -bool RGBMatrixEditor::hasColor2() const -{ - if (m_matrix == nullptr || m_matrix->getColor(1).isValid() == false) - return false; - - return true; -} - -void RGBMatrixEditor::setHasColor2(bool hasColor) -{ - if (m_matrix && hasColor == false) - { - m_matrix->setColor(1, QColor()); - m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm()); - } - emit hasColor2Changed(hasColor); -} - -bool RGBMatrixEditor::hasColor3() const -{ - if (m_matrix == nullptr || m_matrix->getColor(2).isValid() == false) - return false; - - return true; -} - -void RGBMatrixEditor::setHasColor3(bool hasColor) -{ - if (m_matrix && hasColor == false) - { - m_matrix->setColor(2, QColor()); - } - emit hasColor3Changed(hasColor); -} - -bool RGBMatrixEditor::hasColor4() const -{ - if (m_matrix == nullptr || m_matrix->getColor(3).isValid() == false) - return false; - - return true; -} - -void RGBMatrixEditor::setHasColor4(bool hasColor) -{ - if (m_matrix && hasColor == false) - { - m_matrix->setColor(3, QColor()); - } - emit hasColor4Changed(hasColor); -} - -bool RGBMatrixEditor::hasColor5() const -{ - if (m_matrix == nullptr || m_matrix->getColor(4).isValid() == false) + if (m_matrix == nullptr || m_matrix->getColor(index).isValid() == false) return false; return true; } -void RGBMatrixEditor::setHasColor5(bool hasColor) -{ - if (m_matrix && hasColor == false) - { - m_matrix->setColor(4, QColor()); - } - emit hasColor5Changed(hasColor); -} - QString RGBMatrixEditor::algoText() const { if (m_matrix != nullptr && m_matrix->algorithm() != nullptr && diff --git a/qmlui/rgbmatrixeditor.h b/qmlui/rgbmatrixeditor.h index 711a5a8d2a..22cd6009c8 100644 --- a/qmlui/rgbmatrixeditor.h +++ b/qmlui/rgbmatrixeditor.h @@ -39,15 +39,6 @@ class RGBMatrixEditor : public FunctionEditor Q_PROPERTY(QStringList algorithms READ algorithms CONSTANT) Q_PROPERTY(int algorithmIndex READ algorithmIndex WRITE setAlgorithmIndex NOTIFY algorithmIndexChanged) Q_PROPERTY(int algoColors READ algoColors NOTIFY algoColorsChanged) - Q_PROPERTY(QColor color1 READ color1 WRITE setColor1 NOTIFY color1Changed) - Q_PROPERTY(QColor color2 READ color2 WRITE setColor2 NOTIFY color2Changed) - Q_PROPERTY(bool hasColor2 READ hasColor2 WRITE setHasColor2 NOTIFY hasColor2Changed) - Q_PROPERTY(QColor color3 READ color3 WRITE setColor3 NOTIFY color3Changed) - Q_PROPERTY(bool hasColor3 READ hasColor3 WRITE setHasColor3 NOTIFY hasColor3Changed) - Q_PROPERTY(QColor color4 READ color4 WRITE setColor4 NOTIFY color4Changed) - Q_PROPERTY(bool hasColor4 READ hasColor4 WRITE setHasColor4 NOTIFY hasColor4Changed) - Q_PROPERTY(QColor color5 READ color5 WRITE setColor5 NOTIFY color5Changed) - Q_PROPERTY(bool hasColor5 READ hasColor5 WRITE setHasColor5 NOTIFY hasColor5Changed) Q_PROPERTY(int blendMode READ blendMode WRITE setBlendMode NOTIFY blendModeChanged) Q_PROPERTY(int controlMode READ controlMode WRITE setControlMode NOTIFY controlModeChanged) @@ -93,37 +84,9 @@ class RGBMatrixEditor : public FunctionEditor /** Return the accepted colors of the current algorithm */ int algoColors(); - /** Get/set the color 1 of the current algorithm */ - QColor color1() const; - void setColor1(QColor algoColor); - - /** Get/set the color 2 of the current algorithm */ - QColor color2() const; - void setColor2(QColor algoColor); - - bool hasColor2() const; - void setHasColor2(bool hasColor); - - /** Get/set the color 2 of the current algorithm */ - QColor color3() const; - void setColor3(QColor algoColor); - - bool hasColor3() const; - void setHasColor3(bool hasColor); - - /** Get/set the color 2 of the current algorithm */ - QColor color4() const; - void setColor4(QColor algoColor); - - bool hasColor4() const; - void setHasColor4(bool hasColor); - - /** Get/set the color 2 of the current algorithm */ - QColor color5() const; - void setColor5(QColor algoColor); - - bool hasColor5() const; - void setHasColor5(bool hasColor); + Q_INVOKABLE QColor colorAtIndex(int index); + Q_INVOKABLE void setColorAtIndex(int index, QColor color); + Q_INVOKABLE bool hasColorAtIndex(int index); QString algoText() const; void setAlgoText(QString text); @@ -157,15 +120,6 @@ class RGBMatrixEditor : public FunctionEditor signals: void algorithmIndexChanged(); void algoColorsChanged(); - void color1Changed(QColor color); - void color2Changed(QColor color); - void hasColor2Changed(bool hasColor); - void color3Changed(QColor color); - void hasColor3Changed(bool hasColor); - void color4Changed(QColor color); - void hasColor4Changed(bool hasColor); - void color5Changed(QColor color); - void hasColor5Changed(bool hasColor); void algoTextChanged(QString text); void algoTextFontChanged(QFont algoTextFont); From 4d99a820903673c622a543010b3cf92b5d0e0ff1 Mon Sep 17 00:00:00 2001 From: Massimo Callegari Date: Mon, 30 Dec 2024 14:51:28 +0100 Subject: [PATCH 62/63] qmlui: fix RGBMatrix color reset --- .../qml/fixturesfunctions/RGBMatrixEditor.qml | 40 +++++++++++++------ qmlui/rgbmatrixeditor.cpp | 14 ++++++- qmlui/rgbmatrixeditor.h | 1 + 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml b/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml index eb2288dea2..a668023f44 100644 --- a/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml +++ b/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml @@ -362,11 +362,14 @@ Rectangle width: UISettings.listItemHeight height: width imgSource: "qrc:/cancel.svg" + tooltip: qsTr("Reset color 2") visible: rgbMatrixEditor.algoColors > 1 ? true : false - onClicked: rgbMatrixEditor.hasColor2 = false + onClicked: + { + color2Button.color = "transparent" + rgbMatrixEditor.resetColorAtIndex(1) + } } - // filler - //Rectangle { Layout.fillWidth: true; height: parent.height; color: "transparent" } } // row 7 @@ -400,7 +403,7 @@ Rectangle radius: 5 border.color: color3MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 - color: rgbMatrixEditor.colorAtIndex(2) + color: rgbMatrixEditor.hasColorAtIndex(2) ? rgbMatrixEditor.colorAtIndex(2) : "transparent" visible: rgbMatrixEditor.algoColors > 2 ? true : false MouseArea @@ -422,8 +425,13 @@ Rectangle width: UISettings.listItemHeight height: width imgSource: "qrc:/cancel.svg" + tooltip: qsTr("Reset color 3") visible: rgbMatrixEditor.algoColors > 2 ? true : false - onClicked: rgbMatrixEditor.hasColor3 = false + onClicked: + { + color3Button.color = "transparent" + rgbMatrixEditor.resetColorAtIndex(2) + } } Rectangle @@ -434,7 +442,7 @@ Rectangle radius: 5 border.color: color4MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 - color: rgbMatrixEditor.colorAtIndex(3) + color: rgbMatrixEditor.hasColorAtIndex(3) ? rgbMatrixEditor.colorAtIndex(3) : "transparent" visible: rgbMatrixEditor.algoColors > 3 ? true : false MouseArea @@ -456,11 +464,14 @@ Rectangle width: UISettings.listItemHeight height: width imgSource: "qrc:/cancel.svg" + tooltip: qsTr("Reset color 4") visible: rgbMatrixEditor.algoColors > 3 ? true : false - onClicked: rgbMatrixEditor.hasColor4 = false + onClicked: + { + color4Button.color = "transparent" + rgbMatrixEditor.resetColorAtIndex(3) + } } - // filler - //Rectangle { Layout.fillWidth: true; height: parent.height; color: "transparent" } } // row 8 @@ -493,7 +504,7 @@ Rectangle radius: 5 border.color: color5MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 - color: rgbMatrixEditor.colorAtIndex(4) + color: rgbMatrixEditor.hasColorAtIndex(4) ? rgbMatrixEditor.colorAtIndex(4) : "transparent" visible: rgbMatrixEditor.algoColors > 4 ? true : false MouseArea @@ -515,11 +526,14 @@ Rectangle width: UISettings.listItemHeight height: width imgSource: "qrc:/cancel.svg" + tooltip: qsTr("Reset color 5") visible: rgbMatrixEditor.algoColors > 4 ? true : false - onClicked: rgbMatrixEditor.hasColor5 = false + onClicked: + { + color5Button.color = "transparent" + rgbMatrixEditor.resetColorAtIndex(4) + } } - // filler - //Rectangle { Layout.fillWidth: true; height: parent.height; color: "transparent" } } SectionBox diff --git a/qmlui/rgbmatrixeditor.cpp b/qmlui/rgbmatrixeditor.cpp index f115b13cb6..913be54685 100644 --- a/qmlui/rgbmatrixeditor.cpp +++ b/qmlui/rgbmatrixeditor.cpp @@ -134,6 +134,7 @@ void RGBMatrixEditor::setAlgorithmIndex(int algoIndex) /** if we're setting the same algorithm, then there's nothing to do */ if (m_matrix->algorithm() != nullptr && m_matrix->algorithm()->name() == algo->name()) return; + Q_ASSERT(5 == RGBAlgorithmColorDisplayCount); QVector colors = { m_matrix->getColor(0), @@ -177,7 +178,18 @@ void RGBMatrixEditor::setColorAtIndex(int index, QColor color) Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor1, m_matrix->id(), m_matrix->getColor(index), color); m_matrix->setColor(index, color); - m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm()); + if (index < 2) + m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm()); +} + +void RGBMatrixEditor::resetColorAtIndex(int index) +{ + if (m_matrix == nullptr || m_matrix->getColor(index).isValid() == false) + return; + + m_matrix->setColor(index, QColor()); + if (index < 2) + m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm()); } bool RGBMatrixEditor::hasColorAtIndex(int index) diff --git a/qmlui/rgbmatrixeditor.h b/qmlui/rgbmatrixeditor.h index 22cd6009c8..ea44f5cb06 100644 --- a/qmlui/rgbmatrixeditor.h +++ b/qmlui/rgbmatrixeditor.h @@ -86,6 +86,7 @@ class RGBMatrixEditor : public FunctionEditor Q_INVOKABLE QColor colorAtIndex(int index); Q_INVOKABLE void setColorAtIndex(int index, QColor color); + Q_INVOKABLE void resetColorAtIndex(int index); Q_INVOKABLE bool hasColorAtIndex(int index); QString algoText() const; From 9eb789e377191412e1f6844d39411cdec33fe349 Mon Sep 17 00:00:00 2001 From: Massimo Callegari Date: Mon, 30 Dec 2024 15:03:48 +0100 Subject: [PATCH 63/63] qmlui: notify RGBMatrix color change to the UI --- qmlui/rgbmatrixeditor.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qmlui/rgbmatrixeditor.cpp b/qmlui/rgbmatrixeditor.cpp index 913be54685..a1e789cb0e 100644 --- a/qmlui/rgbmatrixeditor.cpp +++ b/qmlui/rgbmatrixeditor.cpp @@ -468,7 +468,9 @@ void RGBMatrixEditor::setScriptStringProperty(QString paramName, QString value) StringStringPair oldValue(paramName, m_matrix->property(paramName)); Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetScriptStringValue, m_matrix->id(), QVariant::fromValue(oldValue), QVariant::fromValue(StringStringPair(paramName, value))); + m_matrix->setProperty(paramName, value); + emit algoColorsChanged(); } void RGBMatrixEditor::setScriptIntProperty(QString paramName, int value)