source: trunk/lib/Colours.cc @ 916

Last change on this file since 916 was 916, checked in by Jari Häkkinen, 12 years ago

Addresses #75. Added author colouring. Currently jari and peter gets non-black hard-coded colour.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1// $Id: Colours.cc 916 2009-11-30 20:02:40Z jari $
2
3/*
4  Copyright (C) 2009 Jari Häkkinen
5
6  This file is part of svndigest, http://dev.thep.lu.se/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "Colours.h"
23
24#include <cstdlib>
25
26namespace theplu {
27namespace svndigest {
28
29  Colours* Colours::instance_=NULL;
30
31
32  Colours::Colours(void)
33    : colour_map_(14)
34  {
35    colour_map_[ 0].label="green";
36    colour_map_[ 0].r=  0; colour_map_[ 0].g=146; colour_map_[ 0].b= 72;
37    colour_map_[ 1].label="blue";
38    colour_map_[ 1].r= 27; colour_map_[ 1].g=117; colour_map_[ 1].b=186;
39    colour_map_[ 2].label="red";
40    colour_map_[ 2].r=189; colour_map_[ 2].g= 32; colour_map_[ 2].b= 46;
41    colour_map_[ 3].label="grey";
42    colour_map_[ 3].r=131; colour_map_[ 3].g=131; colour_map_[ 3].b=131;
43    colour_map_[ 4].label="orange";
44    colour_map_[ 4].r=245; colour_map_[ 4].g=145; colour_map_[ 4].b= 32;
45    colour_map_[ 5].label="brown";
46    colour_map_[ 5].r=117; colour_map_[ 5].g= 77; colour_map_[ 5].b= 41;
47    colour_map_[ 6].label="cyan";
48    colour_map_[ 6].r= 40; colour_map_[ 6].g=170; colour_map_[ 6].b=225;
49    colour_map_[ 7].label="lime";
50    colour_map_[ 7].r=213; colour_map_[ 7].g=221; colour_map_[ 7].b= 38;
51    colour_map_[ 8].label="purple";
52    colour_map_[ 8].r=143; colour_map_[ 8].g= 40; colour_map_[ 8].b=140;
53    colour_map_[ 9].label="lgrey";
54    colour_map_[ 9].r=220; colour_map_[ 9].g=220; colour_map_[ 9].b=220;
55    colour_map_[10].label="lbrown";
56    colour_map_[10].r=194; colour_map_[10].g=151; colour_map_[10].b=106;
57    colour_map_[11].label="pink";
58    colour_map_[11].r=230; colour_map_[11].g=125; colour_map_[11].b=230;
59    colour_map_[12].label="black";
60    colour_map_[12].r=  0; colour_map_[12].g=  0; colour_map_[12].b=  0;
61    colour_map_[13].label="white";
62    colour_map_[13].r=255; colour_map_[13].g=255; colour_map_[13].b=255;
63
64    // temporary until proper configuration is implemented
65    std::vector<colour>::iterator i=colour_map_.begin();
66    author_map_["jari"]=i++;
67    author_map_["peter"]=i++;
68  }
69
70
71  void Colours::get_colour(const std::string& label, unsigned char& r,
72                           unsigned char& g, unsigned char& b) const
73  {
74    r=g=b=0;
75    std::map<std::string,std::vector<colour>::iterator>::const_iterator i;
76    if ((i=author_map_.find(label)) == author_map_.end())
77      // no colour defined for label
78      return;
79    r=i->second->r; g=i->second->g; b=i->second->b;
80  }
81
82
83  Colours& Colours::instance(void)
84  {
85    if (!instance_)
86      instance_ = new Colours;
87    return *instance_;
88  }
89
90}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.