diff --git a/src/Palette.cpp b/src/Palette.cpp index 173cdc18..c51a89f5 100644 --- a/src/Palette.cpp +++ b/src/Palette.cpp @@ -40,28 +40,33 @@ void Palette::initialize (const Rules& rules) //////////////////////////////////////////////////////////////////////////////// Color Palette::next () { + // If there are no colors, then ::initialize was not provided with any, so use + // a default set. + if (! _colors.size ()) + _colors = { + Color ("white on red"), + Color ("white on blue"), + Color ("white on green"), + Color ("black on magenta"), + Color ("black on cyan"), + Color ("black on yellow"), + Color ("black on white"), + Color ("white on bright red"), + Color ("white on bright blue"), + Color ("white on bright green"), + Color ("black on bright magenta"), + Color ("black on bright cyan"), + Color ("black on bright yellow"), + }; + + // Return the next color in the list. Cycle to the beginning if necessary. return _colors[_current++ % _colors.size ()]; } //////////////////////////////////////////////////////////////////////////////// -void Palette::defaults () +int Palette::size () const { - _colors = - { - Color ("white on red"), - Color ("white on blue"), - Color ("black on green"), - Color ("black on magenta"), - Color ("black on cyan"), - Color ("black on yellow"), - Color ("black on white"), - Color ("white on bright red"), - Color ("white on bright blue"), - Color ("black on bright green"), - Color ("black on bright magenta"), - Color ("black on bright cyan"), - Color ("black on bright yellow"), - }; + return static_cast (_colors.size ()); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Palette.h b/src/Palette.h index ec67c47a..5ff8224b 100644 --- a/src/Palette.h +++ b/src/Palette.h @@ -38,9 +38,7 @@ public: Palette () = default; void initialize (const Rules&); Color next (); - -private: - void defaults (); + int size () const; private: std::vector _colors {};