Changeset 919 for trunk/lib/Colours.cc


Ignore:
Timestamp:
Dec 1, 2009, 12:03:31 AM (12 years ago)
Author:
Jari Häkkinen
Message:

Addresses #75. Colours are dynamically assigned to authors. Removed white from the colour map.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Colours.cc

    r916 r919  
    3131
    3232  Colours::Colours(void)
    33     : colour_map_(14)
     33    : colour_map_(13), next_colour_(colour_map_.begin())
     34
    3435  {
    3536    colour_map_[ 0].label="green";
     
    5960    colour_map_[12].label="black";
    6061    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++;
    6862  }
    6963
    7064
    7165  void Colours::get_colour(const std::string& label, unsigned char& r,
    72                            unsigned char& g, unsigned char& b) const
     66                           unsigned char& g, unsigned char& b)
    7367  {
    74     r=g=b=0;
    7568    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;
     69    if ((i=author_map_.find(label)) == author_map_.end()) {
     70      // no colour defined for label, set colour for label
     71      author_map_[label]=next_colour_++;
     72      if (next_colour_==colour_map_.end())
     73        // end of colour map reach, start over
     74        next_colour_=colour_map_.begin();
     75    }
     76    r=author_map_[label]->r;
     77    g=author_map_[label]->g;
     78    b=author_map_[label]->b;
    8079  }
    8180
Note: See TracChangeset for help on using the changeset viewer.