]> icculus.org git repositories - mikachu/openbox.git/blob - otk/rendercolor.hh
only store what we need to in the class
[mikachu/openbox.git] / otk / rendercolor.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef __rendercolor_hh
3 #define __rendercolor_hh
4
5 extern "C" {
6 #include <X11/Xlib.h>
7 }
8
9 #include <map>
10
11 namespace otk {
12
13 struct RGB {
14   int r;
15   int g;
16   int b;
17   RGB(int red, int green, int blue) : r(red), g(green), b(blue) {}
18   // color is in ARGB format
19   RGB(unsigned long color)
20     : r((color >> 16) & 0xff),
21       g((color >> 8) & 0xff),
22       b((color) & 0xff) {}
23 };
24
25 class RenderColor {
26 private:
27   struct CacheItem {
28     GC gc;
29     unsigned long pixel;
30     int count;
31     CacheItem(GC g, unsigned long p) : gc(g), pixel(p), count(0) {}
32   };
33   static std::map<unsigned long, CacheItem*> *_cache;
34
35   int _screen;
36   unsigned char _red;
37   unsigned char _green;
38   unsigned char _blue;
39
40   mutable unsigned long _pixel;
41   mutable GC _gc;
42
43   mutable bool _allocated;
44
45   void create() const;
46   
47 public:
48   static void initialize();
49   static void destroy();
50   
51   RenderColor(int screen, unsigned char red,
52               unsigned char green, unsigned char blue);
53   RenderColor(int screen, RGB rgb);
54   virtual ~RenderColor();
55
56   inline int screen() const { return _screen; }
57   inline unsigned char red() const { return _red; }
58   inline unsigned char green() const { return _green; }
59   inline unsigned char blue() const { return _blue; }
60   unsigned long pixel() const;
61   GC gc() const;
62 };
63
64 }
65
66 #endif // __rendercolor_hh