Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

colorpicker.h

Go to the documentation of this file.
00001 /* Colorpicker -- Picks a color for a directory entry
00002    Copyright (C) 2002 Aaron Bentley
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2, or (at your option)
00007    any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the Free Software Foundation,
00016    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00017 class ColorPicker
00018 {
00019 public:
00020    virtual Gdk_Color operator() (EntryRect const &er)
00021    {
00022       Gdk_Color color;
00023       er.setColor(color);
00024       return color;
00025    }
00026    virtual ~ColorPicker()
00027    {}
00028 };
00029 
00030 class GidColor: public ColorPicker
00031 {
00032 private:
00033    std::map<gid_t, Gdk_Color> gidcolor;
00034 
00035 public:
00036    GidColor();
00037 
00038    virtual Gdk_Color operator() (EntryRect const &er)
00039    {
00040       std::map<gid_t, Gdk_Color>::const_iterator color;
00041       color=gidcolor.find(er.get_EnTree().getGid());
00042       if (color!=gidcolor.end())
00043       {
00044     return color->second;
00045       }
00046       else
00047       {
00048     Gdk_Color white;
00049     white.set_rgb(65535,65535,65535);
00050     return white;
00051       }
00052    }
00053 };
00054 
00055 class AgeColor: public ColorPicker
00056 {
00057    private:
00058    time_t curtime;
00059    time_t oldest;
00060 
00061    public:
00062    AgeColor()
00063       :
00064    curtime(time(NULL))
00065    {
00066       oldest=60*60*24*365; 
00067    }
00068    virtual Gdk_Color operator() (EntryRect const &er)
00069    {
00070       //const long yearsec=60*60*24*365;
00071       Gdk_Color agecolor;
00072       float age=curtime-er.get_EnTree().getATime();
00073       gint red=static_cast<gint>(age/oldest*65535);
00074 
00075       //gint green=er.get_EnTree().getMTime();
00076       //green=green%65535;
00077       agecolor.set_rgb(red, 65535-red, 0);
00078       return agecolor;
00079    }
00080 };

Generated on Mon Apr 7 19:41:43 2003 for DuTree by doxygen1.2.18