/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */


#ifndef ECXX_CTL_GFX_COLOR_GENERATOR_1D_OFF_ON_H
#define ECXX_CTL_GFX_COLOR_GENERATOR_1D_OFF_ON_H


namespace eCxx {


//
// A simple 1-dimensional color generator class - off and on colors
//
template <typename ColorT, typename BufferSizeT, uint8_t AnimChannelIndexes = ColorT::A>
class ColorGenerator1D_OffOn : public ColorGenerator1D_CRTPBase<
    ColorGenerator1D_OffOn<ColorT, BufferSizeT, AnimChannelIndexes>,
    ColorT,
    BufferSizeT
> {
    public:
        using ColorGenerator1DType = ColorGenerator1D_CRTPBase<ColorGenerator1D_OffOn, ColorT, BufferSizeT>;

        using ColorType            = typename ColorGenerator1DType::ColorType;
        using BufferSizeType       = typename ColorGenerator1DType::BufferSizeType;

    public:
        inline ColorGenerator1D_OffOn(const ColorType& offColor, const ColorType& onColor) __ECXX_ATTR_ALWAYS_INLINE
        : _onColor (onColor )
        , _offColor(offColor)
        {}

        inline void reset_impl() __ECXX_ATTR_ALWAYS_INLINE
        {};

        inline const ColorType generate_impl(uint8_t, bool state) __ECXX_ATTR_ALWAYS_INLINE
        { return state ? _onColor : _offColor; }

        inline const ColorType generate_impl(uint8_t, uint8_t lerpFactor) __ECXX_ATTR_ALWAYS_INLINE
        {
            ColorType dst;
            lerpColor<AnimChannelIndexes>(dst, _offColor, _onColor, lerpFactor);
            return dst;
        }

        inline const ColorType generate_impl(BufferSizeType, BufferSizeType, BufferSizeType, bool state) __ECXX_ATTR_ALWAYS_INLINE
        { return generate_impl(0, state); }

        inline const ColorType generate_impl(BufferSizeType, BufferSizeType, BufferSizeType, uint8_t lerpFactor) __ECXX_ATTR_ALWAYS_INLINE
        { return generate_impl(0, lerpFactor); }

#if defined(__x86_64__) || defined(__i386__)
        // NOTE : This color generator implementation does not require reset() to be
        //        called first for this function to work properly
        inline eCxx::CBP::QUInt estimatedTotalAnimationFrameCount_impl() const __ECXX_ATTR_ALWAYS_INLINE
        { return 1; }
#endif

    private:
        const ColorType _onColor;
        const ColorType _offColor;
};


} // namespace eCxx


#endif
