1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
16 BColor(const BaseDisplay * const _display = 0, unsigned int _screen = ~(0u));
17 BColor(int _r, int _g, int _b,
18 const BaseDisplay * const _display, unsigned int _screen = ~(0u));
19 BColor(const std::string &_name,
20 const BaseDisplay * const _display, unsigned int _screen = ~(0u));
23 inline const std::string &name(void) const { return colorname; }
25 inline int red(void) const { return r; }
26 inline int green(void) const { return g; }
27 inline int blue(void) const { return b; }
28 void setRGB(int _r, int _g, int _b) {
35 inline const BaseDisplay *display(void) const { return dpy; }
36 inline unsigned int screen(void) const { return scrn; }
37 void setDisplay(const BaseDisplay * const _display,
38 unsigned int _screen = ~(0u));
40 inline bool isAllocated(void) const { return allocated; }
42 inline bool isValid(void) const { return r != -1 && g != -1 && b != -1; }
44 unsigned long pixel(void) const;
47 BColor &operator=(const BColor &c);
48 inline bool operator==(const BColor &c) const
49 { return (r == c.r && b == c.b && b == c.b); }
50 inline bool operator!=(const BColor &c) const
51 { return (! operator==(c)); }
53 static void cleanupColorCache(void);
56 void parseColorName(void);
58 void deallocate(void);
63 const BaseDisplay *dpy;
65 std::string colorname;
67 // global color allocator/deallocator
69 const BaseDisplay* const display;
70 const unsigned int screen;
73 RGB(void) : display(0), screen(~(0u)), r(-1), g(-1), b(-1) { }
74 RGB(const BaseDisplay * const a, const unsigned int b,
75 const int x, const int y, const int z)
76 : display(a), screen(b), r(x), g(y), b(z) {}
78 : display(x.display), screen(x.screen), r(x.r), g(x.g), b(x.b) {}
80 inline bool operator==(const RGB &x) const {
81 return display == x.display &&
83 r == x.r && g == x.g && b == x.b;
86 inline bool operator<(const RGB &x) const {
88 p1 = (screen << 24 | r << 16 | g << 8 | b) & 0x00ffffff;
89 p2 = (x.screen << 24 | x.r << 16 | x.g << 8 | x.b) & 0x00ffffff;
94 const unsigned long p;
96 inline PixelRef(void) : p(0), count(0) { }
97 inline PixelRef(const unsigned long x) : p(x), count(1) { }
99 typedef std::map<RGB,PixelRef> ColorCache;
100 typedef ColorCache::value_type ColorCacheItem;
101 static ColorCache colorcache;
102 static bool cleancache;
103 static void doCacheCleanup(void);