helper: Added createPalette, and a Palette interface change

This commit is contained in:
Paul Beckingham 2016-04-25 21:10:09 -04:00
parent 6567639465
commit 21166a044f
6 changed files with 32 additions and 16 deletions

View file

@ -46,18 +46,14 @@ Palette::Palette ()
Color ("black on bright cyan"), Color ("black on bright cyan"),
Color ("black on bright yellow"), Color ("black on bright yellow"),
}; };
_current = 0;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Palette::initialize (const Rules& rules) void Palette::add (Color c)
{ {
auto themeColors = rules.all ("theme.palette.color"); _colors.push_back (c);
if (themeColors.size ())
{
_colors.clear ();
for (auto& entry : themeColors)
_colors.push_back (Color (rules.get (entry)));
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -77,3 +73,10 @@ int Palette::size () const
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Palette::clear ()
{
_colors.clear ();
_current = 0;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -36,9 +36,10 @@ class Palette
{ {
public: public:
Palette (); Palette ();
void initialize (const Rules&); void add (Color);
Color next (); Color next ();
int size () const; int size () const;
void clear ();
public: public:
bool enabled {true}; bool enabled {true};

View file

@ -25,7 +25,6 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <cmake.h> #include <cmake.h>
#include <Palette.h>
#include <format.h> #include <format.h>
#include <timew.h> #include <timew.h>
#include <algorithm> #include <algorithm>
@ -189,7 +188,7 @@ int CmdDiagnostics (
if (rules.getBoolean ("color")) if (rules.getBoolean ("color"))
{ {
out << " "; out << " ";
Palette palette; auto palette = createPalette (rules);
for (int color = 0; color < palette.size (); ++color) for (int color = 0; color < palette.size (); ++color)
{ {
if (color && color % 16 == 0) if (color && color % 16 == 0)

View file

@ -25,7 +25,6 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <cmake.h> #include <cmake.h>
#include <Palette.h>
#include <Composite.h> #include <Composite.h>
#include <Color.h> #include <Color.h>
#include <Range.h> #include <Range.h>
@ -54,10 +53,7 @@ int CmdReportDay (
auto excluded = timeline.excluded (rules); auto excluded = timeline.excluded (rules);
// Create a color palette. // Create a color palette.
Palette palette; auto palette = createPalette (rules);
palette.initialize (rules);
palette.enabled = rules.getBoolean ("color");
Color colorExc (palette.enabled ? rules.get ("theme.colors.exclusion") : ""); Color colorExc (palette.enabled ? rules.get ("theme.colors.exclusion") : "");
Color colorLabel (palette.enabled ? rules.get ("theme.colors.label") : ""); Color colorLabel (palette.enabled ? rules.get ("theme.colors.label") : "");

View file

@ -537,6 +537,22 @@ std::vector <Range> combineHolidaysAndExclusions (
return addRanges (range, results, exclusionRanges); return addRanges (range, results, exclusionRanges);
} }
////////////////////////////////////////////////////////////////////////////////
Palette createPalette (const Rules& rules)
{
Palette p;
auto colors = rules.all ("theme.palette.color");
if (colors.size ())
{
p.clear ();
for (auto& c : colors)
p.add (Color (rules.get (c)));
}
p.enabled = rules.getBoolean ("color");
return p;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Extract the tags from a set of intervals, and using a rotating color palette, // Extract the tags from a set of intervals, and using a rotating color palette,
// map unique tags to color. // map unique tags to color.

View file

@ -58,6 +58,7 @@ std::vector <Range> addRanges (const Range&, const std::vector <Range>&, const s
std::vector <Range> subtractRanges (const Range&, const std::vector <Range>&, const std::vector <Range>&); std::vector <Range> subtractRanges (const Range&, const std::vector <Range>&, const std::vector <Range>&);
Range overallRangeFromIntervals (const std::vector <Interval>&); Range overallRangeFromIntervals (const std::vector <Interval>&);
std::vector <Range> combineHolidaysAndExclusions (const Range&, const Rules&, const std::vector <Exclusion>&); std::vector <Range> combineHolidaysAndExclusions (const Range&, const Rules&, const std::vector <Exclusion>&);
Palette createPalette (const Rules&);
std::map <std::string, Color> createTagColorMap (const Rules&, Palette&, const std::vector <Interval>&); std::map <std::string, Color> createTagColorMap (const Rules&, Palette&, const std::vector <Interval>&);
int quantizeTo15Minutes (const int); int quantizeTo15Minutes (const int);