diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h index 949eaaf9d5..16a8d4a396 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h @@ -24,13 +24,14 @@ #include "kaleidoscope/key_defs.h" // for Key, KEY_FLAGS, Key_NoKey, LockLayer #include "kaleidoscope/layers.h" // for Layer, Layer_ #include "kaleidoscope/plugin/LEDControl.h" // for LEDControl +#include // for LEDPaletteTheme namespace kaleidoscope { namespace plugin { // Data structure for an individual qukey struct Overlay { - int8_t layer; + uint8_t layer; KeyAddr addr; uint8_t palette_index; @@ -53,8 +54,24 @@ class ColormapOverlay : public kaleidoscope::Plugin { overlay_count_ = _overlay_count; } - // A wildcard value for a qukey that exists on every layer. + template + void configureOverlays(uint8_t **overlays) { + overlays_ = nullptr; + overlay_count_ = 0; + for (int layer_ = 0; layer_ < _layer_count; layer_++) { + for (int key_index_ = 0; key_index_ < kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns; key_index_++) { + int8_t color_index_ = overlays[layer_][key_index_]; + if (color_index_ >= 0 && color_index_ < ::LEDPaletteTheme.getPaletteSize() && + color_index_ != no_color_overlay) { + overlays_[overlay_count_] = Overlay(layer_, KeyAddr(key_index_), color_index_); + overlay_count_++; + } + } + } + } + // A wildcard value for an overlay that applies on every layer. static constexpr int8_t layer_wildcard{-1}; + static constexpr int8_t no_color_overlay{-1}; EventHandlerResult onSetup(); EventHandlerResult beforeSyncingLeds(); @@ -69,6 +86,36 @@ class ColormapOverlay : public kaleidoscope::Plugin { void setLEDOverlayColors(); }; +// clang-format off + +#define COLORMAP_OVERLAYS_MAP(layers...) \ + namespace kaleidoscope { \ + namespace plugin { \ + const int8_t overlays_[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns] = { \ + layers \ + }; \ + ColormapOverlay.configureOverlays(overlays_); \ + } /* plugin */ \ + } /* kaleidoscope */ + +#define __IDENTITY__(X) X + +#ifdef PER_KEY_DATA_STACKED +#define COLORMAP_OVERLAY_STACKED(...) \ + { \ + MAP_LIST(__IDENTITY__, PER_KEY_DATA_STACKED(0, __VA_ARGS__)) \ + } +#endif + +#ifdef PER_KEY_DATA +#define COLORMAP_OVERLAY(...) \ + { \ + MAP_LIST(__IDENTITY__, PER_KEY_DATA(0, __VA_ARGS__)) \ + } +#endif + +// clang-format on + } // namespace plugin } // namespace kaleidoscope