diff --git a/common/typelist.h b/common/typelist.h index e7da351e7..eceaf88c3 100644 --- a/common/typelist.h +++ b/common/typelist.h @@ -41,28 +41,28 @@ template using RestTypeList = typename RestTypeListHelper::type -// Head -template struct HeadTypeListHelper { - typedef typename HeadTypeListHelper>::type type; +// Tail +template struct TailTypeListHelper { + typedef typename TailTypeListHelper>::type type; }; template -struct HeadTypeListHelper<0, TL> { +struct TailTypeListHelper<0, TL> { typedef TL type; }; -template using HeadTypeList = typename::HeadTypeListHelper::type; +template using TailTypeList = typename::TailTypeListHelper::type; -// Tail +// Head template -struct TailTypeListHelper { - typedef typename::TailTypeListHelper, ConcatTypeLists>>>::type type; +struct HeadTypeListHelper { + typedef typename::HeadTypeListHelper, ConcatTypeLists>>>::type type; }; template -struct TailTypeListHelper<0, TL, prefix> { +struct HeadTypeListHelper<0, TL, prefix> { typedef prefix type; }; -template using TailTypeList = typename::TailTypeListHelper>::type; +template using HeadTypeList = typename::HeadTypeListHelper>::type; template diff --git a/styles/gradient.h b/styles/gradient.h index 960023eed..c57c7a91e 100644 --- a/styles/gradient.h +++ b/styles/gradient.h @@ -9,8 +9,25 @@ // Gradient, color A at base, B at tip. // Any number of colors can be put together into a gradient. -#include "../functions/ramp.h" +#include "mix.h" -template using Gradient = Mix; +template +class Gradient { +public: + void run(BladeBase* blade) { + colors_.run(blade); + mul_ = ((sizeof...(COLORS)-1) << 15) / (blade->num_leds() - 1); + } +private: + PONUA MixHelper colors_; + int mul_; +public: + auto getColor(int led) -> decltype(colors_.getColor(1,1)) { + int x = led * mul_; + auto a = colors_.getColor(x >> 15, led); + auto b = colors_.getColor((x >> 15) + 1, led); + return MixColors(a, b, x & 0x7fff, 15); + } +}; #endif diff --git a/styles/tests.cpp b/styles/tests.cpp index db8d303bc..07a1b441e 100644 --- a/styles/tests.cpp +++ b/styles/tests.cpp @@ -882,7 +882,36 @@ void test_argument_parsing() { CHECK_COLOR(TestRgbArgColors[3], 7, 8, 9, 0); } +void test_gradient() { + MockBlade mock_blade; + mock_blade.colors.resize(3); + Style> style; + style.run(&mock_blade); + + CHECK_COLOR(mock_blade.colors[0], 65535, 0, 0, 1); + CHECK_COLOR(mock_blade.colors[1], 0, 65535, 0, 1); + CHECK_COLOR(mock_blade.colors[2], 0, 0, 65535, 1); +} + +void test_mix() { + MockBlade mock_blade; + mock_blade.colors.resize(1); + Style, Red, Green, Blue, Yellow, White>> s1; + s1.run(&mock_blade); + CHECK_COLOR(mock_blade.colors[0], 65535, 0, 0, 1); + + Style, Red, Green, Blue, Yellow, White>> s2; + s2.run(&mock_blade); + CHECK_COLOR(mock_blade.colors[0], 32767, 32767, 0, 1); + + Style, Red, Green, Blue, Yellow, White>> s3; + s3.run(&mock_blade); + CHECK_COLOR(mock_blade.colors[0], 0, 65535, 0, 1); +} + int main() { + test_mix(); + test_gradient(); test_style6(); test_style5(); test_style4();